[html]页面导入样式时,使用link和@import有什么区别
区别如下:
- link是html标签,@import是css提供的
- link引入的样式页面加载时同时加载,@import引入的样式需等页面加载完成后再加载。
- link没有兼容性,@import不兼容ie5以下
- link可以通过js操作DOM动态引入样式改变样式,而@import不可以
引申:
css引入方式:行内样式,嵌入样式,链接样式,导入样式
[css]圣杯布局和双飞翼布局的理解和区别
圣杯布局
思路:先给中间div设置左右padding,然后给所有子标签浮动,中间子标签设置全宽度,左右子标签设置margin-left值使得三个标签位于同一高度,为了防止覆盖中间子标签
设置相对定位,给定left和right值填充左右边框
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head>
<body> <div class="hd">header</div> <div class="bd"> <div class="middle">middle</div> <div class="left">left</div> <div class="right">right</div> </div> <div class="footer">footer</div> </body> <style> .hd { height: 50px; background: #666; text-align: center; }
.bd { padding: 0 200px 0 180px; height: 100px; }
.middle { float: left; width: 100%; height: 100px; background: blue;
}
.left { float: left; width: 180px; height: 100px; margin-left: -100%; background: #00cc99; position: relative;
left: -180px; }
.right { float: left; width: 200px; height: 100px; margin-left: -200px; background: #00cc99; position: relative; right: -200px; } .footer { height: 50px; background: #666; text-align: center; } </style>
</html>
|
双飞翼布局
思路:给中间标签的子中间标签再设置一个子标签,在该子标签设置左右外边距,给左右子标签留出位置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div class="hd">header</div> <div class="middle"><div class="inside">middle</div></div> <div class="left">left</div> <div class="right">right</div> <div class="footer">footer</div> </body> <style> .hd { height: 50px; background: #666; text-align: center; } .middle { float: left; width: 100%; height: 100px; background: blue; } .left { float: left; width: 180px; height: 100px; margin-left: -100%; background: #0c9; } .right { float: left; width: 200px; height: 100px; margin-left: -200px; background: #0c9; } .footer { clear: both; height: 50px; background: #666; text-align: center; } </style> </html>
|
相同点:圣杯布局和双飞翼布局都是解决左右定宽,中间自适应的三栏布局。并且中间栏优先渲染。