I have a design I want to implement that involves title text appearing with its own background color, padded by 10px, over an image, par example:
http://i.stack.imgur.com/E7EpS.png
The first example in this picture works well, and is simple:
.greenbox {width:520px; height:261px; position:relative;}
.greenbox span { padding:0 10px; background:#000; position:absolute; left:0; bottom:40px; }
Trouble arises when the text overflows onto another line, then the span elements padding does not effect the text on the line breaks, it renders like so:
http://i.stack.imgur.com/pY18f.png
Anyone know of an alternative, or how they would set this design out so that the background color & padding was consistent?
Thanks in advance
Edit: I had simplified the code to make it concise, but had missed a vital part. Actually it's like this:
.greenbox {width:520px; height:261px; position:relative;}
.greenbox a {position:absolute; left:0; bottom:40px; }
.greenbox span { padding:0 10px; background:#000; }
With the html as:
<div class="greenbox">
<a href="link"><span>The Title Goes Here</span></a>
</div>
Thus the span remains inline, wrapped in a absolute position anchor.
I've tackled something similar before: Add padding at the beginning and end of each line of text
I've robbed that solution from myself, and fit it to your case.
Note that the line-height
and padding
adjustments can be very tricky to get right.
See: http://jsbin.com/ahoyug
HTML:
<div class="greenbox">
<a href="#"><span><span>
The Title Goes Here, with overflow
</span></span></a>
</div>
CSS:
.greenbox {width:500px; height:200px; position:relative; background:green}
.greenbox > a {
font: 50px sans-serif;
line-height: 1.14;
padding: 0;
border-left: 20px solid #000;
position: absolute;
left: 0;
bottom: 60px;
text-decoration: none;
color: #fff
}
.greenbox > a > span {
background: #000
}
.greenbox > a > span > span {
position: relative;
left: -10px
}
The somewhat easy way is to add border
to the left of a link and then add two wrappers, then position first to the left and the second back to the right, so it would like somehow like that: http://jsfiddle.net/kizu/fNGgN/4/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With