Overflow: Hidden causing content layout issues - html

I am attempting to create a nice looking text-fade in effect for my website. The issue I am running into is caused by the user of overflow: hidden.
Here is my codepen demonstrating the problem:
https://codepen.io/camerongray6692/pen/zWBqZP
And to satisfy the 'codepen link must be accompanied by code...' rule:
HTML:
<div class="container">
<div class="row">
<h1>Test Heading</h1>
<img src="https://i.imgur.com/5HEZhk0.png" class="imageReplacement"/>
<div class="sectionSubheadings">
<h3 class="test-subheading">This is test text. This is test text. </h3>
<h3 class="test-subheading">This is test text. This is test text. This is test text.</h3>
<h3 class="test-subheading">This is test text.</h3>
</div>
<div class="special-text">
<p>
Suspendisse vel vehicula metus, et tincidunt ex. Nulla egestas cursus accumsan. In vitae egestas felis, id dignissim dui. Etiam scelerisque luctus imperdiet. Duis at mattis tortor. Nam at vulputate lorem. Donec hendrerit tempor pharetra. Nulla efficitur ipsum a lorem faucibus pharetra quis id ante. Sed magna turpis, efficitur vitae fringilla dictum, sollicitudin eget erat. Etiam bibendum sed nunc nec gravida.
</p>
<p>
Quisque pretium lorem molestie lectus mattis ullamcorper. Donec lacinia consequat est nec tempus. Praesent et vehicula lacus. Vivamus arcu ex, vehicula ac diam sit amet, ullamcorper imperdiet leo. Donec pellentesque augue eget molestie pulvinar. Fusce et auctor urna. Vestibulum a fringilla orci.
</p>
<p>
In congue, lacus eget fermentum congue, erat augue accumsan magna, quis euismod nunc enim a odio. Sed sagittis enim pharetra lectus fringilla accumsan. Proin consectetur tellus egestas suscipit posuere. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean porttitor pharetra aliquam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus sollicitudin sapien felis, quis lobortis neque molestie eget. Praesent ut felis sit amet velit ultrices venenatis. Vivamus nunc dolor, malesuada eu erat at, malesuada varius diam. Nam ac mi risus.
</p>
<p>
Sed et lorem lobortis, varius est eu, molestie dui. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nunc consequat ut dolor sit amet vestibulum. Integer commodo laoreet turpis eu suscipit. Etiam vehicula ex id nibh vulputate vulputate. Suspendisse potenti. Ut ac nisl sed purus hendrerit condimentum.
</p>
<p>
In congue, lacus eget fermentum congue, erat augue accumsan magna, quis euismod nunc enim a odio. Sed sagittis enim pharetra lectus fringilla accumsan. Proin consectetur tellus egestas suscipit posuere. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean porttitor pharetra aliquam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus sollicitudin sapien felis, quis lobortis neque molestie eget. Praesent ut felis sit amet velit ultrices venenatis. Vivamus nunc dolor, malesuada eu erat at, malesuada varius diam. Nam ac mi risus.
</p>
</div>
<button class="expand-button">
Continue Reading
</button>
CSS:
.imageReplacement {
background-color: red;
width:225px;
height:225px;
float: right;
margin-left: 25px;
}
.test-subheading {
margin: 0;
padding: 2px 0;
}
.container {
width: 1000px;
}
.special-text {
position: relative;
max-height: 75px;
overflow: hidden;
transition: max-height .5s ease;
}
.special-text.-expanded {
max-height: 1500px;
}
.special-text:not(.-expanded)::after {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
}
.special-text > p {
font-size: 16px;
margin-top: 15px;
}
jQuery:
$(".expand-button").on("click", function() {
$(".special-text").toggleClass("-expanded");
if ($(".special-text").hasClass("-expanded")) {
$(".expand-button").html("Collapse Content");
} else {
$(".expand-button").html("Continue Reading");
}
});
This is so close to the desired effect I am looking for, but I cannot figure out a way to get the text that appears after the image to wrap and use the space underneath the image.
If I set overflow:hidden to visible, the text wraps as expected. However, then the text does not disappear when clicking 'Collapse Content'. I have tried creating a wrapper around the special-text div and setting overflow-x to visible and setting overflow-y to hidden on the special-text div, but it acts exactly as if overflow was set to hidden.
Trying to change the overflow after the -expanded class has been added to the special-text results in the content moving around in a very jarring way during the animation.
If anyone could provide some guidance on how to accomplish this, that would be awesome.

