我必须设置所有 h1 标签的样式,使其在 h1 文本前后都有图像。
我以前知道怎么加图片,但是不知道怎么加。
CSS(将 h1 样式设置为在文本之前显示图像)
h1 {
background-image: url('images/h_ltr.png');
background-position: left center;
background-repeat: no-repeat;
text-align: center;
font-size: 22px;
font-weight: bold;
color: #5d5d5d;
}
最佳答案
您可以使用 :before
和 :after
css 选择器。
h1:before {
background-color: green;
padding: 0 20px;
content: " ";
}
h1:after {
background-color: red;
padding: 0 20px;
content: " ";
}
<h1>Test</h1>
关于h1标签前后的css背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17322161/