skip to Main Content

I want to setup the following layout to my page:
My desirable html layout
To split the page in two, I wrote:

    <style>
    body {
        font-family: Arial;
    }
    
    
    .split {
        height: 100%;
        width: 50%;
        position: fixed;
        z-index: 1;
        top: 0;
        overflow-x: hidden;
    }
    
    
    .left {
        left: 0;
    }

.right {
    right: 0;
....

and

<body>
        <div class="split left">
            .. content layout 1
        </div>
        <div class="split right">
            <div class="so">
                some content layout 2
            </div>
            <div class="layout3">
                .... long content ...
            </div>
    </body>

how can I setup Layout 3 to be scrollable, but not Layout 2?

4

Answers


  1. In your CSS, set the overflow property:

    .layout3 { overflow: scroll; }
    

    This will add scrollbars and allow scrolling of the long content in the layout3 box; you can find out more about overflow at https://developer.mozilla.org/en-US/docs/Web/CSS/overflow.

    If you don’t want the horizontal scrollbar, and the content is guaranteed to wrap and never be wider than the box, you can use

    .layout3 { overflow-y: scroll; }
    

    instead.

    Login or Signup to reply.
  2. To make the content scrollable, you need to specify a height, and add overflow-y: auto; or overflow-y: scroll;. This is the extra css:

    .layout3 {
        height: 80px;
        overflow-y: auto;
    }
    
    .split {
        height: 100%;
        width: 50%;
        position: fixed;
        z-index: 1;
        top: 0;
        overflow-x: hidden;
    
    }
    .left {
        left: 0;
    }
    .right {
        right: 0;
    }
    .layout3 {
        background-color: cyan;
        height: 80px;
        overflow-y: scroll;
    }
    <div class="split left">
        .. content layout 1
    </div>
    <div class="split right">
        <div class="so">
            some content layout 2
        </div>
        <div class="layout3">
            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vel incidunt architecto ad id temporibus neque dignissimos minima aperiam voluptates beatae mollitia, porro, distinctio sint quibusdam possimus dolore laudantium a corporis nisi facilis earum numquam! Temporibus nisi quos fugiat exercitationem ut corrupti vitae itaque voluptas, magni sint, quam tempore praesentium eius saepe enim veniam, perspiciatis aperiam nihil ad facilis quasi? Ut hic ex doloremque libero, magnam iusto. At non incidunt impedit deserunt qui repudiandae voluptatum culpa nulla sunt reiciendis ut vero cupiditate quasi mollitia, enim dolor reprehenderit excepturi perferendis dolorem quod, quaerat dolores quam dolorum fugit! Possimus dolorem harum eaque illo.
        </div>
    Login or Signup to reply.
  3. Here is an idea using CSS grid:

    body {
      margin: 0;
      height: 100vh;
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      grid-template-rows: min-content auto;
    }
    
    .layout1 {
      grid-row: span 2;
    }
    .layout3 {
      contain: size;
      overflow: auto;
    }
    
    
    body > * {
      border: 1px solid;
      padding: 10px;
    }
    <div class="layout1">
      .. content layout 1
    </div>
    <div class="layout2">
      some content layout 2 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque pulvinar semper condimentum. r</div>
    <div class="layout3">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque pulvinar semper condimentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Etiam tristique justo fermentum cursus hendrerit. Vivamus varius, eros ornare rhoncus finibus, mauris ante sagittis erat, at laoreet enim ante quis quam. Cras dolor tellus, mattis ac posuere in, tempor id erat. In ac ipsum sit amet magna rhoncus convallis sit amet ac felis. Donec ligula dolor, lacinia in ante vel, luctus venenatis velit. Ut scelerisque, risus sed scelerisque varius, leo augue viverra sapien, 
    </div>
    Login or Signup to reply.
  4. Using flex:

    * {
      box-sizing: border-box;
    }
    
    body {
      display: flex;
      flex-flow: column wrap;
      height: 100vh;
      width: 100vw;
      margin: 0;
      padding: 10px;
    }
    
    body>* {
      flex: 1 1;
      width: 50%;
      border: 1px solid;
      padding: 10px;
    }
    
    .layout1 {
      flex: 0 0 100%;
    }
    .layout2 {
      flex: 0 1;
    }
    
    .layout3 {
      overflow: auto;
    }
    <div class="layout1">
      .. content layout 1
    </div>
    <div class="layout2">
      some content layout 2 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque pulvinar semper condimentum. r</div>
    <div class="layout3">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque pulvinar semper condimentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Etiam tristique justo fermentum cursus hendrerit. Vivamus varius, eros ornare rhoncus finibus, mauris ante sagittis erat, at laoreet enim ante quis quam. Cras dolor tellus, mattis ac posuere in, tempor id erat. In ac ipsum sit amet magna rhoncus convallis sit amet ac felis. Donec ligula dolor, lacinia in ante vel, luctus venenatis velit. Ut scelerisque, risus sed scelerisque varius, leo augue viverra sapien.
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque pulvinar semper condimentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Etiam tristique justo fermentum cursus hendrerit. Vivamus varius, eros ornare rhoncus finibus, mauris ante sagittis erat, at laoreet enim ante quis quam. Cras dolor tellus, mattis ac posuere in, tempor id erat. In ac ipsum sit amet magna rhoncus convallis sit amet ac felis. Donec ligula dolor, lacinia in ante vel, luctus venenatis velit. Ut scelerisque, risus sed scelerisque varius, leo augue viverra sapien
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search