: Determine content length to have a dynamic hr tag Is there a way to determine the length of the content contained inside an h2 element, which changes. So an hr tag can be set to the same
Is there a way to determine the length of the content contained inside an h2 element, which changes. So an hr tag can be set to the same length plus some additional width?
so it would look sort of like
I tried some psuedocode to explain what I mean. I would move this to a css rule of course
<h2>SOME RANDOM TITLE LENGTH</h2>
<hr style=width_of_H2_plus_5% />
More posts by @Si4351233
3 Comments
Sorted by latest first Latest Oldest Best
Why not just set the h2 style to underline? H2 is a block element. The hr should be unnecessary.
If it's OK to use float or absolute positioning then you could try the following:
<div style="float: left; width:auto;">
<h2>SOME RANDOM TITLE LENGTH</h2>
<hr style="width: 110%; margin-left: -5%;"/>
</div>
Unfortunatley, I don't think width:auto works with static or relative positioning.
I don't believe it's possible purely with HTML & CSS. You could, however, use some JavaScript to calculate the width of your <h2> and then make your <hr>'s width <h2>'s + 5%. You can use the window.onload and window.onresize events to update the width of your <hr> as the size of the window changes.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.