It can be done. I used vw units.
Take a look at the working script
HTML:
<h1 class="SpecialBorder">Title</h1>
CSS
* { margin: 0; padding: 0; } .SpecialBorder { display: inline-block; position: relative; } .SpecialBorder:before , .SpecialBorder:after { content:''; position: absolute; left: 0; bottom: 0; } .SpecialBorder:before { width: 100vw; border-bottom: 1px solid red; } .SpecialBorder:after { width: 100%; border-bottom: 1px solid blue; }
Explanation: before and after pseudo-elements are those that draw borders. both of them are empty elements. with a certain width that makes their border be visible.
they are absolutely located at the bottom of their parent <h1> .
before : responsible for the red border. therefore, its width is set to "100%" of the viewing port. after : responsible for the red border. therefore, the hes width is set to 100% its parent ( <h1> ), so h1 set to `display: inline-block; '(therefore, it will cover only that and its contents)
vw is only supported for new browsers .
note that if you cannot use vw units, you can still do something familiar. remove display:inline-block; from h1 (making it break again) change the width before to 100% (so that it completely covers the whole path), change the value from after to some fixed value of your choice.
Edit: as pointed out in thgaskell comments,
There is an error in which vw units are not updated properly on webkit browsers when resizing a window.
Edit 2: You can use the <br /> tag or cleanup methods such as shown here to create the items that appear after the name.
source share