How can I scroll content inside div but not scroll parent container? - css

I have grid based layout with two columns (aside and section) inside container (main). Every column should be scrollable separately but container should not be scrollable at all. The heights of both columns are dynamic but container has fixed height.
I've tried two approaches with overflow-y on parent container :
With overflow-y: scroll but .... When I finish scrolling inside one of child divs e.g (aside) the whole container(main) starting to scroll what is not I want.
With overflow-y: hidden but .... then content inside scrollable child divs is cut, like
here:
cut content inside child scrollable divs when parent has overflow-y to hidden
I've also tired with overscroll-behaviour property but it seems to be not working, I have no clue why.
main {
display: grid;
grid-template-columns: 336px 2fr;
overflow-y: scroll;
/*hidden cuts my content */
max-height: 400px;
}
section {
max-height: 100vh;
border: 1px solid black;
overflow-y: scroll;
--webkit-overscroll-behavior-y: none;
}
aside {
border: 1px solid blue;
display: flex;
flex-direction: column;
justify-content: flex-start;
overflow-y: scroll;
max-height: 100vh;
--webkit-overscroll-behavior-y: none;
}
div {
display: flex;
max-width: 304px;
border: 1px solid red;
background-color: lightgreen;
margin-bottom: 12px;
padding: 15px;
}
<main>
<aside>
<div>
Text 1
</div>
<div>
Text 2
</div>
<div>
Text 3
</div>
<div>
Text 4
</div>
<div>
Text 5
</div>
<div>
Text 6
</div>
<div>
Text 7
</div>
<div>
Text 8
</div>
<div>
Text 9
</div>
</aside>
<section>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla at lacus nisl. Aliquam sed elit vel nisi egestas fringilla non eget metus. Nam tempus vehicula massa, et pharetra orci pulvinar eu. Etiam tincidunt arcu nisl, ac porttitor felis ornare eget.
Suspendisse feugiat posuere dui, id imperdiet nisl tincidunt vel. Duis ut tempus purus. Nulla facilisis lobortis sagittis. Fusce risus augue, hendrerit id nisi sed, luctus imperdiet sem. Phasellus vestibulum scelerisque massa, tincidunt porta lectus
gravida non. Integer egestas ipsum eros. Duis a ultrices odio. Curabitur justo lectus, ultricies quis urna eget, interdum scelerisque felis. Nullam eleifend est in efficitur vulputate. Praesent sit amet vulputate nibh, at vulputate dui. Nulla facilisi.
Praesent sollicitudin mi nec sem sollicitudin, et aliquam diam rutrum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent finibus justo sem, vitae tincidunt mi consequat in. Aliquam ullamcorper ultrices
nulla, at dapibus nulla hendrerit eget. Nullam sit amet libero a magna dictum mattis. Suspendisse hendrerit suscipit augue, vel congue sapien tincidunt nec. Donec volutpat tempor felis ac sagittis. Donec in bibendum leo. Nunc cursus leo ex, in commodo
massa laoreet vitae. Phasellus eu lorem eu felis facilisis faucibus. Suspendisse pretium a ex id sodales. Proin eu enim id nisl aliquam luctus nec non tellus. Nullam fermentum dolor ac semper aliquet. Fusce accumsan vestibulum lorem eget malesuada.
In eget molestie urna, eget viverra sapien. Nullam malesuada sapien at orci hendrerit, vitae dapibus lorem pulvinar. Duis ornare odio lectus, id hendrerit magna mattis id. Duis in est non nisi placerat gravida sed ut enim. Proin pellentesque mollis
eros, sit amet mattis lectus fringilla quis. Donec eu ligula eu ex mollis suscipit. Vestibulum blandit imperdiet sodales. Maecenas malesuada magna id sem fermentum, nec pulvinar dolor mollis. Nam tempus, velit ac dignissim interdum, augue est pulvinar
urna, id molestie lectus tellus in mi. Curabitur cursus purus eget hendrerit auctor. Maecenas vel orci et urna hendrerit varius. Suspendisse potenti.
</section>
</main>
Here is snippet for this case:
https://jsfiddle.net/Lgeayx4u/3/
Is it possible do what I want with pure CSS? I would like to avoid JS.

