This happens because the em
will take, in this case, a percentage of the source size of the parent element, and not necessarily its own size (height/width
), so if in mobile you don’t use a breakpoint to set a new font size for the parent element a div.logo
is right to remain the same, as your reference has not changed.
That way, you can use the vw
Unit in the parent element or in the parent element itself div
. I explain more about this unit here.
Look at this example(or jsfiddle):
Note: In Stacksnippet click on
on the button Whole page and jsfiddle changes the window or iframe size manually
html, body {
margin: 0;
padding: 0;
}
#header{
font-size: 2vw;
}
#header .logo{
height: 180px;
box-sizing: border-box;
width: 100%;
text-align: center;
padding: 30px 0 0 0;
color: #666;
font-size: 5em;
font-weight: bolder;
text-transform: uppercase;
font-family: 'Raleway';
}
<div id="header">
<div class="logo">
<p>Font responsiva.</p>
</div>
</div>
Or you can create the breakpoints you said before. See that example. Notice that I change only the source of #header
.
I left the link pro canIUse in the other reply, rsrs. Great answer. ++
– Samir Braga
@Samirbraga upvote for another answer, very detailed ;)
– Guilherme Nascimento