Reputation: 77
I am trying to figure out the overflow property
So to middle an element using margin:auto
property it has width
defined but,
what is the requirement for centering an element vertically with respect to its container/parent?
With current set up overflow happens so,
when does the overflow auto expands the container to fit the overflow element ???
div {
margin: 200px auto;
height: 100%;
width: 60%;
border: 10px solid red;
text-align: center;
}
body {
height: 300px;
min-height: 500px;
padding: 0;
border: 10px solid yellow;
overflow: auto;
}
<div>
somet text
</div>
Upvotes: 0
Views: 98
Reputation: 1398
Just a few things about your current code:
To answer your question though, I think that you can easily do what you want using the new flexbox display option. Here is an example:
body {
padding: 0;
border: 10px solid yellow;
height: 300px;
display: flex;
}
div {
height: 60%;
width: 60%;
border: 1px solid red;
text-align: center;
overflow: auto;
margin: auto;
}
<div>
somet text
<br><br><br><br> somet text
<br><br><br><br> somet text
<br><br><br><br> somet text
<br><br><br><br> somet text
<br><br><br><br> somet text
<br><br><br><br>
</div>
Upvotes: 1