Ok After tons of trail and error, this is the only way I found to do exactly what you want
pen here https://codepen.io/anon/pen/BrzpgY
This is not that flexible because you have to define a max-height on the container which need to be high enough to show the image but not too high that it shows too much text.
The main issue here is you are trying to show this in an unnatural as far as how the content works. You want the image to show which means it needs to be outside of the content and if it is outside then your floated image won't let your text wrap because the text is in a block element. The element must remain block because you need to give it a max height for animation.
We can't set overflow visible on expand because what it does is it just shows the content right away which is why you see that button in front of text because the text will just show, the animation is useless at this point.
While the below code works but it is not dynamic. I strongly suggest you make a compromise somewhere, either put the image with the text and have the fade hide part of the image or show the text on the left side like you had. The only other option is maybe use js to calculate height on click then set a bunch of things but I really think that is over complication for this
$(".expand-button").on("click", function() {
$(".row").toggleClass("-expanded");
if ($(".row").hasClass("-expanded")) {
$(".expand-button").html("Collapse Content");
} else {
$(".expand-button").html("Continue Reading");
}
});
.imageReplacement {
background-color: red;
width:225px;
height:225px;
float: right;
margin-left: 25px;
position: relative;
z-index: 1;
}
.test-subheading {
margin: 0;
padding: 2px 0;
}
.container {
width: 1000px;
}
.row {
position: relative;
max-height: 320px;
overflow: hidden;
transition: max-height .5s ease;
}
.row.-expanded {
max-height: 1500px;
}
.row:not(.-expanded) .row-content::after {
content: '';
position: absolute;
top: 200px;
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
}
.special-text > p {
font-size: 16px;
margin-top: 15px;
}
button {
position: absolute;
bottom: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<div class="row-content">
<h1>Test Heading</h1>
<img src="https://i.imgur.com/5HEZhk0.png" class="imageReplacement"/>
<div class="sectionSubheadings">
<h3 class="test-subheading">This is test text. This is test text. </h3>
<h3 class="test-subheading">This is test text. This is test text. This is test text.</h3>
<h3 class="test-subheading">This is test text.</h3>
</div>
<p>
Suspendisse vel vehicula metus, et tincidunt ex. Nulla egestas cursus accumsan. In vitae egestas felis, id dignissim dui. Etiam scelerisque luctus imperdiet. Duis at mattis tortor. Nam at vulputate lorem. Donec hendrerit tempor pharetra. Nulla efficitur ipsum a lorem faucibus pharetra quis id ante. Sed magna turpis, efficitur vitae fringilla dictum, sollicitudin eget erat. Etiam bibendum sed nunc nec gravida.
</p>
<p>
Quisque pretium lorem molestie lectus mattis ullamcorper. Donec lacinia consequat est nec tempus. Praesent et vehicula lacus. Vivamus arcu ex, vehicula ac diam sit amet, ullamcorper imperdiet leo. Donec pellentesque augue eget molestie pulvinar. Fusce et auctor urna. Vestibulum a fringilla orci.
</p>
<p>
In congue, lacus eget fermentum congue, erat augue accumsan magna, quis euismod nunc enim a odio. Sed sagittis enim pharetra lectus fringilla accumsan. Proin consectetur tellus egestas suscipit posuere. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean porttitor pharetra aliquam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus sollicitudin sapien felis, quis lobortis neque molestie eget. Praesent ut felis sit amet velit ultrices venenatis. Vivamus nunc dolor, malesuada eu erat at, malesuada varius diam. Nam ac mi risus.
</p>
<p>
Sed et lorem lobortis, varius est eu, molestie dui. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nunc consequat ut dolor sit amet vestibulum. Integer commodo laoreet turpis eu suscipit. Etiam vehicula ex id nibh vulputate vulputate. Suspendisse potenti. Ut ac nisl sed purus hendrerit condimentum.
</p>
<p>
In congue, lacus eget fermentum congue, erat augue accumsan magna, quis euismod nunc enim a odio. Sed sagittis enim pharetra lectus fringilla accumsan. Proin consectetur tellus egestas suscipit posuere. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean porttitor pharetra aliquam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus sollicitudin sapien felis, quis lobortis neque molestie eget. Praesent ut felis sit amet velit ultrices venenatis. Vivamus nunc dolor, malesuada eu erat at, malesuada varius diam. Nam ac mi risus.
</p>
</div>
<button class="expand-button">
Continue Reading
</button>
</div>
</div>

Related

Problem with the sticky element of locmotive scroll

I'm coming to you for help because I have a problem with locomotive scroll and its sticky element.
Context: I have created a container with two elements in it
A parent containing three images, each image is in absolute position so that it can be overlaid.
A parent containing three texts
I want the element containing the three images to be sticky to its parent.
Problem: I have the desired result, only my sticky element sticks out of its parent. When I remove the absolute position of the images all work correctly.
Question: How do I keep my absolute position for the overlay of the images and make the sticky element not stick out of its parent?
HTML
<section id="secteur">
<div class="container" id="fixed">
<div class="assets col-6#sm">
<div data-scroll data-scroll-sticky data-scroll-target="#fixed">
<div class="imgone">
<img src="
https://cdn.sanity.io/images/s02i1y2u/staging/ec87773a743f14c42fafb5ed1a6afedf4026eec1-1920x1466.png" />
</div>
<div class="imgtwo">
<img class="imgtwo" src=" https://cdn.sanity.io/images/s02i1y2u/staging/d3d9331a320133031754f779ff68a429f71084db-1920x1466.png" />
</div>
<div class="imgthree">
<img class="imgthree" src="https://cdn.sanity.io/images/s02i1y2u/staging/f77e88e29ab27c21a7edee537d2a67ac592bc268-1920x1466.png" />
</div>
</div>
</div>
<div class="metiers col-6#sm">
<div class="metier one">
<h3>Metallerie</h3>
<p>Donec at lorem leo. Praesent suscipit nunc vel sapien gravida tincidunt. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Maecenas massa lorem, convallis sed nulla fermentum, condimentum molestie sapien. Ut vitae vestibulum sapien. Donec congue nibh eu nisl imperdiet, sit amet mattis lectus malesuada. Curabitur non porta ligula. Sed consequat sagittis lobortis. Cras id ligula ut turpis luctus iaculis. Etiam rhoncus, ex a imperdiet finibus, nisi ipsum eleifend ex, at convallis est mauris non orci. Phasellus aliquet orci sapien, eu condimentum quam blandit ut. Sed suscipit sit amet diam eu sodales. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Aenean ultricies diam sem, ac gravida ex aliquet ac. Suspendisse ornare blandit enim in tempus. Phasellus orci risus, lacinia eget ultrices at, molestie eu turpis.</p>
</div>
<div class="metier two">
<h3>Chaudronnerie</h3>
<p>Donec at lorem leo. Praesent suscipit nunc vel sapien gravida tincidunt. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Maecenas massa lorem, convallis sed nulla fermentum, condimentum molestie sapien. Ut vitae vestibulum sapien. Donec congue nibh eu nisl imperdiet, sit amet mattis lectus malesuada. Curabitur non porta ligula. Sed consequat sagittis lobortis. Cras id ligula ut turpis luctus iaculis. Etiam rhoncus, ex a imperdiet finibus, nisi ipsum eleifend ex, at convallis est mauris non orci. Phasellus aliquet orci sapien, eu condimentum quam blandit ut. Sed suscipit sit amet diam eu sodales. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Aenean ultricies diam sem, ac gravida ex aliquet ac. Suspendisse ornare blandit enim in tempus. Phasellus orci risus, lacinia eget ultrices at, molestie eu turpis.</p>
</div>
<div class="metier three">
<h3>Serrurerie</h3>
<p>Donec at lorem leo. Praesent suscipit nunc vel sapien gravida tincidunt. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Maecenas massa lorem, convallis sed nulla fermentum, condimentum molestie sapien. Ut vitae vestibulum sapien. Donec congue nibh eu nisl imperdiet, sit amet mattis lectus malesuada. Curabitur non porta ligula. Sed consequat sagittis lobortis. Cras id ligula ut turpis luctus iaculis. Etiam rhoncus, ex a imperdiet finibus, nisi ipsum eleifend ex, at convallis est mauris non orci. Phasellus aliquet orci sapien, eu condimentum quam blandit ut. Sed suscipit sit amet diam eu sodales. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Aenean ultricies diam sem, ac gravida ex aliquet ac. Suspendisse ornare blandit enim in tempus. Phasellus orci risus, lacinia eget ultrices at, molestie eu turpis.</p>
</div>
</div>
</div>
</section>
<section id="next">
<div class="container">
<p>Page suivante</p>
Realisations
</div>
</section>
SCSS
#secteur {
.container {
display: flex;
justify-content: space-between;
.assets {
width: 100%;
padding-top: calc(var(--space-xxxl) + 0.75em);
position: relative;
.imgone {
grid-column: 1;
grid-row: 1;
transition: opacity .5s ease;
}
.imgtwo,
.imgthree {
grid-column: 1;
grid-row: 1;
transition: opacity .5s ease;
opacity: 0;
&.visible {
opacity: 1;
}
}
img {
width: 90%;
position: absolute;
}
}
.metiers {
cursor: pointer;
display: flex;
align-items: flex-start;
padding-top: var(--space-xxxl);
flex-direction: column;
justify-content: flex-start;
h3 {
margin-bottom: 12px;
padding-bottom: 8px;
border-bottom: 1px solid black;
}
.metier {
margin-bottom: var(--space-xl);
}
}
}
.invisible {
opacity: 0;
}
.one,
.two,
.three {
transition: opacity .5s ease;
}
.opacity {
opacity: 0.3;
}
}
#vide {
height: 200vh;
}
I created a codepen to simulate the problem encountered
https://codepen.io/christophedelamare/pen/YzYBBdw

