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/>; }
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.
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.
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.
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/>')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With