Adding
using the :after selector

后端 未结 5 1237
甜味超标
甜味超标 2021-02-07 02:03

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

5条回答
  •  春和景丽
    2021-02-07 02:43

    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('
    ')

提交回复
热议问题