How can I reposition a nav bar from the side to the center with enlarged font with just CSS flexbox?

I'm supposed to only use flexbox to move things around when the page width changes to below certain threshold. The before and after page layouts are supposed to look like this below: I have no idea how this is done and this assignment is one that comes before learning grid and media-query so I think I'm really not supposed to use those.
My code is as follows (there are no lines that have anything to do with repositioning the nav bar because I don't know what properties are to be used for that purpose, so it's basically just a generic display of the title, the nav bar, the passages and the footer):
<html>
<head>
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap"
rel="stylesheet"
/>
<style>
.content {
margin: 0 auto;
min-width: 1000px;
}
.flex {
display: flex;
position: relative;
}
a {
color: red;
}
article {
margin-left: 200px;
}
body {
font-family: "Open Sans", sans-serif;
}
footer {
color: #888888;
font-size: 14px;
margin-left: 100px;
}
header {
font-size: 60px;
text-align: center;
}
nav {
display: flex;
flex-direction: column;
margin-left: 100px;
position: absolute;
}
</style>
<title>Responsive Layout</title>
</head>
<body>
<main>
<header>My Responsive Layout</header>
<div class="content">
<div class="flex">
<nav>
Home
About Us
Contact Us
</nav>
<article>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque
vel felis id quam sodales volutpat non vitae tellus. Integer eu
diam auctor, ultrices lorem id, volutpat nisi. Sed pretium, augue
nec elementum feugiat, neque magna ultrices nulla, at venenatis
augue magna at ligula. Nunc euismod, turpis sed eleifend commodo,
tellus elit lacinia ipsum, eu scelerisque tortor neque id mauris.
Interdum et malesuada fames ac ante ipsum primis in faucibus.
Morbi vitae elit id mi molestie laoreet. Vivamus tempor, magna vel
iaculis aliquet, dolor nulla rhoncus turpis, in consequat nisi
tortor at enim. Sed faucibus magna erat, efficitur facilisis
mauris ornare nec.
</p>
<p>
Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Morbi orci nunc, blandit et
velit non, luctus elementum sapien. Donec arcu purus, consequat
quis diam quis, pretium tempus urna. Morbi efficitur mollis
mattis. Duis eu sodales lorem. Etiam vel fermentum lacus. Nunc
fermentum erat et aliquet dapibus. Integer pharetra imperdiet
vestibulum. Pellentesque varius magna a lorem tristique efficitur.
Praesent facilisis congue nibh sed efficitur. Nullam arcu ligula,
eleifend ut lectus sit amet, sodales rutrum ex. Proin ultricies
vulputate velit vitae porttitor.
</p>
<p>
Ut ultrices sollicitudin arcu id viverra. In nec varius orci.
Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Nullam euismod urna non augue
tincidunt aliquet. Suspendisse pretium dui vitae libero euismod
porttitor. Sed tristique pulvinar interdum. Praesent vestibulum ac
orci a consequat. Etiam bibendum sagittis viverra. Vestibulum quis
mi tortor. Nulla bibendum nunc et metus faucibus aliquet.
</p>
</article>
</div>
<footer>© My Special Layout Crew</footer>
</div>
</main>
</body>
</html>
Please teach me how it's done with flexbox alone if possible. Thanks much!
There are a few issues with the current CSS:
nav doesn't need position: absolute;
Following (1) above, explicit margins for nav and article are not needed either
Not using justify-content and flex-wrap attributes makes your markup arrangement hacky
The following should give you an idea, adjust values per your need.
<html>
<head>
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap"
rel="stylesheet"
/>
<style>
.content {
margin: 0 auto;
min-width: 1000px;
}
.flex {
display: flex;
position: relative;
justify-content: center;
flex-wrap: wrap;
max-width: 800px;
margin: 0 auto;
}
a {
color: red;
}
article {
min-width: 800px;
}
body {
font-family: "Open Sans", sans-serif;
}
footer {
color: #888888;
font-size: 14px;
margin-left: 100px;
}
header {
font-size: 60px;
text-align: center;
}
nav {
display: flex;
flex-direction: column;
min-width: 100px;
}
</style>
<title>Responsive Layout</title>
</head>
<body>
<main>
<header>My Responsive Layout</header>
<div class="content">
<div class="flex">
<nav>
Home
About Us
Contact Us
</nav>
<article>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque
vel felis id quam sodales volutpat non vitae tellus. Integer eu
diam auctor, ultrices lorem id, volutpat nisi. Sed pretium, augue
nec elementum feugiat, neque magna ultrices nulla, at venenatis
augue magna at ligula. Nunc euismod, turpis sed eleifend commodo,
tellus elit lacinia ipsum, eu scelerisque tortor neque id mauris.
Interdum et malesuada fames ac ante ipsum primis in faucibus.
Morbi vitae elit id mi molestie laoreet. Vivamus tempor, magna vel
iaculis aliquet, dolor nulla rhoncus turpis, in consequat nisi
tortor at enim. Sed faucibus magna erat, efficitur facilisis
mauris ornare nec.
</p>
<p>
Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Morbi orci nunc, blandit et
velit non, luctus elementum sapien. Donec arcu purus, consequat
quis diam quis, pretium tempus urna. Morbi efficitur mollis
mattis. Duis eu sodales lorem. Etiam vel fermentum lacus. Nunc
fermentum erat et aliquet dapibus. Integer pharetra imperdiet
vestibulum. Pellentesque varius magna a lorem tristique efficitur.
Praesent facilisis congue nibh sed efficitur. Nullam arcu ligula,
eleifend ut lectus sit amet, sodales rutrum ex. Proin ultricies
vulputate velit vitae porttitor.
</p>
<p>
Ut ultrices sollicitudin arcu id viverra. In nec varius orci.
Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Nullam euismod urna non augue
tincidunt aliquet. Suspendisse pretium dui vitae libero euismod
porttitor. Sed tristique pulvinar interdum. Praesent vestibulum ac
orci a consequat. Etiam bibendum sagittis viverra. Vestibulum quis
mi tortor. Nulla bibendum nunc et metus faucibus aliquet.
</p>
</article>
</div>
<footer>© My Special Layout Crew</footer>
</div>
</main>
</body>
</html>

