admin管理员组

文章数量:1134232

I want to setup the following layout to my page: 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?

Updated html layout:

I want to setup the following layout to my page: 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?

Updated html layout:

Share Improve this question edited Jan 9 at 16:12 Flaviu_ asked Jan 7 at 18:56 Flaviu_Flaviu_ 1,34620 silver badges36 bronze badges 2
  • Why position: fixed? Use grid or flex. – Kosh Commented Jan 7 at 19:00
  • Tried, not work. Put everything on Layout 1 column. – Flaviu_ Commented Jan 7 at 19:05
Add a comment  | 

4 Answers 4

Reset to default 3

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>

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.

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>

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>

本文标签: cssSetup a portion of html page as scrollableStack Overflow