display
- 通过display来修改元素的性质。
--block:设置元素为块元素
--inline:设置元素为行内元素
--inline-block:设置元素为行内块元素
--none: 隐藏元素
visibility
visibility属性主要用于元素是否可见
-visible:可见的
-hidden: 隐藏的
overflow
- 当相关标签里面的内容超出了样式的宽度和高度使,就会发生一些奇怪的事情,浏览器会让内容溢出盒子。
可以通过overflow来控制内容溢出的情况。
可选值:
--visible:默认值
--scroll:添加滚动条
--auto:根据需要添加滚动条
--hidden:隐藏超出盒子的内容
文档流
文档流指的是文档中可实现的对象在排列时所占用的位置,
将窗体自上而下分为一行行,并在每行中按从左至右的顺序排放元素,即为文档流。
也就是说在文档流中元素默认会紧贴到上一个元素的右边,如果右边不足以放下元素,元素则会另起一行,在新的一行中继续从左至右摆放。
这样一来每一个块元素都会另起一行,那么我们如果想在文档流中进行布局就会变得比较麻烦。
浮动
所谓浮动指的就是使元素脱离原来的文本流,在父元素中浮动起来。
--none: 不浮动
--left:向左浮动
--right: 向右浮动
clear: 清除浮动
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>浮动</title>
<style type="text/css">
.box1{
width: 600px;
height: 200px;
background-color: red;
float: left;
}
.box2{
width: 200px;
height: 200px;
background-color: yellow;
float: left;
}
.box3{
width: 200px;
height: 200px;
background-color: green;
float: left;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</body>
</html>
内联素浮动
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>内联素的浮动</title>
<style type="text/css">
.box1{
background-color: #bfa;
}
.s1{
float: left;
width: 100px;
height: 100px;
background-color: yellow;
}
</style>
</head>
<body>
<div class="box1">a</div>
<span class="s1">hello</span>
</body>
</html>
简单布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>简单布局</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.header{
width: 1000px;
height: 150px;
background-color: yellowgreen;
margin: 0 auto;
}
.content{
width: 1000px;
height: 400px;
background-color: orange;
margin: 10px auto;
}
.left{
width: 200px;
height: 100%;
background-color: skyblue;
float: left;
}
.center{
width: 580px;
height: 100%;
background-color: yellow;
float: left;
margin: 0 10px;
}
.right{
width: 200px;
height: 100%;
background-color: pink;
float: left;
}
.footer{
width: 1000px;
height: 150px;
background-color: silver;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="header"></div>
<div class="content">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
<div class="footer"></div>
</body>
</html>
网友评论