Div permanent positioning while resizing browser

So what my goal is, is to position this div background box "lightgrey", with the text which is in another div, but everytime i get the divs positioned the way I want, they seem to be offset, I was thinking of creating a #media_query but I felt like I would have to create way too many statements to have it adjust accordingly, if anyone has any suggestions that would be great.
<div style="width:200px; height:200px;right:0;margin-right:7%; border: 5px;
solid:grey; background-color:lightgrey;position:absolute;">
</div>
<div style="position:absolute;right:0;margin-right:10%;">
<h3>{{major_choice.0.Major}}</h3>
<h3>Overall Rating:</h3>
<h3>{{major_choice.0.ProfessorRating}}</h3>
</div>
The first image is of a map leaflet that does what I want to achieve and its essentially dynamically changing the size without losing its position, verses what I created which constantly moves out of position when i resize the screen.
Leaflet Map (my goal):
This first image is ideal with how I would want it positioned:
When I resize this happens:
I don't have a ton of experience with css, I'm in a web development class right now, but I wont be able to see my professor because of the holidays, if anyone could give me some suggestions I would really appreciate it!
Any suggestions?
html code: https://pastebin.com/iTmsyV5Z
I can't really get a full example working to test but something like:
<div style="width: 200px; height:200px; border: 5px;
solid:grey; background-color: lightgrey; float: left;">
</div>
<div style="margin-left:10%; float: left;">
<h3>{{major_choice.0.Major}}</h3>
<h3>Overall Rating:</h3>
<h3>{{major_choice.0.ProfessorRating}}</h3>
</div>
or
<div style="width: 200px; height:200px; border: 5px;
solid:grey; background-color: lightgrey; float: left;">
</div>
<div style="margin-right:10%; float: right;">
<h3>{{major_choice.0.Major}}</h3>
<h3>Overall Rating:</h3>
<h3>{{major_choice.0.ProfessorRating}}</h3>
</div>
Should work after some adjustments of the values. Not sure if you want the grey box all the way to the right or left.
I achieved this by using relative positioning. And floating both elements left so they stack horizontally. I believe this is what you wanted.
By adding the element within your main container, absolute positioning will work nicely. This will then scroll with the container. If you require it to stay where it is on the screen, you will need to use fixed positioning, it will then be relative to your viewport. So keep in mind when adjusting your top and right positioning to compensate.
.Menu,
.Content {
position: fixed;
background-color: #CCC;
left: 10%;
right: 10%;
}
.Menu {
top: 10px;
height: 50px;
}
.Content {
top: 70px;
bottom: 10px;
overflow: auto;
padding-right: 250px;
}
.Floating {
position: absolute;
background-color: #EDEDED;
right: 20px;
top: 20px;
width: 210px;
height: auto:
}
<div class="Menu">
This is the menu
</div>
<div class="Content">
<div class="Floating">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer euismod lectus eros, placerat euismod nisl pharetra eget. Fusce commodo ipsum non ipsum fringilla dignissim. Integer eu mi ligula. In hac habitasse platea dictumst. Cras aliquet luctus felis
nec rutrum. In in magna eros. Donec tellus ipsum, auctor et eleifend non, mollis quis mauris. Praesent cursus malesuada mattis.
</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer euismod lectus eros, placerat euismod nisl pharetra eget. Fusce commodo ipsum non ipsum fringilla dignissim. Integer eu mi ligula. In hac habitasse platea dictumst. Cras aliquet luctus
felis nec rutrum. In in magna eros. Donec tellus ipsum, auctor et eleifend non, mollis quis mauris. Praesent cursus malesuada mattis. Morbi id quam libero. Donec laoreet ullamcorper lobortis. Etiam quis est ac lacus varius malesuada. Nunc venenatis
rutrum dui, id euismod nunc porttitor id. Nulla id sapien imperdiet, ullamcorper felis et, rhoncus tortor. Quisque purus tellus, molestie a urna in, bibendum bibendum mauris. Nunc aliquet ornare tincidunt. Praesent leo diam, fermentum nec tempor in,
pellentesque eget velit. Aenean luctus mauris et turpis vehicula, at tristique ex gravida. Vivamus finibus, tellus vel volutpat facilisis, enim metus mattis mi, quis dictum tortor mi a mauris. Pellentesque malesuada tellus non consectetur feugiat.
Proin rutrum sem nec odio varius tincidunt. Quisque egestas enim et orci scelerisque, quis viverra lectus tristique. Donec consectetur, lacus sed vehicula lacinia, ipsum arcu consequat odio, sed porta erat neque eu lacus. Proin consequat quam vitae
nisl vulputate, ut imperdiet justo ultricies. Phasellus dictum vestibulum ullamcorper. Quisque lobortis eros sed ante porta ultricies. Suspendisse sit amet purus non enim fringilla pellentesque. Sed posuere, metus ut venenatis pretium, enim urna laoreet
sapien, accumsan condimentum mauris nisi sed elit. Nunc mollis sit amet enim ac placerat. Donec elementum consectetur ipsum in molestie. Fusce auctor sollicitudin lorem a pharetra. Vestibulum blandit consectetur sagittis. Nullam varius commodo dictum.
Sed tempus a nulla nec feugiat. Sed pharetra mattis velit sed sollicitudin. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean sit amet vehicula felis. Nullam faucibus interdum rhoncus. Proin eget velit non
nunc dignissim vestibulum sit amet id nulla. Nunc a lectus mauris. Sed sagittis orci ullamcorper nisi ullamcorper dictum. Etiam ut tellus tortor. In a molestie tortor. Quisque turpis tellus, fermentum euismod eros a, vulputate aliquam sapien. Integer
nunc dui, scelerisque nec interdum id, auctor ut ante. Curabitur pharetra dui vitae tellus tincidunt auctor. Etiam eget fringilla massa. Phasellus auctor lorem hendrerit massa porttitor, luctus consequat leo semper. Curabitur sollicitudin est sapien,
sed vulputate neque finibus ac. Aliquam pulvinar enim ac mi congue, eu dapibus velit imperdiet. Suspendisse pretium tellus eu urna auctor, quis sodales erat varius. Aenean eget felis mi. Suspendisse non tellus in mauris congue finibus et et risus.</div>
</div>

