How do I make a responsive div with scroll content in HTML?

Arthur Zopellaro

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)?

Arthur Zopellaro

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I make this right content responsive?

From Dev

Bootstrap - how to make a single div content not responsive?

From Dev

How do I make a single child div scroll?

From Dev

How do I make a div that "floats" above all the other content in HTML with CSS?

From Dev

how to make a DIV responsive css html

From Dev

How can I make an image in a div responsive?

From Dev

How do I make this code more responsive?

From Dev

How do I make this responsive layout with CSS?

From Dev

How do I make a background image responsive?

From Dev

How do I make a website responsive?

From Dev

How do i make the sidebar responsive

From Dev

How do I make my django app load content as I scroll?

From Dev

How to place Content DIV on bootstrap carousel and make it responsive?

From Dev

How can I make a div scroll horizontally

From Dev

How do i make a div responsive when its got relative positioning with left and right attributes

From Dev

How do I fix a sticky scroll on a mobile responsive website?

From Dev

How do I fix a sticky scroll on a mobile responsive website?

From Dev

How do I create a fixed background with scroll for a responsive site?

From Dev

How can i make content of an css table responsive

From Dev

How do i make something scroll like this?

From Dev

how to make content to be fixed inside scroll div using only css?

From Dev

how to make content to be fixed inside scroll div using only css?

From Dev

How do I make text in div lower opacity in HTML

From Dev

How do I have my html content scroll underneath my header elements?

From Dev

How do I have my html content scroll underneath my header elements?

From Dev

how can i make text wrapping in responsive div?

From Dev

How do I build the "To add content" page of a responsive website

From Dev

How to make responsive popup div?

From Dev

How make a div container responsive?

Related Related

  1. 1

    How do I make this right content responsive?

  2. 2

    Bootstrap - how to make a single div content not responsive?

  3. 3

    How do I make a single child div scroll?

  4. 4

    How do I make a div that "floats" above all the other content in HTML with CSS?

  5. 5

    how to make a DIV responsive css html

  6. 6

    How can I make an image in a div responsive?

  7. 7

    How do I make this code more responsive?

  8. 8

    How do I make this responsive layout with CSS?

  9. 9

    How do I make a background image responsive?

  10. 10

    How do I make a website responsive?

  11. 11

    How do i make the sidebar responsive

  12. 12

    How do I make my django app load content as I scroll?

  13. 13

    How to place Content DIV on bootstrap carousel and make it responsive?

  14. 14

    How can I make a div scroll horizontally

  15. 15

    How do i make a div responsive when its got relative positioning with left and right attributes

  16. 16

    How do I fix a sticky scroll on a mobile responsive website?

  17. 17

    How do I fix a sticky scroll on a mobile responsive website?

  18. 18

    How do I create a fixed background with scroll for a responsive site?

  19. 19

    How can i make content of an css table responsive

  20. 20

    How do i make something scroll like this?

  21. 21

    how to make content to be fixed inside scroll div using only css?

  22. 22

    how to make content to be fixed inside scroll div using only css?

  23. 23

    How do I make text in div lower opacity in HTML

  24. 24

    How do I have my html content scroll underneath my header elements?

  25. 25

    How do I have my html content scroll underneath my header elements?

  26. 26

    how can i make text wrapping in responsive div?

  27. 27

    How do I build the "To add content" page of a responsive website

  28. 28

    How to make responsive popup div?

  29. 29

    How make a div container responsive?

HotTag

Archive