I’m trying to get a logo in a div to appear bigger proportionally on mobile than on desktop. It looks great at 100% width on mobile, but on desktop it’s way too big. How could I scale the div’s width percentage down as the screen gets bigger? Essentially going from 100% at the lowest screen dimension to 30% at the highest.
.outer {
display: table;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
.middle {
display: table-cell;
vertical-align: middle;
}
.inner {
margin-left: auto;
margin-right: auto;
width: 3%;
}
#logo {
width: 100%;
height: auto;
}
<div class="outer">
<div class="middle">
<div class="inner" style="max-width:100vw;">
<img id="logo" src="https://via.placeholder.com/100">
</div>
</div>
</div>
4
Answers
Using media queries is a way to change CSS for different screen sizes like this:
Instead of
max-width
you could also usemin-width
to indicate that the screen should have this width at minimum for the styles to apply. You could even useprint
instead ofscreen
to apply styles for when a user wants to print the page (e.g. press CTRL + P to print a page).You can set the adaptive size of the logo without media query using the
clamp()
function.In the example below, the logo will increase in size from minimum
100px
to maximum200px
and the preferred value in20vw
:You can do it just with media queries.
which means for screens smaller than 768 pixels. you can change this value if you want.
Use
clamp()
. Here a basic example where I am using random values to illustrate the trick. The image will go from100px
on big screen to400px
on smaller.