If you don't want the outer container to scroll and also keep a fixed height to it, then definitely you will not be able to reach the complete content for the aside and section portions. The better option is to let them inherit the container's height and set overflow-y: hidden on the container:
main {
display: grid;
grid-template-columns: 336px 2fr;
overflow-y: hidden;
/*hidden cuts my content */
height: 300px;
}
section, aside{ height: 100%; }
section {
max-height: 100vh;
border: 1px solid black;
overflow-y: scroll;
--webkit-overscroll-behavior-y: none;
}
aside {
border: 1px solid blue;
display: flex;
flex-direction: column;
justify-content: flex-start;
overflow-y: scroll;
max-height: 100vh;
--webkit-overscroll-behavior-y: none;
}
div {
display: flex;
max-width: 304px;
border: 1px solid red;
background-color: lightgreen;
margin-bottom: 12px;
padding: 15px;
}
<main>
<aside>
<div>
Text 1
</div>
<div>
Text 2
</div>
<div>
Text 3
</div>
<div>
Text 4
</div>
<div>
Text 5
</div>
<div>
Text 6
</div>
<div>
Text 7
</div>
<div>
Text 8
</div>
<div>
Text 9
</div>
</aside>
<section>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla at lacus nisl. Aliquam sed elit vel nisi egestas fringilla non eget metus. Nam tempus vehicula massa, et pharetra orci pulvinar eu. Etiam tincidunt arcu nisl, ac porttitor felis ornare eget.
Suspendisse feugiat posuere dui, id imperdiet nisl tincidunt vel. Duis ut tempus purus. Nulla facilisis lobortis sagittis. Fusce risus augue, hendrerit id nisi sed, luctus imperdiet sem. Phasellus vestibulum scelerisque massa, tincidunt porta lectus
gravida non. Integer egestas ipsum eros. Duis a ultrices odio. Curabitur justo lectus, ultricies quis urna eget, interdum scelerisque felis. Nullam eleifend est in efficitur vulputate. Praesent sit amet vulputate nibh, at vulputate dui. Nulla facilisi.
Praesent sollicitudin mi nec sem sollicitudin, et aliquam diam rutrum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent finibus justo sem, vitae tincidunt mi consequat in. Aliquam ullamcorper ultrices
nulla, at dapibus nulla hendrerit eget. Nullam sit amet libero a magna dictum mattis. Suspendisse hendrerit suscipit augue, vel congue sapien tincidunt nec. Donec volutpat tempor felis ac sagittis. Donec in bibendum leo. Nunc cursus leo ex, in commodo
massa laoreet vitae. Phasellus eu lorem eu felis facilisis faucibus. Suspendisse pretium a ex id sodales. Proin eu enim id nisl aliquam luctus nec non tellus. Nullam fermentum dolor ac semper aliquet. Fusce accumsan vestibulum lorem eget malesuada.
In eget molestie urna, eget viverra sapien. Nullam malesuada sapien at orci hendrerit, vitae dapibus lorem pulvinar. Duis ornare odio lectus, id hendrerit magna mattis id. Duis in est non nisi placerat gravida sed ut enim. Proin pellentesque mollis
eros, sit amet mattis lectus fringilla quis. Donec eu ligula eu ex mollis suscipit. Vestibulum blandit imperdiet sodales. Maecenas malesuada magna id sem fermentum, nec pulvinar dolor mollis. Nam tempus, velit ac dignissim interdum, augue est pulvinar
urna, id molestie lectus tellus in mi. Curabitur cursus purus eget hendrerit auctor. Maecenas vel orci et urna hendrerit varius. Suspendisse potenti.
</section>
</main>

Related

How to position header in certain position?

