[英]align h1 before and after background
I have image before and after h1. 我在h1之前和之后都有图像。
However, I need to position it as following: 但是,我需要将其定位如下:
h1
text should be in the center h1
文本应该在中心 h1
before image should start at the left side of container 图像之前的h1
应该从容器的左侧开始 h1
after image should end at the right side of container 图像后的h1
应该在容器的右侧结束 I cannot get all of them. 我不能得到所有这些。 For example, I can center h1 text, but then h1 before and h1 after images are not aligned correctly. 例如,我可以居中h1文本,但之后是h1之前和h1之后图像未正确对齐。 Here is jsfiddle example: http://jsfiddle.net/wK8ve/ 这是jsfiddle的例子: http : //jsfiddle.net/wK8ve/
Also Html and css here: 还有Html和css:
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: HTML:
<div class="test">
<h1>Test</h1>
</div>
And here is live example: http://modeles-de-lettres.org/test/index.php?p=about_us 以下是现场示例: http : //modeles-de-lettres.org/test/index.php?p = about_us
use float
. 使用float
。
In your before and after sections you will want 在你需要的前后部分
http://jsfiddle.net/wK8ve/1/ http://jsfiddle.net/wK8ve/1/
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";
}
I'm assuming this is what you want anyway, if not clarify. 我假设这是你想要的,如果不澄清的话。
I guess this is what you want. 我想这就是你想要的。 I used img
instead of :before
and :after
我用img
代替:before
和:after
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.