边框
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> input{ border: none; /*清空border 样式*/ border-bottom: 1px solid red; } </style></head><body>用户名: <input type="text" name="" id=""></body></html>
内边框
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .div1{ width: 258px; height: 258px; padding:20px; /*垂直方向 水平方向 会增加盒子的大小*/ background-color: red; border: 1px solid black; } </style></head><body> <div class="div1"> 学海无涯 </div></body></html>
特殊情况
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .div1{ width: 200px; height: 200px; background-color: red; } .div2{ /*盒子如果没有宽度 则 padding 不会撑开盒子*/ background-color:#ccc; padding: 20px; } </style></head><body> <div class="div1"> <div class="div2"> nihao </div> </div></body></html>
margin居中对齐
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 600px; /*必须定义宽度 , 没有宽度 不会居中 */ height: 600px; background-color: #ccc; margin-left:auto; margin-right: auto; } </style></head><body> <div> 你好 </div> <div> 你好 </div> <div> 你好 </div></body></html>
外边距
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .div1{ width: 300px; height: 260px; background-color: #ccc; /* border: 1px solid transparent; 给父元素加上边框 */ /* overflow: hidden; */ padding-top: 40px; } .div2{ width: 200px; height: 100px; background-color: yellow; /* margin-top: 40px; */ } input{ margin:0 20px } </style></head><body> <div class="div1"> <div class="div2"> </div> </div></body></html>