Position Sticky with overflow-x set for parent div

I am trying to do a sticky header with position: sticky style.
The problem with position sticky is it wont work, if the parent container has some overflow set. But, in my case, I have a horizontal scroll. Since, I am putting a scroll for parent container ( overflow-x), the sticky is not working.
JSBin Link
.sticky {
position: sticky;
top: 10px;
z-index: 1;
}
In the example given you can see that, first block sticky is not working (because I have set overflow-x). But, it is working for the second item.
So, my question is how to make position sticky work with overflow-x set for parent.
as you probably know, setting position:sticky;top:10px on an element means that at first it is considered with position:relative and then after 10px with position:fixed ;
you need to set a height for the scrollable content. at least this is the only solution i know when you want position:sticky to work with overflow
hope it helps
OBS : check it in Firefox because in Chrome it doesn't work ( position:sticky -> This is an experimental API that should not be used in production code. i suggest you find another solution. like position:fixed and use JQ to position the headers relative to their containers )
html, body {
overflow: initial;
background: none;
}
body {
box-sizing: border-box;
margin: 0 150px;
font-family: 'Source Sans Pro', sans-serif;
}
.sticky {
position:sticky;
top: 10px;
z-index: 1;
}
[data-lorem] {
margin-top: 2em;
line-height: 1.5;
text-align: justify;
background: #eee;
border-radius: 5px;
padding: 15px;
}
[data-lorem] .sticky {
background: #3A5E8C;
padding: 15px 10px;
color: white;
border-radius: 5px;
display: inline-block;
width: 100%;
box-sizing: border-box;
}
[data-lorem] h2 {
float: left;
margin: 0;
}
[data-lorem] img {
float: right;
margin-top: 5px;
}
.nosupport {
color: darkred;
font-weight: bold;
display: none;
text-align: center;
}
<div data-lorem="p" style="
overflow-x: scroll;height:80vh;
">
<div class="content_area" style="
width: 1000px;
">
<span class="sticky"><h2>No</h2><img src="http://www.html5rocks.com/static/images/share.png" title="Just an example"></span>
Donec et odio pellentesque diam. Interdum varius sit amet mattis. In fermentum posuere urna nec tincidunt praesent semper. Auctor augue mauris augue neque. Vitae congue eu consequat ac felis donec. Pellentesque diam volutpat commodo sed egestas egestas. Orci phasellus egestas tellus rutrum tellus pellentesque eu tincidunt tortor. Pellentesque nec nam aliquam sem. Enim lobortis scelerisque fermentum dui faucibus in. In nibh mauris cursus mattis molestie a iaculis at erat. At lectus urna duis convallis convallis tellus id interdum velit. Massa sapien faucibus et molestie.
Proin libero nunc consequat interdum varius sit. Risus at ultrices mi tempus imperdiet nulla malesuada pellentesque elit. Sem viverra aliquet eget sit amet tellus cras adipiscing. Tortor consequat id porta nibh. Diam maecenas sed enim ut. Cras ornare arcu dui vivamus arcu felis. Sagittis eu volutpat odio facilisis mauris sit amet massa vitae. Enim tortor at auctor urna nunc id. Eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Nisi scelerisque eu ultrices vitae auctor eu augue.
Vulputate dignissim suspendisse in est ante in nibh mauris. Netus et malesuada fames ac turpis egestas integer eget aliquet. Turpis egestas integer eget aliquet nibh praesent tristique magna. Ut placerat orci nulla pellentesque dignissim enim. Et egestas quis ipsum suspendisse ultrices gravida. Malesuada fames ac turpis egestas integer eget aliquet nibh praesent. Pretium vulputate sapien nec sagittis aliquam malesuada. Sit amet nulla facilisi morbi tempus. A erat nam at lectus urna duis convallis. Commodo quis imperdiet massa tincidunt nunc pulvinar. Justo eget magna fermentum iaculis. Ac ut consequat semper viverra nam libero justo laoreet. Neque volutpat ac tincidunt vitae semper. Lacus vel facilisis volutpat est velit. Nunc sed blandit libero volutpat sed cras. Et magnis dis parturient montes nascetur ridiculus. Vitae congue eu consequat ac. Accumsan in nisl nisi scelerisque eu ultrices vitae auctor eu.</div></div>
<div data-lorem="p">
<span class="sticky"><h2>JavaScript</h2></span>
Donec et odio pellentesque diam. Interdum varius sit amet mattis. In fermentum posuere urna nec tincidunt praesent semper. Auctor augue mauris augue neque. Vitae congue eu consequat ac felis donec. Pellentesque diam volutpat commodo sed egestas egestas. Orci phasellus egestas tellus rutrum tellus pellentesque eu tincidunt tortor. Pellentesque nec nam aliquam sem. Enim lobortis scelerisque fermentum dui faucibus in. In nibh mauris cursus mattis molestie a iaculis at erat. At lectus urna duis convallis convallis tellus id interdum velit. Massa sapien faucibus et molestie.
Proin libero nunc consequat interdum varius sit. Risus at ultrices mi tempus imperdiet nulla malesuada pellentesque elit. Sem viverra aliquet eget sit amet tellus cras adipiscing. Tortor consequat id porta nibh. Diam maecenas sed enim ut. Cras ornare arcu dui vivamus arcu felis. Sagittis eu volutpat odio facilisis mauris sit amet massa vitae. Enim tortor at auctor urna nunc id. Eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Nisi scelerisque eu ultrices vitae auctor eu augue.
Vulputate dignissim suspendisse in est ante in nibh mauris. Netus et malesuada fames ac turpis egestas integer eget aliquet. Turpis egestas integer eget aliquet nibh praesent tristique magna. Ut placerat orci nulla pellentesque dignissim enim. Et egestas quis ipsum suspendisse ultrices gravida. Malesuada fames ac turpis egestas integer eget aliquet nibh praesent. Pretium vulputate sapien nec sagittis aliquam malesuada. Sit amet nulla facilisi morbi tempus. A erat nam at lectus urna duis convallis. Commodo quis imperdiet massa tincidunt nunc pulvinar. Justo eget magna fermentum iaculis. Ac ut consequat semper viverra nam libero justo laoreet. Neque volutpat ac tincidunt vitae semper. Lacus vel facilisis volutpat est velit. Nunc sed blandit libero volutpat sed cras. Et magnis dis parturient montes nascetur ridiculus. Vitae congue eu consequat ac. Accumsan in nisl nisi scelerisque eu ultrices vitae auctor eu.</div>

