CSS
right aligned next to text

前端 未结 2 445
梦如初夏
梦如初夏 2020-12-06 07:55

I need a h2 that has a heavy stroke to the right of it. Like so:

2条回答
  •  一个人的身影
    2020-12-06 08:20

    What you need is a single element and an :after pseudo. P.S It's responsive.

    Demo

    Explanation: Here, the main part is to use overflow: hidden; on the element, and than am creating a virtual element using an :after pseudo with content property, and am positioning it absolute to the parent element which am setting to relative

    Hello World

    h2 { font-size: 20px; font-family: Arial; position: relative; overflow: hidden; } h2:after { display: inline-block; content: ""; height: 4px; background: #f00; position: absolute; width: 100%; top: 50%; margin-top: -2px; margin-left: 10px; }

提交回复
热议问题