Currently still doing my project and I'm trying to find out how to position headings in certain places. Figure 1 is my final goal for my headings to look like.
[Figure 1][1]
Currently this is what mine looks like (Figure 2), I am struggling to position the heading to a similar spot, every time I do, the paragraphs and the navbar move further down leaving a big white gap between the headings & paragraphs.
Also was wondering how would I level out the image with the text & navbar?
Thanks in advance, much appreciated.
[Figure 2][2]
I believe this is what you wanted:
preview
Basically, you could wrap the header (image + text) into a CSS flexbox, and the rest of the stuff into another flexbox. I edited the CSS file to reflect these changes. Hope this helps! Let me know if you have any other questions.
Here's a link to the jsfillde: https://jsfiddle.net/rzLbkw9m/
Here's the html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="holiday.css" rel="stylesheet" type="text/CSS">
<title>Task 4</title>
</head>
<body>
<div class="header-container">
<div class="header-image">
<img src="https://st.depositphotos.com/1115174/1875/v/450/depositphotos_18752455-stock-illustration-summer-beach-vacation-background.jpg" alt="Holiday" width="400" height="200" align="left">
</div>
<div class="header-text">
<h1>Holiday Time</h1>
<h3>Get away from it all</h3>
</div>
</div>
<div class="row">
<div class="list-column">
<ul class="list">
<li>Destinations</li>
<li>Deals</li>
<li>Flights</li>
<li>Cruise</li>
<li>Extras</li>
<li>Money</li>
</ul>
</div>
<div class="main-column">
<div class="paragraph">
<p>
<img src="https://images.pexels.com/photos/88212/pexels-photo-88212.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="Holiday" width="220" height="150" align="right" class="intext-img">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec ultrices libero eu eros viverra, eget tristique ipsum commodo. Phasellus tempus a erat quis hendrerit. Quisque ipsum felis, vestibulum sed finibus vel, molestie id ante. Morbi metus leo, dictum nec pellentesque nec, condimentum quis magna. Praesent est turpis, pharetra non fermentum sed, elementum ac ante. Integer sodales metus id rutrum hendrerit. Phasellus vel dapibus massa, ut aliquet arcu. Ut consectetur feugiat neque, sed sagittis dui rutrum eget. Maecenas commodo mattis enim quis lacinia. Duis in ipsum vitae mi laoreet dignissim. Nullam consequat velit at magna commodo, in fringilla enim rutrum. Cras at augue sed nisl ultricies lobortis. Praesent rhoncus lectus facilisis, rhoncus purus et, luctus eros. Nunc eros nisi, finibus sit amet urna quis, posuere ultrices mauris.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc quis lorem vel neque bibendum iaculis vel id tellus. Nulla auctor elit vitae sollicitudin ultrices. Fusce molestie dictum neque, et dictum magna iaculis eget. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed volutpat, augue eget tincidunt feugiat, felis mi vulputate sem, eu mattis nisi quam sit amet est. Cras eu sem nec metus iaculis tempus sit amet non sapien. Aenean id odio semper purus dignissim elementum. Vestibulum faucibus mi ac odio hendrerit venenatis. Cras rhoncus diam magna, at placerat quam rutrum ut.
</p>
</div>
<div class="paragraph">
<p>
<img src="https://i.pinimg.com/474x/c6/60/24/c66024ea79527d9bbafe79ed171558b9--luxury-travel-luxury-hotels.jpg" alt="Holiday" width="220" height="150" align="right" class="intext-img">
Quisque fringilla sodales lorem eget rhoncus. Curabitur pulvinar blandit justo nec volutpat. Mauris bibendum lobortis quam et aliquam. Nulla dictum varius est, sed fringilla ante volutpat ac. Sed tempus dolor diam, ac porta ligula sagittis ac. Morbi vitae nisi porttitor, sollicitudin urna non, tempus justo. Donec vel vulputate est. Donec aliquet vitae velit eu interdum. Quisque et facilisis diam. Duis rutrum faucibus purus at tempus. Mauris auctor tincidunt mauris, quis porttitor magna aliquam molestie. Aliquam efficitur, ex sed finibus porta, tellus diam dictum arcu, ac egestas quam enim tristique velit. Integer volutpat tortor et tortor consequat tincidunt. Donec imperdiet libero vitae sapien commodo, eget pretium libero eleifend. Sed mi felis, porttitor vel blandit laoreet, pretium a felis. Duis in erat interdum, rutrum lectus viverra, pellentesque elit. Sed imperdiet massa ullamcorper mauris tempus, at euismod nibh convallis. In sapien lorem, lacinia eget viverra sit amet, suscipit in diam. Phasellus at sapien eu orci pellentesque eleifend suscipit eu diam. Vivamus quis nibh id sem placerat rutrum. Nunc pellentesque aliquet congue.
Nam at eros elementum, venenatis nibh vel, volutpat mi. Donec varius sapien ipsum, sed sagittis ligula iaculis hendrerit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent pharetra ante eget purus rhoncus, ac pharetra eros fermentum. Etiam porta nec leo pretium gravida. Integer a nulla quam. In ullamcorper, nibh id efficitur porttitor, lacus mi semper nisi, id pulvinar ex leo at mi. Vestibulum placerat lacus vitae velit laoreet, in efficitur risus convallis. Nunc at sagittis dolor, eu gravida nunc. In hac habitasse platea dictumst. Mauris vitae lobortis ipsum, quis rhoncus mauris. Ut eget nibh sed dolor sollicitudin dictum efficitur ac ligula. Nullam ut nulla sit amet leo varius tincidunt.
</p>
</div>
</div>
</div>
<div class="footer"> Contact: 0191 227 1111</div>
</body>
</html>
Here's the css file:
/* header */
.header-container {
display: flex;
align-items: center;
border: 1px solid lightblue;
}
.header-text {
margin-left: 25px;
}
.header-text h1 {
color: purple;
font-size: 48px;
}
.header-text h3 {
margin-left: 20px;
}
/* navbar */
.list-column {
flex: 30%;
align-self: flex-start;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}
li a:first-of-type {
padding-top: 2px;
}
/* main content */
.row {
margin-top: 10px;
display: flex;
align-items: flex-start;
}
.paragraph {
margin-bottom: 25px;
}
.intext-img {
margin-top: 5px;
margin-left: 10px;
margin-bottom: 10px;
}
p {
font-size: 18px;
margin: 0px;
}
/* footer */
.footer {
position: absolute;
right: 0;
bottom: 0;
left: 0;
padding: 0.8rem;
text-align: left;
background-color: #64A3D6;
}
create a div around h1 and h3
.header{
position: relative;
top: 50%;
transform: translateY(-50%);
}
this will put the header in the middle of the area vertically. make sure the padding or margin is minimal

