0


I can't get the result a paragraph in html and css. I'd like to set 2 lines (or 2 borders) between a text, like this:

---- TEXT ---- 

How can I do this using CSS or something like that?

Vinicius Lima
  • 534
  • 7
  • 20

5 Answers5

4

You can try with :before and :after pseudo elements like this:

html

<p>Test</p>

css

p:before{
    content:"----";
}

p:after{
    content:"----";
}

fiddle

Alex Char
  • 32,879
  • 9
  • 49
  • 70
2

Here's a quick and easy way, so long as your background is a solid color.

HTML:

<p class="myCopy">
    <span>My Text goes here</span>
</p>

CSS:

.myCopy {
    display: block;
    height: 10px;
    border-bottom: solid 1px #000;
    text-align: center;
}

.myCopy span {
    display: inline-block;
    background-color: #fff;
    padding: 0 10px;
}

Adjust the height value of .myCopy to move the line up and down. Change the background color of the inner span to match the primary background color.

EDIT: here's a fiddle - FIDDLE!!!

relic
  • 1,662
  • 1
  • 16
  • 24
1

From the top answer of CSS Title with Horizontal Line on either side

How about this:

<h1 class='strikearound'>Lined Title</h1>
h1.strikearound {
    position: relative;
    font-size: 30px;
    z-index: 1;
    overflow: hidden;
    text-align: center;
}
h1.strikearound:before, h1.strikearound:after {
    position: absolute;
    top: 51%;
    overflow: hidden;
    width: 50%;
    height: 1px;
    content: '\a0';
    background-color: grey;
}
h1.strikearound:before {
    margin-left: -50%;
    text-align: right;
}

Demo in fiddle

What's nice is it doesn't rely on any particular background color

Screenshot:

screenshot

Community
  • 1
  • 1
KyleMit
  • 30,350
  • 66
  • 462
  • 664
0

You can use a paragraph <p> or a line-break <br> tag to separate text. Additionally, a horizontal rule <hr> tag will create a horizontal line to separate text.

rageandqq
  • 2,221
  • 18
  • 24
0

You can use position: relative to move children on bottom border for solid color.

Html:

<p class="myCopy">
    <span>My Text goes here</span>
</p>

Css:

.myCopy {
    display: block;
    border-bottom: solid 1px #000;
    text-align: center;
}

.myCopy span {
    position:relative;
    bottom: -10px;
    display: inline-block;
    background-color: #fff;
    padding: 0 10px;
}

Styled version: http://jsfiddle.net/UnG4T/1/

Or you can use 100% width :after and :before with negative margin for other bg

.myCopy {
    position: relative;
    display: block;
    text-align: center;
}

.myCopy::before, .myCopy::after{
    content: "";
    position: absolute;
    top: 50%;
    display: inline-block;
    width: 100%;
    border-bottom: solid 1px #000;
}

.myCopy::before{
    margin-left: -100%;
}

.myCopy span {
    display: inline-block;
    padding: 0 10px;
}

Styled version: http://jsfiddle.net/UnG4T/3/

Kinga
  • 386
  • 1
  • 8