表格
把两个单元格相邻的边框线合并为一条线,去掉表格边框之间的空隙
要放在<table></table>
里
border-collapse:collapse;
设置表格悬停样式
td:hover{background: blue;color: yellow;}
列表
给列表加图标
ul li{list-style-image: url(img/1145584.gif)};
列表位置
ul{list-style-position:outside;}
ul{list-style-position:inside;}
浮动
让纵向排列的列表横排
列表浮动,并加大宽度,不让前边图标挡住后边的字
{float: left;width: 100px;}
一个元素浮动以后,它将不再具备块级元素的换行效果
如果左浮动,它会位于一行的左边,默认左对齐
去掉列表前符号
ol li{list-style-type: none;}
清除前边浮动元素对它的影响
style="clear:both;"
边距
内边距
pedding不允许为负值
width: 400px;height: 400px;border: 1px solid red;
padding-left:100px;padding-top: 50px;
不写方向表示上下左右都是100px
padding: 100px;
此时宽、高都多了200px
在边框上减去200px即可
写两个表示上下、左右
padding: 50px 100px;
写三个表示上、左右、下
padding: 50px 100px 200px;
写四个表示上、右、下、左
padding: 50px 100px 200px 200px;
外边距
margin可以为负值
让边框在水平方向居中
margin: 0px auto;
或使用相对尺寸vw
width:80vw;height: 300px;border: 1px solid red;
margin: 0px 10vw;
vw:将窗口的宽度等分为100份,每一份就是1vw
vh:将窗口的高度等分为100份,每一份就是1vh
例如20vw表示宽度为窗口的20%
边距多用于实现搜索框
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.input{
width: 300px;height: 38px;border: 1px solid red;
border-radius: 6px 0px 0px 6px;
font: 16px/38px "微软雅黑";
background: url(img/search.png) no-repeat;
padding-left: 40px;
}
</style>
</head>
<body>
<input type="text" name="search" class="input" />
</body>
</html>
尺寸
当使用相对大小vw和vh时,大小会根据当前窗口的拉伸而拉伸
此时可以设置尺寸限制
最大尺寸
max-width:200px;
max-height:100px;
最小尺寸
min-width:100px;
min-height:80px;
浮动和清除
当一个div元素浮动起来,它所占据的空间就会被释放,后面的元素就会占据它的位置
float:left;
清除前边的浮动对后边元素产生的影响
clear:both;
让图片和文字中线对齐
img{vertical-align: middle;}