2

How to create a line in the middle of the text, the line must occupy the entire length of the div? Like this, the parentheses indicate the start and the end of div:

[Text ------------------ Text]

2 Answers2

6

using psuedo elements, see that Working Fiddle

HTML:

<div><span>Left</span><span class="right">Right</span></div>

CSS:

span
{
    background-color: white;
}
.right
{
    float: right;
}

div
{
    position: relative;
}
div:before
{
    content: '';
    display: block;
    width: 100%;
    border-top: 1px solid black;
    position: absolute;
    bottom: 50%;
    z-index: -1;
}

You can apply padding: 0 15px; on the span for better result..

avrahamcool
  • 13,888
  • 5
  • 47
  • 58
2

Would this work?

div { width: 80%; }
hr { position: relative; top: 0.4em; }
span.left { float: left; padding-right: 0.5em; }
span.right { float: right; padding-left: 0.5em; }

<div>
    <span class="left">Text</span>
    <span class="right">Text</span>
    <hr/>
</div>
Douglas
  • 36,802
  • 9
  • 76
  • 89