Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding <hr/> using the :after selector

Tags:

I'm trying to "automatically" add a horizontal-rule after each article in my page. Is there a way of doing this using the :after selector? I'm hoping to be able to style it something like this:

article {     padding: 10px; }  article:after {     content: <hr/>; } 
like image 329
dvn928361 Avatar asked Dec 23 '13 02:12

dvn928361


People also ask

How do you add HR 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 you add a HR 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.

What is the use of HR /> tag?

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.


1 Answers

This is impossible with pure CSS, but you could use a border and margins to look like a hr:

article {     margin: 3px 0px;      border-bottom: 1px solid black; } 

Or you could use JavaScript:

var articles = document.getElementsByTagName('article') for (var i = 0; i < articles.length; i ++) {     articles[i].parentNode.insertBefore(document.createElement('hr'), articles[i].nextSibling) } 

Or easier in jQuery:

$('article').after('<hr/>') 
like image 186
tckmn Avatar answered Sep 18 '22 15:09

tckmn