@remmji
Posted
Hello 👋
There are few simple ways to center a div:
💡Flex:
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
💡Grid:
.container {
display: grid;
place-items: center;
height: 100vh;
}
💡Positioning:
div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
In regards to your second question. Flexible layouts like Flexbox and CSS Grid can make it easier to create responsive designs that work well on different screen sizes and devices. Using relative units like vw, vh, and % instead of absolute units like px or em can also help ensure that your designs remain responsive.
Additionally, it's important to keep in mind that HTML is designed to be responsive by default. When building a website or application, it's our responsibility as developers to ensure that our code and styles support and enhance this responsiveness, rather than hindering it. By using the appropriate units and layouts, we can build designs that are flexible and adapt to different screen sizes, rather than being rigid and difficult to use on smaller screens.
Hope those tips will help you :)
Marked as helpful