为什么这样子不显示伪类设置的样式,我设置了定位才能显示
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style> h1:before{ width:100px; height:5px; background:red; content:"";} h1:after{ width:100px; height:5px; background:#000; content:"";} </style> </head> <body> <h1>和哈哈哈哈哈哈哈哈哈</h1> </body> </html>
因为
:before和:after的display属性默认为inline. 行内非替换元素不适用width或height属性。改成display: block即可。一周热门 更多>