CSS Solution
Without knowing the structure of your HTML it's difficult to give an exact solution. However you do say that the button is to be displayed below the text. Therefore a CSS only solution could be to wrap both text and button in a div
with display:inline-block
so that its width shrinks to its contents. You would then set .button
to have width: 100%
, thus filling the width of its parent. Because .tekst
would be then be setting the width of the parent (remember, the parent is shrinking to fit its content), .button
would necessarily have the same width as tekst
.
CSS:
.tekst-button-parent {
display: inline-block;
}
.tekst {
...
}
.button {
width: 100%;
...
}
HTML:
<div class="tekst-button-parent">
<div class="tekst"> ... </div>
<div class="button"> ... </div>
</div>
You may need to further style tekst-button-parent
to occupy the same position in which your two elements currently reside.
JavaScript Solution
Alternatively you could use JavaScript to set the width of .button
to be the same as .tekst
everytime the window loads or resizes. If you only have the two occurrences of those divs then identifying the divs by className
will be easy.
<script>
var setButtonSize = function(event) {
var width = document.getElementsByClassName( "tekst")[ 0 ].innerWidth;
document.getElementsByClassName( "button")[ 0 ].style.width = width + "px";
};
window.onresize = setButtonSize;
window.onload = setButtonSize;
</script>
If you have more than one pair of .tekst
and .button
then you'll need to match each pair before resizing.