A simple example using @media query . For% s of% s to be responsive you can use as a unit of measure the percentage div
(or %
, of viewport width ).
In your case, two% with% s as if they were two columns, half a half, you could use:
body{
margin: 0;
}
main{
display: flex;
}
.coluna{
width: 46%;
background: yellow;
padding: 2%;
}
@media screen and (max-width: 600px){
main{
display: block;
}
.coluna{
width: 100%;
}
}
<main>
<div class="coluna">
div 1
</div>
<div class="coluna">
div 2
</div>
</main>
As the half would be
vw
but I used an internal space of
div
, I discount the sum of the values of each side (left and right, equal to 4%) and deduct in width of
50%
, getting 46% (50% -4% = 46%).
Where 2%
means that when the width of the screen is up to 600 pixels, the @media rule , that is, up to 600 pixels wide of the screen, the two div
s will occupy the total width of the screen ( (max-width: 600px)
) being one below the other. Above% with% of one will stand side by side.
This value of div
you should set according to the content of each 100%
, which you think is best suited visually. It may be a bit larger or smaller, it will depend on your layout .
It should be remembered that the content of each 600px
should also have styles that adapt to the width of the% s-country% s (images, internal divs, texts, etc.). Everything must have relative dimensions.
You can also create other 600px
to change the properties of elements for each screen dimension, it will also depend on your layout and what you want to do.
In responsiveness everything is relative, it will depend on the content you are going to use, define maximum dimensions (as div
), minimums (as div
), and a multitude of criteria based on the content you want to display
You also need to include the tag below in div
so that the mobile browser recognizes the screen's dimensions and scale ( more about this in this link ):
<meta name="viewport" content="width=device-width, initial-scale=1.0">
You can take a look at this tutorial on responsiveness.