I have a simple HTML and CSS code. I am using CSS calc
function to create fluid typography.
Hover when I make the window smaller, the image overlaps the text. The issue disappears when I use fixed font-size like 3rem
instead of calc
function.
Is there any way to stop overlap while using CSS calc
funciton?
<div>
<h1>
This is a loooooong title
</h1>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/Shaqi_jrvej.jpg/1200px-Shaqi_jrvej.jpg">
</div>
div {
display: flex;
flex-wrap: wrap;
}
div img {
width: 400px;
height: 100%;
}
div h1 {
/*It works when I set fixed font-size size like "3rem" */
font-size: calc(1.625rem + 5.075vw);
width: 300px;
}
2
Answers
to fix this, you can make two changes: add gap between the two elements and implement word-wrap strategy that way:
you can just set a dynamic width to h1 like :
the h1 with gonna change if screen size change