Reputation: 5928
I am trying to make dynamic padding within a container and are having some trouble with that.
If I for example have this html
<div class="sections-container">
<div class="section"> </div>
<div class="section"> </div>
</div>
and this styling
.sections-container {
border: 1px solid black;
width: 90%;
height: 400px;
padding: 2.4rem;
}
.section {
border: 1px solid black;
width: 100%;
height: 100px;
margin-top: 24px;
}
then the padding in the container is hardcoded to be 24px. You can see it at this stackblitz example: https://stackblitz.com/edit/typescript-yw8xyp?file=style.css.
What I am trying to achieve is:
So when the container hit a specific size - then the padding should change dynamically - increase or decrease dependinding on the container size. I am trying to do this only using CSS - if that is even possible :D
Does someone know how to do this? Thanks in advance :)
Upvotes: 0
Views: 2469
Reputation: 457
You can achieve adaptive padding, using a variable for the width like this: https://stackblitz.com/edit/typescript-u26fhc?embed=1&file=style.css
For min and max you need media queries
Upvotes: 3
Reputation: 209
i guess you want padding in all 4 sides. use display flex
.sections-container {
border: 1px solid black;
width: 80%;
height: 400px;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.section {
border: 1px solid black;
width: 70%;
height: 100px;
}
Upvotes: 1