How to force CSS grid to be specific height

I have found this question: How to set max height to a CSS grid, which talks about setting a specific height to the elements of a grid. I want to set a height to the grid itself, though, and have any elements overflowing to have a scroll bar (refer to the figure below).
Even though I set a max-height to the container element, the large text (.top) still overflows and makes the container element's height larger than its max-height. And since I don't know the size of the .bottom element (its height is auto), I can't set a max-height to the .top element.
.container {
padding: 5px;
width: 200px;
max-height: 200px;
grid-template: 1fr auto / 1fr;
grid-template-areas: "top" "bottom";
background: red;
}
.top {
background: blue;
grid-area: top;
}
.bottom {
background: green;
grid-area: bottom;
}
<div class="container">
<div class="top">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin scelerisque blandit ipsum vitae vehicula. Vestibulum id urna ac odio scelerisque venenatis. Mauris blandit vitae tortor ac auctor. Donec pharetra accumsan eleifend. Fusce porta ante at turpis venenatis, sed luctus mi efficitur. Nunc eget metus pellentesque ante lacinia facilisis. Aenean magna nisi, feugiat at ullamcorper a, tincidunt id augue. Curabitur ut nisl eu risus convallis luctus et vitae enim. Ut vitae purus sed enim tempus convallis. Vestibulum consequat scelerisque ornare.</p>
<p>Sed at urna turpis. Aenean vehicula, nunc elementum vehicula rutrum, sem orci ornare mauris, auctor ultricies quam enim quis sem. Praesent accumsan volutpat mollis. Proin tempus rhoncus lacus. Cras gravida, mauris sed suscipit vulputate, odio elit sagittis urna, non suscipit odio sapien eget ex. Ut vulputate ante sit amet diam tempus, eget tempus dolor sodales. Etiam quis orci posuere, interdum diam quis, tincidunt urna. Vivamus lectus lectus, hendrerit in sapien quis, tempor sollicitudin sem. Proin quis sem lectus. Fusce quis molestie enim, quis dapibus lacus. Nulla fringilla metus a odio lacinia feugiat. Vivamus rutrum diam placerat tristique scelerisque. Integer a iaculis justo, a tempus lorem.</p>
</div>
<div class="bottom">
<p>Little Text</p>
</div>
</div>
So how can a specific-height grid still be achieved and have any elements that are too large have a scrollbar?
You forgot to set display: grid on the container, and overflow: auto on the top:
.container {
padding: 5px;
width: 200px;
max-height: 200px;
grid-template: 1fr auto / 1fr;
grid-template-areas: "top" "bottom";
background: red;
display: grid; /* added */
}
.top {
background: blue;
grid-area: top;
overflow: auto; /* added */
}
.bottom {
background: green;
grid-area: bottom;
}
<div class="container">
<div class="top">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin scelerisque blandit ipsum vitae vehicula. Vestibulum id urna ac odio scelerisque venenatis. Mauris blandit vitae tortor ac auctor. Donec pharetra accumsan eleifend. Fusce porta ante at turpis venenatis, sed luctus mi efficitur. Nunc eget metus pellentesque ante lacinia facilisis. Aenean magna nisi, feugiat at ullamcorper a, tincidunt id augue. Curabitur ut nisl eu risus convallis luctus et vitae enim. Ut vitae purus sed enim tempus convallis. Vestibulum consequat scelerisque ornare.</p>
<p>Sed at urna turpis. Aenean vehicula, nunc elementum vehicula rutrum, sem orci ornare mauris, auctor ultricies quam enim quis sem. Praesent accumsan volutpat mollis. Proin tempus rhoncus lacus. Cras gravida, mauris sed suscipit vulputate, odio elit sagittis urna, non suscipit odio sapien eget ex. Ut vulputate ante sit amet diam tempus, eget tempus dolor sodales. Etiam quis orci posuere, interdum diam quis, tincidunt urna. Vivamus lectus lectus, hendrerit in sapien quis, tempor sollicitudin sem. Proin quis sem lectus. Fusce quis molestie enim, quis dapibus lacus. Nulla fringilla metus a odio lacinia feugiat. Vivamus rutrum diam placerat tristique scelerisque. Integer a iaculis justo, a tempus lorem.</p>
</div>
<div class="bottom">
<p>Little Text</p>
</div>
</div>

