2016-01-20 66 views
0

我为自己制作了一幅全幅图像,并添加了文字。 我一直在抓我的头,现在有很多时间。 我试图找到最佳的解决方案,以添加上下文边界的文本。H1标签边框长度可能吗?

但是,我想边界的长度是一半或更少,但我根本无法弄清楚。

在标签类之前,我尝试在文本容器div上使用边框,但我在对齐文本和获得正确对齐方面遇到了问题。

下面是它的是现在:

CSS:

.adcontainer { 
    position: relative; 
    width: 100%; 
    height: auto; 
} 
.adcontainer img { 
    width: 100%; 
    height: auto; 
} 
.adcontainertext { 
    position: absolute; 
    top: 25%; 
    left: 15%; 
    z-index: 0; 
    padding: 0; 
    padding: 1.2em; 
    font-size: .5em; 
    text-align: center; 
} 


.advertheading 
{ 
    font-size: 20px; 
    border-bottom: 1px solid white; 
    border-top: 1px solid white; 
    line-height: 100px; 
    display:inline-block 

} 

HTML:

<div style="clear: both;"> 
<div class="adcontainer"><img src="https://cdn.shopify.com/s/files/1/0786/5107/files/LARGE_BANNER-BELOW.jpg?5938182738858039286" /> 
<div class="adcontainertext"> 
<h2 class="advertheading" style="font-weight: normal; color: #ffffff;">Join the club</h2> 
</div> 
</div> 
</div> 

最好的问候, 罗宾。

回答

3

.adcontainer { 
 
    position: relative; 
 
    width: 100%; 
 
    height: auto; 
 
} 
 
.adcontainer img { 
 
    width: 100%; 
 
    height: auto; 
 
} 
 
.adcontainertext { 
 
    position: absolute; 
 
    top: 25%; 
 
    left: 15%; 
 
    z-index: 0; 
 
    padding: 0; 
 
    padding: 1.2em; 
 
    font-size: .5em; 
 
    text-align: center; 
 
} 
 

 
.adcontainertext h2:before { 
 
    content: ''; 
 
    border-top: 1px solid #FFF; 
 
    position: absolute; 
 
    width: 50%; 
 
    left: 25%; 
 
    top: 0; 
 
} 
 

 
.advertheading { 
 
    font-size: 20px; 
 
    line-height: 100px; 
 
    display:inline-block; 
 
    position: relative; 
 
} 
 

 
.adcontainertext h2:after { 
 
    content: ''; 
 
    border-bottom: 1px solid #FFF; 
 
    position: absolute; 
 
    width: 50%; 
 
    left: 25%; 
 
    bottom: 0; 
 
}
<div style="clear: both;"> 
 
    <div class="adcontainer"> 
 
    <img src="https://cdn.shopify.com/s/files/1/0786/5107/files/LARGE_BANNER-BELOW.jpg?5938182738858039286" /> 
 
    
 
    <div class="adcontainertext"> 
 
     <h2 class="advertheading" style="font-weight: normal; color: #ffffff;">Join the club</h2> 
 
    </div> 
 
    </div> 
 
</div>

+0

就像一个魅力。甚至不知道,之前和之后将工作。 再次,非常感谢。非常感激!最好的祝福。 – Robin

+1

没问题,upvote会很多appriciated :) –