Home >Web Front-end >HTML Tutorial ># HTML && CSS
1. The Div is centered left and right
<div>1<div>div{ width;300px;height:300px;margin:0 auto; }
2. The Div is centered up, down, left, and right
<div class='father'> <div class='son'></div></div>.son{position:absolute;top:50%;left:50%;width:300px;heigeht:300px; margin-top:-150px; /*等于高度的一半*/margin-left:-150px; /*等于宽度的一半*/}
3. The background image is centered up, down, left, and right
background-position:center;
4. The border becomes a small triangle
We get a small triangle with a width of 10px, a black downward direction, and the background The color is red
div{ width:0; height:0; border:10px solid red; border-top-color:black; }
5. About line wrapping
white-space:nowrap;/*不换行*/ white-space:normal;/*换行*/
6. Regarding the transmission problem of margin-top
It can be solved by adding a border to its parent element
7. Clear the default style
body,h1,h2,h3,h4,h5,h6,dl,dd,p{marhon:0;} ul,ol{margin:0; padding:0;} th.td{padding:0;}
8. Table
<table border='1'> <thead><tr><th>sex</th><th>age</th></tr></thead> <tbody> <tr><td>man</td><td>18</td></tr> <tr><td>female</td><td>28</td></tr> </tbody> table{border-collapse:collapse;} 跨行合并:rowspan; 跨列合并:colspan;
9. Form
/*for和id相同*/<label for='username'>用户名</lable> <input type='text' id='username' value='Input your name'/>
10. Clear float
.clearfix:after{ display:block; content:''; clear:both; } .clearfix{ zoom:1; /* for IE6*/ }