How do you get a div to hide/scroll overflow and scale to the viewport with consistent margins?

(EDIT: my current code added to bottom of post)
I need to set a value for the height of the div in order for it to hide/scroll overflow properly, but I don't want a div at a specific pixel height. I can solve that by using % or vh units, but I don't actually want to use those units. By that, I mean I don't want my div to always be, for example, 2/3 of the page, because that means the bottom of the div will be a different distance from the bottom of the browser window, like this-
* {
padding: 0;
margin: 0;
}
html, body {
width: 100%;
height: 100%;
}
body > div {
width: 90%;
height: 90%;
background: yellow;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style2.css">
</head>
<body>
<div>
</div>
</body>
</html>
-I want it to be a consistent distance from the bottom of the browser window,
like this-
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
div {
background-color: yellow;
width: 350px;
position: fixed;
left: 10px;
top: 10px;
right: 10px;
bottom: 10px;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style2.css">
</head>
<body>
<div>
</div>
</body>
</html>
(for visual representation primarily, I am not really using the code itself as an example)
Basically, I want my div to be a variable height and hide/scroll overflow, but always 10px from the bottom.
I think these describe the same problem I'm having:
Setting a length (height or width) for one element minus the variable length of another, i.e. calc(x - y), where y is unknown
Getting a scrollable child div to Vertically fill the remainder of its parent dynamically
The answers there are to use tables or flexbox - are these the only options (without using javascript)?
My code:
* {
margin: 0;
padding: 0;
}
body {
font-family: Helvetica, Arial, sans-serif;
overflow-x: hidden;
overflow-y: hidden;
width: 100%;
height: 100%;
}
p {
font-size: 9pt;
}
a {
text-decoration: none;
color: black;
}
.container { /*this contains all the divs!!*/
padding: 10px;
}
.header {
}
.name {
float: left;
width: 25vw;
padding-right: 5vw;
}
.about {
width: 65vw;
}
.main { /*this contains divs 'left' and 'right'*/
/*background-color: #CCCCCC;*/
clear: left;
padding-top: 10px;
width: 95vw;
}
.left {
/*background-color: #E6E6E6;*/
float: left;
min-height: 10px;
width: 25vw;
padding-right: 5vw;
}
.hold { /*this is how i tried your solution*/
position: relative;
height: calc(95vh - 10px);
}
.right { /*this is my problem div*/
background-color: #FFFF00;
width: 65vw;
height: 100%;
overflow-y: hidden;
overflow-x: hidden;
}
.lorem {
margin-right: 20vw;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> Name </title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="header">
<div class="name">
<p> Name </p>
</div> <!-- end div name -->
<div class="about">
<p> about </p>
</div> <!-- end div name -->
</div> <!-- end div header -->
<div class="main">
<div class="left">
</div> <!-- end div left -->
<div class="hold">
<div class="right">
<div class="lorem">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam feugiat facilisis purus at fermentum. Etiam ultricies iaculis nulla maximus cursus. Maecenas justo nulla, suscipit a dapibus at, lobortis nec mauris. Mauris egestas mi sit amet risus convallis, in hendrerit lorem maximus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse sollicitudin tempor libero, nec molestie dui tempor sit amet. Aenean molestie ex id nisl venenatis, quis tincidunt lectus porta. Vivamus aliquam lobortis nulla, id porta leo consequat sollicitudin. Ut iaculis neque placerat ipsum placerat tincidunt.
Quisque libero sem, hendrerit quis urna sit amet, mollis venenatis nisl. Morbi vel neque rhoncus, congue purus ac, condimentum nunc. Morbi vestibulum metus nec velit eleifend, ac sodales nulla posuere. Praesent id fermentum massa. Morbi vestibulum lorem nulla, ac vestibulum nunc auctor non. Donec ultricies placerat mauris, at pretium nibh finibus eu. Suspendisse gravida neque nisl, sit amet bibendum ante placerat eget. Sed laoreet suscipit turpis vitae ullamcorper. Mauris quis pharetra eros. Curabitur quis diam non dui elementum facilisis vel ac sem. Duis vitae augue vitae mi pulvinar placerat ut quis purus. Donec sagittis maximus aliquam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Phasellus pharetra nisi arcu, in laoreet lacus convallis sed. Nam euismod ligula felis, ut laoreet nisl sodales eget. Maecenas cursus, augue vitae suscipit laoreet, purus magna bibendum tellus, sed maximus ex dui ac velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nulla eget aliquet tellus, in viverra sapien. Sed eget urna mauris. Morbi dapibus dolor et felis viverra condimentum sed a nisl. Integer congue cursus ultrices. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse nulla risus, pulvinar eget odio vitae, scelerisque cursus magna. Nam maximus eros vitae massa euismod, vel tempus felis vulputate.
Nunc blandit massa a nisl viverra, vitae molestie ex rhoncus. Pellentesque finibus luctus nisi. Sed quis luctus metus. Nullam sed augue ultrices, lacinia dolor ac, egestas ante. In non nisi nibh. Sed vitae dui libero. Duis ut ullamcorper urna. Phasellus quis fringilla leo.
Nulla porta tellus ut nibh pharetra dapibus. Mauris ullamcorper egestas aliquam. Cras posuere scelerisque imperdiet. In ultrices, leo eu molestie bibendum, augue dui semper ante, vel faucibus nibh enim sed eros. Mauris ipsum dui, placerat et tincidunt vitae, laoreet vel enim. Praesent at ligula et neque placerat blandit sed vulputate ipsum. Phasellus sodales, odio nec aliquam pretium, augue lacus mattis quam, nec vulputate purus lorem vitae nisi.
Suspendisse nisl ipsum, volutpat ac dapibus at, tincidunt eget nulla. Mauris ornare a nisi ac fringilla. Maecenas leo sapien, vulputate in dictum a, feugiat in eros. Aliquam sit amet sagittis leo. Mauris metus nisl, convallis eget mollis ut, ullamcorper eu tellus. Pellentesque eu dolor tempor, bibendum leo vitae, maximus velit. Aenean volutpat neque sit amet tellus mattis euismod.
Quisque nec vehicula orci. Curabitur varius fringilla risus, convallis tincidunt velit porttitor vitae. Aenean in lacus nec nunc tempor dignissim nec pretium sem. Nullam finibus odio quis metus ornare, in fermentum elit rutrum. Proin vitae dui in metus vehicula sodales. Donec massa neque, suscipit ac est quis, ultrices auctor risus. Cras eu auctor lectus. Nam sagittis vulputate hendrerit. Maecenas consequat odio justo, at malesuada nulla ullamcorper a. Donec arcu tellus, dignissim ut velit vel, consequat scelerisque dolor. Curabitur dictum vel risus quis consequat.
Pellentesque fringilla eu nisi sed tincidunt. Nulla feugiat sit amet purus sit amet cursus. Suspendisse nibh purus, tincidunt eu congue ut, ultricies id lectus. Phasellus convallis in nibh vel molestie. Nunc condimentum congue justo. In congue, turpis at vulputate imperdiet, dolor erat ultricies turpis, vitae egestas est augue in nisl. Ut ut leo diam. Duis vulputate ligula velit, vitae volutpat felis viverra a. Maecenas justo quam, lobortis a placerat ut, ullamcorper ac lorem. Sed eu vehicula odio.
Fusce id mauris ornare, mollis mi at, vulputate turpis. Praesent a risus feugiat, rutrum lacus nec, sodales nisi. Nulla ullamcorper libero pretium lacus accumsan, eu tempor mi porta. In tincidunt porta feugiat. Cras lectus arcu, convallis nec neque ac, vestibulum pretium ex. Curabitur mi ipsum, commodo ut eros eget, fringilla fringilla tortor. Curabitur maximus tellus ut turpis malesuada, auctor semper lectus porta. Suspendisse non sapien sagittis, dapibus tellus et, egestas quam. Aliquam vitae massa sit amet urna rhoncus rutrum sit amet et lorem. Phasellus gravida justo ut vulputate vestibulum.
Nunc sed tempus metus, sit amet volutpat mi. Quisque sed metus rutrum, iaculis enim sed, sodales lacus. Quisque quis mi ac sapien scelerisque efficitur lacinia et nunc. Proin tincidunt scelerisque turpis, non euismod ante interdum at. Sed vitae velit scelerisque, placerat nulla in, egestas justo. Mauris urna orci, pulvinar a nibh a, luctus pellentesque mauris. Nulla faucibus hendrerit urna non venenatis. Quisque nulla mi, suscipit sit amet nunc eu, dictum ullamcorper tellus. Donec lacus libero, commodo quis mauris pellentesque, feugiat iaculis nisl. Nulla facilisi. Suspendisse sed risus quis risus fringilla condimentum. Aenean aliquet in eros vel volutpat. Vivamus malesuada ultrices lorem sit amet feugiat. In interdum leo ac orci sollicitudin, maximus vestibulum nisl gravida. Sed venenatis pharetra fringilla. Etiam mauris risus, cursus et est tristique, mattis venenatis nisi.
</p>
</div> <!-- end div LOREM -->
</div> <!-- end div main -->
</div> <!-- end div hold -->
</div> <!-- end div container -->
</body>
</html>
You're on the right track! You can combine vh with calc to get the desired effect.
height: calc(100vh - 10px) - assuming the element is positioned at the top of the screen, that'll achieve the effect you're describing.
To handle scroll/overflow, you'll need an inner container - a div inside the one you set the height property on. Give that inner div { height: 100%; overflow: auto; } and you should be all set.
Here's a demo - to see it working, use the full screen view and shrink your browser's height.
/* These styles are just to make this easier to see,
and to normalize the display a little. */
* { box-sizing: border-box; margin: 0; padding: 0; }
.page { width: 100px; border: 2px solid; }
/* Here's the box that locks to some distance from the bottom, in this case 30px */
.outer {
height: calc(100vh - 30px);
position: relative;
border: 1px solid blue;
}
/* And here's the scrollable container inside it */
.inner {
height: 100%;
overflow: auto;
}
<div class="page">
<div class="outer">
<div class="inner">
content content content content
content content content content
content content content content
</div>
</div>
</div>

absolute parent - display overflow on child content

http://codepen.io/Kalesh/pen/xbBmdj?editors=110
Absolute parent containing a header and content divs. Both are dynamic. I want to display scroll-bar on the content only.
I don't want to give any height to header or make the content absolute with top X.
Is there any way to accomplish this?
#parent {
position:absolute;
top: 10px; bottom: 225px; right: 340px; width: 320px;
border: 1px solid black;
}
#header {
border-bottom: 2px solid #426da9; padding: 4px 10px 0; font-size: 32px;
}
#content {
padding: 10px;
font-size: 20px;
}
<div id="parent">
<div id="header">
HEADER
Duis risus eros, bibendum nec pretium at, eleifend non nisi.
</div>
<div id="content">
CONTENT
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut sollicitudin arcu, sit amet varius purus. Proin eget magna nec sapien vehicula tincidunt. Vestibulum commodo magna sit amet tempor posuere. Ut ac consequat ipsum. Phasellus nulla est, elementum in dictum pulvinar, lacinia sit amet turpis. Nulla auctor placerat dapibus. Nulla vestibulum non nunc sed venenatis. In ac enim scelerisque, ornare leo at, posuere diam. Sed molestie metus semper fermentum maximus. Aliquam in accumsan risus, id maximus mauris.
Duis risus eros, bibendum nec pretium at, eleifend non nisi. Curabitur auctor, odio eu congue aliquet, sapien sapien rutrum orci, sit amet hendrerit sem sem et lectus. Nulla facilisi. Praesent fermentum id nunc et volutpat. Vivamus ac sodales nisi. Duis nec libero eu quam faucibus iaculis et vel magna. Cras erat mauris, imperdiet a porta eu, pharetra eu augue.
Duis risus eros, bibendum nec pretium at, eleifend non nisi. Curabitur auctor, odio eu congue aliquet, sapien sapien rutrum orci, sit amet hendrerit sem sem et lectus. Nulla facilisi. Praesent fermentum id nunc et volutpat. Vivamus ac sodales nisi. Duis nec libero eu quam faucibus iaculis et vel magna. Cras erat mauris, imperdiet a porta eu, pharetra eu augue.
</div>
</div>
Since the header must have a flexible height, it will be difficult to achieve this in old CSS. However, new browsers support flexible boxes, which are perfect for this:
#parent {
display: flex; /* Magic begins */
flex-direction: column; /* Column layout */
}
#content {
flex: 1; /* Starting at 0, grow to fill the remaining space */
overflow: auto; /* Add scrollbars if necessary */
}
#parent {
position:absolute;
top: 10px; bottom: 225px; right: 340px; width: 320px;
border: 1px solid black;
display: flex;
flex-direction: column;
}
#header {
border-bottom: 2px solid #426da9; padding: 4px 10px 0; font-size: 32px;
}
#content {
padding: 10px;
font-size: 20px;
flex: 1;
overflow: auto;
}
<div id="parent">
<div id="header">
HEADER
Duis risus eros, bibendum nec pretium at, eleifend non nisi.
</div>
<div id="content">
CONTENT
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut sollicitudin arcu, sit amet varius purus. Proin eget magna nec sapien vehicula tincidunt. Vestibulum commodo magna sit amet tempor posuere. Ut ac consequat ipsum. Phasellus nulla est, elementum in dictum pulvinar, lacinia sit amet turpis. Nulla auctor placerat dapibus. Nulla vestibulum non nunc sed venenatis. In ac enim scelerisque, ornare leo at, posuere diam. Sed molestie metus semper fermentum maximus. Aliquam in accumsan risus, id maximus mauris.
Duis risus eros, bibendum nec pretium at, eleifend non nisi. Curabitur auctor, odio eu congue aliquet, sapien sapien rutrum orci, sit amet hendrerit sem sem et lectus. Nulla facilisi. Praesent fermentum id nunc et volutpat. Vivamus ac sodales nisi. Duis nec libero eu quam faucibus iaculis et vel magna. Cras erat mauris, imperdiet a porta eu, pharetra eu augue.
Duis risus eros, bibendum nec pretium at, eleifend non nisi. Curabitur auctor, odio eu congue aliquet, sapien sapien rutrum orci, sit amet hendrerit sem sem et lectus. Nulla facilisi. Praesent fermentum id nunc et volutpat. Vivamus ac sodales nisi. Duis nec libero eu quam faucibus iaculis et vel magna. Cras erat mauris, imperdiet a porta eu, pharetra eu augue.
</div>
</div>

