css - How to create a flexible leader line in div after a label field -
<div class="titelcontent"> <div class="name">name</div> <div class="hzline"></div> </div>
i want name
div , hzline
div auto fit 100% in titelcontent
.
the label (for example, name) vary in length , want red underline span remainding space of titlecontent
div.
how achieve following? easy using tables can't figure out how via span
or div
.
updated allow background images show through
you can make mark-up bit tighter using pseudo-element follows:
<div class="wrapper"> <div class="inner">photoshop</div> </div>
and use following css styling:
div.wrapper { color:#82439a; font-size: 16px; font-weight: bold; font-family: tahoma; line-height: 180%; background: red url(http://placekitten.com/1000/500) no-repeat left top; overflow: hidden; } div.inner { position: relative; display: inner; color: yellow; padding-right: 0.50em; border: 1px dotted yellow; } div.inner:after { content: "\a0"; position: absolute; bottom: 0; left: 100%; border-bottom: 5px solid #d71d00; width: 1000%; }
demo fiddle: http://jsfiddle.net/audetwebdesign/we8bc/
how works
the parent element div.wrapper
may contain background image or transparent , show background of ancestor element. need set overflow: hidden
.
for label (<div.inner>
), set position: relative
, generate 100% width pseudo-element bottom border serve underline. use absolute positioning place div.inner:after
right of <div.inner>
(left: 100%
) , make width relatively large. pseudo-element trigger overflow condition taken care of hiding overflow in parent element. can control left/right spacing using padding.
you can use set display
property either inline
or inline-block
. if use display: inline
, work in ie7; adjust line height needed styling.
note generated content non-breaking space, hex code "\a0".
support ie7
if need support ie7, need hack if use inline-block
discussed in previous question: ie7 not understand display: inline-block
ie7 not support table-cell
of other posted solutions face same limitation.