[英]align h1 before and after background
我在h1之前和之后都有图像。
但是,我需要将其定位如下:
h1
文本应该在中心 h1
应该从容器的左侧开始 h1
应该在容器的右侧结束 我不能得到所有这些。 例如,我可以居中h1文本,但之后是h1之前和h1之后图像未正确对齐。 这是jsfiddle的例子: http : //jsfiddle.net/wK8ve/
还有Html和css:
CSS:
.test {
border: 1px solid black;
width: 1000px;
height: 200px;
}
h1 {
text-align: center;
font-size: 22px;
font-weight: bold;
color: #5d5d5d;
margin: 0 0 32px 0;
}
h1:before {
text-align: left;
background-image: url('http://modeles-de-lettres.org/test/images/h_ltr.png');
background-repeat: no-repeat;
background-position: center left;
padding: 0 352px 0 0;
content: "\00a0";
}
h1:after {
background-image: url('http://modeles-de-lettres.org/test/images/h_rtl.png');
background-repeat: no-repeat;
background-position: center right;
padding: 0 180px;
content: "\00a0";
}
HTML:
<div class="test">
<h1>Test</h1>
</div>
以下是现场示例: http : //modeles-de-lettres.org/test/index.php?p = about_us
使用float
。
在你需要的前后部分
h1:before {
text-align: left;
background-image: url('http://modeles-de-lettres.org/test/images/h_ltr.png');
background-repeat: no-repeat;
background-position: center left;
padding: 0 352px 0 0;
content: "\00a0";
}
h1:after {
float: right;
background-image: url('http://modeles-de-lettres.org/test/images/h_rtl.png');
background-repeat: no-repeat;
background-position: center right;
padding: 0 180px;
content: "\00a0";
}
我假设这是你想要的,如果不澄清的话。
我想这就是你想要的。 我用img
代替:before
和:after
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.