0

Here in my html, I don't know the header height. so how to make the content became scrollable on overflow?

.parent{
  border:2px solid red;
  position:fixed;
  top:0;
  left:0;
  width:20%;
  height:50%;
}

header{
  width:100%;
  border:1px solid red;
}

.content{
  flex:1;
  position: relative;
  overflow-y:scroll;
  background:lightgreen;
}
<div class="parent">
  <section>
    <header>
      <h1>Title</h1>  
    </header>
    <div class="content">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

      Why do we use it?
      It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
    </div>
  </section>
</div>  

2
  • try overFlow: scroll? Commented Jun 26, 2018 at 2:49
  • I tried with that, not works Commented Jun 26, 2018 at 2:51

2 Answers 2

3

I see you have the .content div with the flex:1; set you need to set the parent of your flex items to display:flex or your flexbox characteristics will not work. You also will probably want to have the flex-direction set to column. Also if you want flex items to fill the container your flex items need to be direct children of the parent that has the display:flex attached to it. So either remove the <section> or set the <section> to be the flexbox and give it the display:flex. Here is a snippet:

.parent{
  border:2px solid red;
  position:fixed;
  top:0;
  left:0;
  width:20%;
  height:50%;
  display:flex;
  flex-direction:column;
}

header{
  width:100%;
  border:1px solid red;
}

.content{
	position: relative;
  background:lightgreen;
  width:100%;
  flex:1;
  overflow-Y:scroll;
}
<div class="parent">
  <header>
    <h1>Title</h1>  
  </header>
  <div class="content">
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
  </div>
</div>  

Sign up to request clarification or add additional context in comments.

1 Comment

really need to Thumps up!!
0

You need to specify a height value for your .content class or else overflow won't work.

.parent{
  border:2px solid red;
  position:fixed;
  top:0;
  left:0;
  width:20%;
  height:50%;
}

header{
  width:100%;
  border:1px solid red;
}

.content{
  flex:1;
  position: relative;
  overflow-y:scroll;
  height: 250px;
  background:lightgreen;
}
<div class="parent">
  <section>
    <header>
      <h1>Title</h1>  
    </header>
    <div class="content">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

      Why do we use it?
      It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
    </div>
  </section>
</div>  

Edit: Use max-height if dynamic content is being used so a static height isn't acceptable. Then the content you receive from the backend will take up as much space as it needs until it reaches the max height value and then overflow.

5 Comments

I don't want to set the height here. If I set the height it works. I am getting content from backend, in case if the content overflows need to scroll. unless I don't want to set the height for minimal content(s)
@user2024080 Use max-height then. Then the content you receive from the backend will take up as much space as it needs until it reaches the max height value and then it'll overflow.
@user2024080 In that case you can add min/max height. But you need to add height to get scroll working
@JakeMiller - adding ` max-height:80%;` not works next.plnkr.co/edit/Ilm7tdcGXOOpV1Kb?open=lib%2Fscript.js, same case if I add the max-height:300px then it works. looks for px values
@user2024080 You need to use calc(80%) for max-height

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.