A simple example using @media query. So that the div
s are responsive you can use as unit of measure the percentage %
(or vw
, of viewport width).
In your case, two div
as if they were two columns, half and 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 half would be 50%
but I used an internal spacing of 2%
, i discount the sum of the values of each side (left and right, equal to 4%) and deduct in the width of the div
, 46% (50% - 4% = 46%).
Where it has (max-width: 600px)
means that when the width of the screen is up to 600 pixels, the styles of the @media Rule, that is, up to 600 pixels of screen width, the two div
s will occupy the full width of the screen (100%
) one below the other. Above 600px
one will stand beside the other.
That value of 600px
you must define according to the content of each div
, what you think best fits visually. It may be a slightly higher or lower value, it will depend on your layout.
It is worth remembering that the content of each div
should also have styles that suit the width of div
s-parents (images, internal Ivs, texts etc.). Everything must have relative dimensions.
You can also create other @media queries
to change the properties of elements for each screen dimension, will also depend on your layout and what you want to do.
In responsiveness everything is relative, it will depend on the content you will use, set maximum dimensions (such as max-width
), minimum (as min-width
), and another plethora of criteria based on the content you want to display.
You also need to include the tag below in head
so that the mobile browser recognizes the size and scale of the screen (more about this link):
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Can give a study in this tutorial on responsiveness.
No need for frameworks, just use @media queries.
– Sam