Content wrapper to fill 100% height of page

I'm struggling to get my div (#content) to full 100% height of the page, if I resize my browser, my div (.divAboutRight) stretches accordingly to accommodate the content but my wrapper div (#content) does not? I have an image (#logo) which is centered to it's parent (#content) which it is not doing when the parent doesn't fill 100%.
I'm sure I'm missing something really basic.
Any assistance or guidance would be appreciated.
<style>
html{margin:0; padding:0; width:100%; height:100%;}
body{height:100%;min-height:100%; margin:0; padding:0; width:100%; background-color:#fb9f32; color:#FFF;}
.head{width:100%; height:60px; background-color:#FFFFFF;}
#content{width:100%;height:100%;min-height: 100%; position:relative; border:1px solid red;}
#Back
{
position:absolute;
left:0;
background:url(../images/Back.png) no-repeat;
background-size: 100% 100%;
float:left;
min-width:55%;
height:59%;
border:1px solid green;
}
#logo
{
display:block;
position: absolute;
top: 50%;
left: 50%;
max-height: 132px;
max-width: 133px;
margin: -66.5px 0 0 -66px;
z-index:9999999;
}
.divAboutRight{width:35%; margin-right:5%; margin-top:3%;float:right; border:1px solid yellow;}
</style>
<body>
<div class="head">
<!-- Header Content -->
</div>
<div id="content">
<div id="Back">
<!-- absolute positioned -->
</div>
<!-- Fixed logo to be center of content wrapper -->
<img id="logo" width="133" height="132" src="images/logo.png"/>
<div class="divAboutRight">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam id est leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In et volutpat metus. Cras et ante in enim sollicitudin facilisis quis eget lacus. Donec a justo in lacus ornare porttitor feugiat sit amet velit. Nunc iaculis, tellus quis sollicitudin placerat, leo nulla viverra lectus, id semper massa arcu in purus. Vivamus dictum venenatis metus quis viverra. Donec euismod, mauris vel aliquam convallis, lectus diam scelerisque lacus, id adipiscing orci augue nec arcu. Nulla molestie est lobortis tempor consectetur. Curabitur convallis malesuada velit et volutpat. Morbi a commodo velit. Integer malesuada nunc augue, ac convallis justo sollicitudin a. Nam nulla urna, facilisis quis ullamcorper dictum, venenatis eu ante. Ut consectetur sit amet lacus sed posuere. Nunc facilisis est eu ultrices scelerisque.
Cras feugiat tincidunt justo, et eleifend felis pretium ac. Nulla ornare, massa eu tincidunt tristique, sapien enim congue nisl, id pellentesque nisl lorem vel dolor. Mauris imperdiet, diam ac aliquam convallis, eros ante rhoncus justo, non malesuada mi nulla non sem. Interdum et malesuada fames ac ante ipsum primis in faucibus. Suspendisse potenti. Praesent sapien velit, sodales eget odio at, ullamcorper molestie nibh. Mauris iaculis posuere leo, non sollicitudin libero ullamcorper quis. Integer lobortis et eros vitae imperdiet. Ut ligula sem, tempor quis lobortis imperdiet, interdum ac nisl. Sed non lectus mauris.
Donec mattis lorem dolor, a feugiat neque dictum in. Nullam pharetra magna mi, quis hendrerit odio vestibulum id. Donec faucibus risus sed felis mattis pharetra vel a enim. Curabitur ultrices bibendum dapibus. Nulla sit amet metus mauris. Phasellus at tellus est. Mauris sagittis, eros quis laoreet sodales, tortor justo tempus dolor, et tincidunt dui tellus et erat. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque vitae pulvinar sapien. Praesent pellentesque metus sem, pellentesque ullamcorper augue pellentesque eu.
In neque lectus, ultricies ultrices nisi sed, commodo viverra justo. Cras quis neque vulputate, elementum ante non, pellentesque urna. Fusce id tempus magna. Fusce nec tortor id nulla pharetra sodales nec at tellus. Suspendisse gravida felis non turpis consequat, sit amet gravida risus ornare. Interdum et malesuada fames ac ante ipsum primis in faucibus. Duis elementum consequat mauris ut accumsan. Donec nec aliquet tortor. Donec turpis tellus, convallis at faucibus sed, volutpat ac turpis. Vestibulum consequat sapien mi, et ultricies libero convallis ultricies. Mauris placerat mollis elementum. Nulla molestie felis purus, sed hendrerit enim vehicula ac. Curabitur adipiscing fringilla ultricies. Nunc hendrerit libero non aliquet egestas. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam mattis dui a enim interdum aliquet.
Nulla sagittis ligula enim, in vulputate lectus tincidunt ac. Sed imperdiet gravida orci at semper. Proin mollis adipiscing neque, vitae convallis risus rutrum eget. Praesent augue neque, lacinia nec tincidunt sed, elementum non sem. Suspendisse a mi condimentum, pellentesque lorem id, tempor turpis. In tortor nibh, convallis egestas ornare scelerisque, semper non nisi. Pellentesque ullamcorper euismod malesuada. Curabitur condimentum arcu id lorem posuere tincidunt. Proin convallis, elit vel fringilla tincidunt, eros diam ullamcorper lacus, eget posuere tortor velit vestibulum lorem. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cras sit amet pellentesque lacus. Maecenas molestie augue id ipsum feugiat, non pulvinar mi eleifend. Aenean augue metus, tincidunt non pellentesque eu, tristique quis metus. In a neque viverra, commodo velit ut, pretium diam.
</div>
</div>
</body>
From what I can see, Your div #content does not cover the full height because you have a div .head with a height of 60px;
Yo can either float your .head div or make it's position:absolute;
You could also include the .head div iside the #content div like this:
<body>
<div id="content">
<div class="head">
<!-- Header Content -->
</div>
<div id="Back">
<!-- absolute positioned -->
</div>
<!-- Fixed logo to be center of content wrapper -->
<img id="logo" width="133" height="132" src="images/logo.png"/>
<div class="divAboutRight">
<!-- Dynamic Content -->
</div>
</div>
</body>
If you are OK supporting IE9+, here is the code:
<style>
#content{
.
.
height:calc(100% - 60px);
.
}
</style>
Calc is supported in all modern browsers now.
On the other hand, if you can't support calc, here is one more way:
<style>
.head {
... // rest of head's css
z-index: 2;
}
#content {
position: relative;
box-sizing('border-box');
height: 100%;
padding-top: 60px; // height equal to the header
margin-top: -60px; // this will offset your content up again
z-index: 1; // make the content go BEHIND the head
... // rest of the CSS
}
</style>
note: this will make the scrollbar start from behind the head, because the content will be under the head.