I have the following code:
/* css */
.phone {
height: 100%;
width: 40%;
overflow: hidden;
padding: 0;
border-radius: 3%;
border: 2px solid red;
}
.phone .screen {
height: 50%;
overflow-y: auto;
background-color: #c3cee0;
}
.phone .nav {
background-color: black;
overflow: hidden;
color: white;
}
<!-- HTML -->
<div class="phone">
<div class="screen">
<p>Lorem Ipsum...</p>
...
<p>Lorem Ipsum...</p>
</div>
<div class="nav">
<p>Back</p>
<p>Home</p>
<p>Menu</p>
</div>
</div>
I want the phone to be responsive but in order to enable the scroll in the div.screen
I need to set the height
of the div.phone
. The problem is that the red border
is going beyond the phone's content.
I'd like the border to finish where the div.nav
ends but I'm getting unwanted extra space. See this live demostration.
TL;DR
Live demostration.
I need to set a height
(for div.phone
) in order to enable the scroll
for the text messages but then I get that extra space shown by the red border. How can I make div.phone
(red border) be the same height of the whole content (without the extra space)?
I fixed the issue by using display: flex
. Live demonstration.
Basically
.phone {
height: 50%; /* whatever height you need */
display: flex;
flex-direction: column; /* used to separate the divs vertically */
/* instead of horizontally */
border-radius: 3%;
border: 2px solid red;
}
.phone .screen {
flex: 9; /* screen will take 9/10 spaces from the div.phone */
overflow-y: auto; /* enables scroll */
}
.phone .nav {
flex: 1; /* nav will take 1/10 spaces from the div.phone */
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments