Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal Line in Background using Css3

How to implement this type of style to text using only css3, means a horizontal line in the middle of the tag... Can it be possible using pure css...

enter image description here

Here's my structure:-

<p class="datedAside">4 weeks ago</p>
like image 992
SaurabhLP Avatar asked Jul 09 '12 09:07

SaurabhLP


People also ask

How do I add a horizontal line in CSS?

Its simple to add a horizontal line in your markup, just add: <hr>. Browsers draw a line across the entire width of the container, which can be the entire body or a child element.

How do I insert a horizontal line in HTML?

The <hr> tag defines a thematic break in an HTML page (e.g. a shift of topic). The <hr> element is most often displayed as a horizontal rule that is used to separate content (or define a change) in an HTML page.

How do I print a horizontal line in HTML?

The <hr> tag in HTML stands for horizontal rule and is used to insert a horizontal rule or a thematic break in an HTML page to divide or separate document sections. The <hr> tag is an empty tag, and it does not require an end tag.


2 Answers

You can achieve this with pure css using linear gradient as background:

<p class="datedAside">4 weeks ago</p>
<style>
p {
    background: linear-gradient(180deg, 
        rgba(0,0,0,0) calc(50% - 1px), 
        rgba(192,192,192,1) calc(50%), 
        rgba(0,0,0,0) calc(50% + 1px)
    );
}
</style>

https://jsfiddle.net/klesun/aujrkpLk/

like image 98
Klesun Avatar answered Sep 17 '22 08:09

Klesun


Here's one way to do it by adding a span inside the p.

HTML:

<p class="datedAside"> <span> 4 weeks ago </span> </p>​

CSS:

p {background: #000; height:1px; margin-top:10px;}
p span{background: #fff; padding:10px; position:relative; top:-10px; left: 20px}​

DEMO: http://jsfiddle.net/9GMJz/

like image 44
tb11 Avatar answered Sep 19 '22 08:09

tb11