HTML <div> and CSS Style

I am trying to get a picture to be on the left side of the page with the text floating to right. I am using:
<div class="body">
<div style="float: left;">
<img src="me.png" height="310" width="350">
</div>
<p id="text"> BAJFS:LKJFKLJ##LKJLK#FJ##:LFKJ##:LFKJ##:LK#FJ:L#KFJ#:#LFKJ#:LFKJ##F:L#K#JF:#LFK J </p>
</div>
which I thought would make my image be on the left, with text floating to the right. The CSS I am using is:
.body
{
width: 880px;
margin: 20px auto;
background-color: #CFECEC;
padding: 10px 16px;
-moz-border-radius: 2px;
-webkit-border-radius: 10px;
-khtml-border-radius: 10px;
border-radius: 5px;
-webkit-box-shadow: 3px 5px 4px #000;
-moz-box-shadow: 3px 5px 4px #000;
box-shadow: 3px 5px 4px #000;
}
Can anyone help me have a picture on the left of this frame with text to the right?
I think the only reason that your text didn't float to the right cause it has no space inside. The paragraph's width is totally a difference cause they're all consecutive letters.
Your CSS works just fine. The problem lies in the text youre trying to wrap. You've got a single line with no spaces, therefore it simply doesnt fit next to the image, so it drops down below it.
Try the same code with different dummy text, and youll see that it works:
<div class="body">
<div style="float: left;">
<img src="me.png" height="310" width="350">
</div>
<p id="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc mi mi, porttitor et rhoncus ac, aliquet vitae nunc. Phasellus nec eros vel lectus tempus placerat. Aenean lacinia euismod ultricies. In non ullamcorper urna. Donec nisi dolor, dictum eu facilisis sed, semper a lacus. Nulla dictum molestie tellus vitae ultricies. Etiam urna est, sodales et ultricies quis, vestibulum et lectus. Fusce iaculis cursus eleifend. Fusce venenatis est non nulla adipiscing condimentum. Aenean volutpat lectus est, at dictum nibh. Quisque facilisis purus et arcu dapibus at fringilla metus elementum. Integer consequat pellentesque auctor. Duis hendrerit feugiat diam vel lobortis. Nunc mauris leo, lacinia sit amet laoreet ut, auctor a arcu.
Aliquam dignissim rhoncus turpis, eget facilisis est blandit sed. Nunc quis nulla diam. Ut et quam nisl, a tristique mauris. Etiam ut quam in sem luctus pellentesque. Morbi viverra, odio ut tincidunt posuere, odio mauris egestas mi, non ornare arcu justo gravida risus. Sed odio leo, viverra ut tristique ac, imperdiet eu tortor. Nulla nunc nisl, pharetra eu ornare sed, aliquam quis lorem. Nunc pellentesque, libero eu venenatis laoreet, sapien augue ultricies sem, in facilisis nisi erat in odio. Suspendisse ullamcorper, risus at aliquam gravida, mi dolor adipiscing erat, ut tincidunt lacus urna sed leo. Cras posuere imperdiet velit, eu convallis velit ornare et. Praesent semper varius tortor, et malesuada sem malesuada quis. Mauris elementum sem ac ante aliquet faucibus et et nisi. Quisque id quam in dui varius egestas et eu diam. Fusce ultrices feugiat sapien.
In aliquam congue urna in scelerisque. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin tortor eros, pellentesque id pharetra nec, interdum et tellus. In dapibus condimentum iaculis. Vivamus nec risus et ante blandit pretium non at tortor. Vivamus non sapien lorem. Phasellus ac nisi eget quam varius accumsan vel a ipsum. Phasellus mattis pellentesque auctor. Aenean risus mi, iaculis ut feugiat vel, pretium sit amet eros. Curabitur varius faucibus tempor.</p>
</div>
You can set width to your #text and float it right. Also you need set width to your images parent div. Add overflow: hidden; to .body to contain floated elements.
#text {
float: left;
width: 550px;
}
.figure { /* add this to your images parent */
float: left;
width: 350px;
}
.body {
...
overflow: hidden;
}

Resources