I'm trying to float:right; image next to paragraph <p>, which are nested together in <div> container. The problem is that the parent <div> resize its height with the size of the text in the paragraph, that's good, but floated right image overflows the div, and same <div> didn't resize itself according to the image height.
.container {
width: 70%;
background-color: #777;
margin: 0 auto;
padding: 25px;
}
.content {
width: 100%;
height: auto;
float: left;
}
.content .container {
width: 70%;
height: auto;
background-color: white;
/*
overflow: hidden; /* Try later without overflow. (autoportrait.jpg overflow .content .container
*/
}
.autoportrait {
width: 20%;
height: 20%;
/*
max-width:205px;
max-height:265px;
margin-bottom: 25px;
*/
padding: 10px 10px 10px 10px;
border: solid;
border-width: 2px;
float: right;
clear: both;
}
<div class="content">
<div class="container">
<!--
<main>
<section>
-->
<img class="autoportrait" src="autoportrait.jpg" alt="Autoportrait of me">
<h2>Post title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu purus et enim eleifend fringilla. Cras nec tortor elementum, vestibulum orci id, congue nisl. Fusce ornare ac turpis sit amet tincidunt. Phasellus vel magna ut massa tempus ultricies.
Etiam erat libero, molestie vitae scelerisque quis, consequat eget lorem. Nulla finibus felis non mi viverra efficitur. Proin eget lobortis libero. Fusce aliquam eros sed placerat viverra. Nulla venenatis, nulla sit amet suscipit vulputate, sem
mauris rutrum erat, id pharetra dui nunc at dui. Morbi dignissim luctus maximus. Cras vitae ornare risus. Sed accumsan vitae eros ac placerat. Proin commodo non orci nec consectetur. Nunc posuere, enim a lobortis ultrices, augue ex ultrices ante,
nec consectetur elit leo a ligula. Mauris pellentesque massa nisl, non pellentesque ex pulvinar eu.
</p>
<!--
</section>
</main>
-->
</div>
</div>
I tried to use overflow: hidden; , but that works only for a single "post". When I try to put a second one, the same problem appears and length of the images that flows out of the 'content container' doubles.
I'm newbie in HTML/CSS and the code I write it's for my own knowledge. So I'll be grateful if we figure out something.
Greetings from Varna, Bulgaria!
Make the div to clear it's children using :after pseudo class.
.container{
width: 70%;
background-color: #777;
margin: 0 auto;
padding: 25px;
border:1px solid red;
}
.content{
width: 100%;
height: auto;
float: left;
}
.content .container {
width: 70%;
height: auto;
background-color: white;
/*overflow: hidden; /* Try later without overflow. (autoportrait.jpg overflow .content .container) */
}
.autoportrait{
width: 20%;
height: 20%;
/*max-width:205px;
max-height:265px;
margin-bottom: 25px;*/
padding: 10px 10px 10px 10px;
border: solid;
border-width: 2px;
float: right;
clear:both;
}
.container:after {
visibility: hidden;
display:table;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
<div class="content">
<div class="container">
<!--<main>
<section>-->
<img class="autoportrait" src="http://images.financialexpress.com/2015/12/Lead-image.jpg" alt="Autoportrait of me">
<h2>Post title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu purus et enim eleifend fringilla.
</p>
<!--</section>
</main>-->
</div>
<div class="container">
<!--<main>
<section>-->
<img class="autoportrait" src="http://images.financialexpress.com/2015/12/Lead-image.jpg" alt="Autoportrait of me">
<h2>Post title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu purus et enim eleifend fringilla.
Cras nec tortor elementum, vestibulum orci id, congue nisl. Fusce ornare ac turpis sit amet tincidunt.
Phasellus vel magna ut massa tempus ultricies. Etiam erat libero, molestie vitae scelerisque quis, consequat eget lorem.
Nulla finibus felis non mi viverra efficitur. Proin eget lobortis libero. Fusce aliquam eros sed placerat viverra.
Nulla venenatis, nulla sit amet suscipit vulputate, sem mauris rutrum erat, id pharetra dui nunc at dui.
Morbi dignissim luctus maximus. Cras vitae ornare risus. Sed accumsan vitae eros ac placerat.
Proin commodo non orci nec consectetur. Nunc posuere, enim a lobortis ultrices, augue ex ultrices ante, nec consectetur elit leo a ligula.
Mauris pellentesque massa nisl, non pellentesque ex pulvinar eu.
</p>
<!--</section>
</main>-->
</div>
</div>
Simplest solution is to use overflow: hidden; on .content .container.
I know you said you attempted it previously and even had it commented out in .content .container but it's working for me. Perhaps the issue was where/how you placed the second article in your markup.
.container {
width: 70%;
background-color: #777;
margin: 0 auto;
padding: 25px;
}
.content {
width: 100%;
height: auto;
float: left;
}
.content .container {
width: 70%;
height: auto;
background-color: white;
overflow: hidden;
border: 1px solid #ccc;
}
.autoportrait {
width: 20%;
height: 20%;
/*
max-width:205px;
max-height:265px;
margin-bottom: 25px;
*/
padding: 10px 10px 10px 10px;
border: solid;
border-width: 2px;
float: right;
clear: both;
}
<div class="content">
<div class="container">
<img class="autoportrait" src="http://placehold.it/300x500/fc0/" alt="Autoportrait of me">
<h2>Post title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu purus et enim eleifend fringilla. Cras nec tortor elementum, vestibulum orci id, congue nisl. Fusce ornare ac turpis sit amet tincidunt. Phasellus vel magna ut massa tempus ultricies.
Etiam erat libero, molestie vitae scelerisque quis, consequat eget lorem. Nulla finibus felis non mi viverra efficitur. Proin eget lobortis libero. Fusce aliquam eros sed placerat viverra. Nulla venenatis, nulla sit amet suscipit vulputate, sem
mauris rutrum erat, id pharetra dui nunc at dui. Morbi dignissim luctus maximus. Cras vitae ornare risus. Sed accumsan vitae eros ac placerat. Proin commodo non orci nec consectetur. Nunc posuere, enim a lobortis ultrices, augue ex ultrices ante,
nec consectetur elit leo a ligula. Mauris pellentesque massa nisl, non pellentesque ex pulvinar eu.
</p>
</div>
<div class="container">
<img class="autoportrait" src="http://placehold.it/300x500/fc0/" alt="Autoportrait of me">
<h2>Post title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu purus et enim eleifend fringilla. Cras nec tortor elementum, vestibulum orci id, congue nisl. Fusce ornare ac turpis sit amet tincidunt. Phasellus vel magna ut massa tempus ultricies.
Etiam erat libero, molestie vitae scelerisque quis, consequat eget lorem. Nulla finibus felis non mi viverra efficitur. Proin eget lobortis libero. Fusce aliquam eros sed placerat viverra. Nulla venenatis, nulla sit amet suscipit vulputate, sem
mauris rutrum erat, id pharetra dui nunc at dui. Morbi dignissim luctus maximus. Cras vitae ornare risus. Sed accumsan vitae eros ac placerat. Proin commodo non orci nec consectetur. Nunc posuere, enim a lobortis ultrices, augue ex ultrices ante,
nec consectetur elit leo a ligula. Mauris pellentesque massa nisl, non pellentesque ex pulvinar eu.
</p>
<!--
</section>
</main>
-->
</div>
</div>
Related
When centering the #outer div, the scrollbar starts not on the top left of the element but on the center. It becomes impossible to read the beginning of the text, and a part of the border is cut off.
How could I center and be able to scoll and see all content, including the border, when the content #outer is larger than the parent #container, using css?
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
#container {
width: 100%;
height: 100%;
display: grid;
place-content: center;
}
#outer {
width: max-content;
border: 1rem solid black;
padding: 2rem;
}
#inner {
background-color: red;
}
<div id="container">
<div id="outer">
<div id="inner">The beginning of this text is missing. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pulvinar ex ut volutpat iaculis. Mauris a tellus vel mauris ullamcorper semper quis non quam. Nullam in scelerisque dolor, vel cursus odio. Nulla dignissim imperdiet mauris eleifend ultricies. Sed auctor tortor nec neque mollis feugiat. Aliquam tincidunt lacus at dictum elementum. Aliquam nunc lacus, lobortis vitae finibus et, vehicula eget nibh. Suspendisse eget tincidunt quam. In posuere quam ac neque sagittis, at finibus ante dignissim. Proin magna enim, bibendum quis pulvinar eget, porttitor non dui. Sed mollis placerat sem, id condimentum libero tempor quis. Maecenas ultrices tellus vel nisi mattis, sit amet scelerisque urna gravida. Nullam eu ipsum vitae eros pulvinar fringilla id ut massa. Fusce vitae rhoncus nulla.</div>
</div>
</div>
This may be because of display:grid;
, because when I removed that, the content is showing itself fully.
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
#container {
overflow-x:scroll;
width: 100%;
height: 100%;
place-content: center;
}
#outer {
width: max-content;
border: 1rem solid black;
padding: 2rem;
}
#inner {
background-color: red;
}
<div id="container">
<div id="outer">
<div id="inner">The beginning of this text is missing. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pulvinar ex ut volutpat iaculis. Mauris a tellus vel mauris ullamcorper semper quis non quam. Nullam in scelerisque dolor, vel cursus odio. Nulla dignissim imperdiet mauris eleifend ultricies. Sed auctor tortor nec neque mollis feugiat. Aliquam tincidunt lacus at dictum elementum. Aliquam nunc lacus, lobortis vitae finibus et, vehicula eget nibh. Suspendisse eget tincidunt quam. In posuere quam ac neque sagittis, at finibus ante dignissim. Proin magna enim, bibendum quis pulvinar eget, porttitor non dui. Sed mollis placerat sem, id condimentum libero tempor quis. Maecenas ultrices tellus vel nisi mattis, sit amet scelerisque urna gravida. Nullam eu ipsum vitae eros pulvinar fringilla id ut massa. Fusce vitae rhoncus nulla.</div>
</div>
</div>
I don't know much about grid, but I think another fix might be the width;
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
#container {
width:100%;
height: 100%;
display: grid;
place-content: center;
}
#outer {
width:100%;
border: 1rem solid black;
padding: 2rem;
}
#inner {
background-color: red;
}
<div id="container">
<div id="outer">
<div id="inner">The beginning of this text is missing. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pulvinar ex ut volutpat iaculis. Mauris a tellus vel mauris ullamcorper semper quis non quam. Nullam in scelerisque dolor, vel cursus odio. Nulla dignissim imperdiet mauris eleifend ultricies. Sed auctor tortor nec neque mollis feugiat. Aliquam tincidunt lacus at dictum elementum. Aliquam nunc lacus, lobortis vitae finibus et, vehicula eget nibh. Suspendisse eget tincidunt quam. In posuere quam ac neque sagittis, at finibus ante dignissim. Proin magna enim, bibendum quis pulvinar eget, porttitor non dui. Sed mollis placerat sem, id condimentum libero tempor quis. Maecenas ultrices tellus vel nisi mattis, sit amet scelerisque urna gravida. Nullam eu ipsum vitae eros pulvinar fringilla id ut massa. Fusce vitae rhoncus nulla.</div>
</div>
</div>
But I don't know if you want it on separate lines.
When I try to use overflow: hidden;, the result isn't that I expect.
The article has the good size on big screens, but on small screens, the text is too big so it's over the article..
.article {
padding: 35px;
width: 100%;
max-height: 200px;
border-radius: 10px;
box-shadow: 0 0 0.50rem black;
}
.article_img {
float: left;
height: 200px;
width: 200px;
padding-right: 25px;
object-fit: contain;
}
<section>
<article class="article">
<img class="article_img" src="https://cdn.easycash.fr/img/prod/0/0/3/9/4/1/9/8/1/src/6556940-sony-ps3-slim-noir-320-go-sans-manette.jpg">
<h1>Test</h1>
<p style="overflow: hidden;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacinia laoreet leo eget congue. Vestibulum vulputate sed risus vel accumsan. Vivamus sed rhoncus libero. Sed placerat dolor id velit pharetra, vitae vehicula augue convallis. In nec euismod
felis. Nunc eget ornare ligula. Praesent finibus ipsum at imperdiet imperdiet. Aenean at pulvinar ligula, nec rhoncus metus. Vivamus luctus lobortis enim, quis facilisis diam pulvinar ut. Integer ultricies pellentesque leo, sed bibendum justo sollicitudin
vitae. Sed dictum ipsum et bibendum porta. Nam vulputate tempus dui vel volutpat. Donec massa diam, fringilla eu neque sed, mattis tincidunt tortor. Nulla neque purus, dictum non porttitor vitae, fermentum rhoncus lorem. Donec eleifend ultricies
justo, pretium interdum magna tempus vel. Suspendisse ultrices, tortor at placerat commodo, ligula diam feugiat felis, eget consectetur nibh est et dolor.</p>
</article>
</section>
Result:
Expected (approx.):
As of now, you can use the proprietary -webkit-line-clamp and define the number of lines you want:
html { box-sizing: border-box; }
*, *::before, *::after, *::marker { box-sizing: inherit; }
.line-clamp-5 {
display: -webkit-box;
-webkit-line-clamp: 5;
-webkit-box-orient: vertical;
overflow: hidden;
}
.article {
padding: 35px;
width: 100%;
max-height: 200px;
border-radius: 10px;
box-shadow: 0 0 0.50rem black;
}
.article_img {
float: left;
height: 200px;
width: 200px;
padding-right: 25px;
object-fit: contain;
}
<section>
<article class="article">
<img class="article_img" src="https://cdn.easycash.fr/img/prod/0/0/3/9/4/1/9/8/1/src/6556940-sony-ps3-slim-noir-320-go-sans-manette.jpg">
<h1>Test</h1>
<p class="line-clamp-5">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacinia laoreet leo eget congue. Vestibulum vulputate sed risus vel accumsan. Vivamus sed rhoncus libero. Sed placerat dolor id velit pharetra, vitae vehicula augue convallis. In nec euismod
felis. Nunc eget ornare ligula. Praesent finibus ipsum at imperdiet imperdiet. Aenean at pulvinar ligula, nec rhoncus metus. Vivamus luctus lobortis enim, quis facilisis diam pulvinar ut. Integer ultricies pellentesque leo, sed bibendum justo sollicitudin
vitae. Sed dictum ipsum et bibendum porta. Nam vulputate tempus dui vel volutpat. Donec massa diam, fringilla eu neque sed, mattis tincidunt tortor. Nulla neque purus, dictum non porttitor vitae, fermentum rhoncus lorem. Donec eleifend ultricies
justo, pretium interdum magna tempus vel. Suspendisse ultrices, tortor at placerat commodo, ligula diam feugiat felis, eget consectetur nibh est et dolor.</p>
</article>
</section>
This property is in the process of being standardized as line-clamp, but not implemented yet.
Further information:
https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-line-clamp
https://caniuse.com/css-line-clamp
It is possible to use display: flex to make columns to be aligned like row. Then if you want to avoid overflow, we can delete max-height:
.article {
padding: 35px;
width: 100%;
border-radius: 10px;
box-shadow: 0 0 0.50rem black;
}
img {
height: 200px;
width: 200px;
padding-right: 25px;
object-fit: contain;
}
.container {
display: flex;
flex-direction: row;
}
.one {
flex-basis: 10%;
background-color: aqua;
}
.two {
flex: 1;
background-color: aquamarine;
}
<section>
<article class="article">
<div class="container">
<div class="one">
<img class="article_img"
src="https://cdn.easycash.fr/img/prod/0/0/3/9/4/1/9/8/1/src/6556940-sony-ps3-slim-noir-320-go-sans-manette.jpg">
</div>
<div class="two">
<h1>Test</h1>
<p style="overflow: hidden;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacinia laoreet
leo
eget congue. Vestibulum vulputate sed risus vel accumsan. Vivamus sed rhoncus libero. Sed placerat dolor id
velit pharetra, vitae vehicula augue convallis. In nec euismod felis. Nunc eget ornare ligula. Praesent
finibus
ipsum at imperdiet imperdiet. Aenean at pulvinar ligula, nec rhoncus metus. Vivamus luctus lobortis enim,
quis
facilisis diam pulvinar ut. Integer ultricies pellentesque leo, sed bibendum justo sollicitudin vitae. Sed
dictum ipsum et bibendum porta. Nam vulputate tempus dui vel volutpat. Donec massa diam, fringilla eu neque
sed,
mattis tincidunt tortor. Nulla neque purus, dictum non porttitor vitae, fermentum rhoncus lorem. Donec
eleifend
ultricies justo, pretium interdum magna tempus vel. Suspendisse ultrices, tortor at placerat commodo, ligula
diam feugiat felis, eget consectetur nibh est et dolor.</p>
</div>
</div>
</article>
</div>
</section>
UPDATE:
If you want to have a fixed height, then it is necessary to use overflow-y: scroll. Otherwise, the content of will overflow article element:
.article {
width: 100%;
padding: 35px;
max-height: 200px;
height: 200px;
border-radius: 10px;
box-shadow: 0 0 0.50rem black;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container {
display: flex;
height: 100%;
}
.one {
flex: 0 0 20%;
white-space: nowrap;
}
.two {
flex: 0 0 80%;
overflow-y: hidden;
white-space: normal;
height: 100%;
}
.article_img {
max-width: 100%;
max-height: 100%;
padding-right: 25px;
height: auto;
object-fit: contain;
}
.ellipsis {
display: -webkit-box;
overflow : hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
<section>
<article class="article">
<div class="container">
<div class="one">
<img class="article_img" src="https://cdn.easycash.fr/img/prod/0/0/3/9/4/1/9/8/1/src/6556940-sony-ps3-slim-noir-320-go-sans-manette.jpg">
</div>
<div class="two">
<h1>Test</h1>
<div class="ellipsis">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacinia laoreet
leo
eget congue. Vestibulum vulputate sed risus vel accumsan. Vivamus sed rhoncus libero. Sed placerat dolor id
velit pharetra, vitae vehicula augue convallis. In nec euismod felis. Nunc eget ornare ligula. Praesent
finibus
ipsum at imperdiet imperdiet. Aenean at pulvinar ligula, nec rhoncus metus. Vivamus luctus lobortis enim,
quis
facilisis diam pulvinar ut. Integer ultricies pellentesque leo, sed bibendum justo sollicitudin vitae. Sed
dictum ipsum et bibendum porta. Nam vulputate tempus dui vel volutpat. Donec massa diam, fringilla eu neque
sed,
mattis tincidunt tortor. Nulla neque purus, dictum non porttitor vitae, fermentum rhoncus lorem. Donec
eleifend
ultricies justo, pretium interdum magna tempus vel. Suspendisse ultrices, tortor at placerat commodo, ligula
diam feugiat felis, eget consectetur nibh est et dolor.
</div>
</div>
</div>
</article>
</section>
I have a div with a custom horizontal scroll. I would like to display a border bottom in the horizontal scroll but separated, because I get it without space between them. This is my current code:
div {
overflow-x: auto;
white-space: nowrap;
width: 200px;
}
div::-webkit-scrollbar-track {
border-radius: 10px;
}
div::-webkit-scrollbar {
height: 6px;
border-bottom: 1px solid #ccc;
}
div::-webkit-scrollbar-thumb {
border-radius: 10px;
background-color: #000;
}
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ac dictum ipsum. Vestibulum a ligula magna. Sed id justo eu nibh pharetra hendrerit vel nec ante. Proin ultrices ante quis erat pulvinar maximus. Quisque id arcu odio. Donec sit amet augue
urna. Proin lectus ligula, aliquam a velit eu, molestie tempor ipsum. Ut ac neque aliquet nulla aliquet facilisis. Donec ac ultrices augue. In nec augue ullamcorper, tristique enim a, mollis lectus. Curabitur in sodales erat. Suspendisse at egestas
urna, et elementum arcu. Aliquam dapibus ut neque quis consectetur. Etiam at lectus id odio finibus maximus et a nisi.
</div>
Are you able to edit the HTML?
Can't you just add a wrapper div?
#Wrap{
width:200px;
padding-bottom:6px;
border-bottom: 1px solid #ccc;
}
#Inner {
position:relative;
overflow-x: auto;
white-space: nowrap;
width: 100%;
}
/*Custom Scrollbar*/
#Inner::-webkit-scrollbar-track {
border-radius: 10px;
}
#Inner::-webkit-scrollbar {
height: 6px;
}
#Inner::-webkit-scrollbar-thumb {
border-radius: 10px;
background-color: #000;
}
<div id="Wrap">
<div id="Inner">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ac dictum ipsum. Vestibulum a ligula magna. Sed id justo eu nibh pharetra hendrerit vel nec ante. Proin ultrices ante quis erat pulvinar maximus. Quisque id arcu odio. Donec sit amet augue
urna. Proin lectus ligula, aliquam a velit eu, molestie tempor ipsum. Ut ac neque aliquet nulla aliquet facilisis. Donec ac ultrices augue. In nec augue ullamcorper, tristique enim a, mollis lectus. Curabitur in sodales erat. Suspendisse at egestas
urna, et elementum arcu. Aliquam dapibus ut neque quis consectetur. Etiam at lectus id odio finibus maximus et a nisi.
</div>
</div>
One simple solution: add padding and then the border-bottom
div {
overflow-x: auto;
white-space: nowrap;
width: 200px;
padding: 16px 0px;
border-bottom: 1px solid #000;
}
Another solution consists on adding a wrapper and creating a new div that will be used to have the separated border bottom, something like this:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
div {
overflow-x: auto;
white-space: nowrap;
width: 200px;
}
div::-webkit-scrollbar-track {
border-radius: 10px;
}
div::-webkit-scrollbar {
height: 6px;
border-bottom: 1px solid #ccc;
}
div::-webkit-scrollbar-thumb {
border-radius: 10px;
background-color: #000;
}
.border-bottom{
margin-top: 8px;
border-bottom: 1px solid #000;
}
</style>
</head>
<body>
<div id="content-wrapper">
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ac dictum ipsum. Vestibulum a ligula magna. Sed id justo
eu nibh pharetra hendrerit vel nec ante. Proin ultrices ante quis erat pulvinar maximus. Quisque id arcu odio. Donec
sit amet augue urna. Proin lectus ligula, aliquam a velit eu, molestie tempor ipsum. Ut ac neque aliquet nulla aliquet
facilisis. Donec ac ultrices augue. In nec augue ullamcorper, tristique enim a, mollis lectus. Curabitur in sodales
erat. Suspendisse at egestas urna, et elementum arcu. Aliquam dapibus ut neque quis consectetur. Etiam at lectus
id odio finibus maximus et a nisi.
</div>
<div class="border-bottom"></div>
</div>
</body>
</html>
I have an interesting problem. The CSS property position, value fixed, is supposedly relative to the browser window. Yet, somehow, in this code it sticks to the parent which is absolute, when scrolled. How and why?
HTML:
<section>
<div class="container">
<div class="wrapper">
<div class="content">
<div class="bar">
</div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a quam ultrices libero convallis consequat eget non eros. Proin in velit ullamcorper, tristique leo id, tempus ipsum. Mauris in nisl at tortor vulputate dictum. Morbi at leo non ante euismod gravida ut sit amet massa. Suspendisse potenti. Fusce nec ultricies arcu. Sed at nunc turpis. Vivamus suscipit eu mi mollis tempor. Nullam ut urna libero. Duis finibus egestas erat, non faucibus sem placerat a. Curabitur sollicitudin porttitor urna, a eleifend diam ultrices non. Praesent lacus lectus, volutpat scelerisque lacus quis, vehicula eleifend dui. Praesent eget est magna. Sed faucibus tellus diam, commodo ultricies ipsum pulvinar et. Phasellus nec blandit tortor, eget facilisis tellus. Nulla vitae ornare neque.
</div>
</div>
</div>
</section>
<section>
<div class="container">
<div class="wrapper">
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a quam ultrices libero convallis consequat eget non eros. Proin in velit ullamcorper, tristique leo id, tempus ipsum. Mauris in nisl at tortor vulputate dictum. Morbi at leo non ante euismod gravida ut sit amet massa. Suspendisse potenti. Fusce nec ultricies arcu. Sed at nunc turpis. Vivamus suscipit eu mi mollis tempor. Nullam ut urna libero. Duis finibus egestas erat, non faucibus sem placerat a. Curabitur sollicitudin porttitor urna, a eleifend diam ultrices non. Praesent lacus lectus, volutpat scelerisque lacus quis, vehicula eleifend dui. Praesent eget est magna. Sed faucibus tellus diam, commodo ultricies ipsum pulvinar et. Phasellus nec blandit tortor, eget facilisis tellus. Nulla vitae ornare neque.
</div>
</div>
</div>
</section>
CSS:
section {
width: 100%;
display: block;
max-width: none;
height: 100vh !important;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
position: relative;
}
section .content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
}
section .wrapper {
max-width: 770px;
margin: 0 auto 50px;
text-align: center;
padding: 0 25px 50px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.bar {
display: block;
width: 100%;
height: 30px;
background: #00aeef;
margin-bottom: 40px;
}
.bar.fixed {
position: fixed;
top: 0;
}
jQuery:
$(window).scroll(function() {
var scrollPos = $(document).scrollTop();
if(scrollPos > $('.bar').offset().top) {
$('.bar').addClass('fixed');
} else {
$('.bar').removeClass('fixed');
}
}).scroll();
https://jsfiddle.net/bg6cqcfp/1/
Well, it appears the transform property is at fault here.
transform: translate();
I managed to find a similar issue after using Google with different keywords. After removing those from the parent absolute element, the issue disappears. Weird.
I need to fix the following code so that child elements were 100% height of its parent. Chromium and Firefox debugging tools show that parent element (footer) has non-zero height. So children should have the same height.
HTML
<div class="footer">
<footer class="clearfix">
<section class="path">
<img height="474px" src="../../src/images/api-maps.yandex.ru.png">
</section>
<section class="info">
<p>bla</p>
</section>
<section class="links">
<p>bla</p>
</section>
<footer class="clearfix"></footer>
</footer>
</div>
CSS
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
.clearfix {
margin: 0;
padding: 0;
}
.clearfix:before, .clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
div.footer {
width: 100%;
}
div.footer footer {
background-color: black;
width: 100%;
overflow: hidden;
}
footer.clearfix {
border-top: 6px solid grey;
}
footer section {
float: left;
width: 33.333%;
height: 100%;
}
section.path {
background-color: red;
}
section.path img {
width: 100%;
display: block;
}
section.info {
background-color: blue;
}
section.links {
background-color: yellow;
}
I can't figure out why it doesn't work.
The footer has no height of its own, just what is implied by the image in the content so height:100% won't work.
As mentioned in the comments by raplh.m
the height on the container would have to be explicit. A better approach is to use flexbox, or display: table, which is better supported. That is, display: table on the container and display: table-cell on the sections within.
In fact you can use both and if the browser supports flexbox it will use that in preference to display:table.
As a bonus...you don't need to clear any floats because there aren't any.
footer {
display: table;
table-layout: fixed;
width: 100%;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
section {
display: table-cell;
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
text-align: center;
}
img {
display: block;
margin: auto;
}
.path {
background: red;
}
.info {
background: yellow;
}
.links {
background: blue;
}
<footer>
<section class="path">
<img height="474px" src="http://lorempixel.com/output/city-h-c-200-474-10.jpg">
</section>
<section class="info">
<p>bla</p>
</section>
<section class="links">
<p>bla</p>
</section>
</footer>
Codepen Demo
Since you are using percentage heights, you need to specify the height of parent elements.
Try this:
html, body { height: 100%; }
.footer { height: 100%; }
footer { height: 100%; }
DEMO: http://jsfiddle.net/1krrxb87/
For a clear understanding of how the height property works with percentage values, see my answers here:
Why is the 'height' property with percentage value not working on my div?
Percentage height not working in nested flexbox layout in Chrome
This is also possible without use off flexbox or display:table
When you need footer to be atleast have an cross browser height off 100% off the parent you need these CSS rules
footer {
min-height: 100%;
height: auto !important;
height: 100%;
}
To have three floated sections that will have 100% height and appear equal height you can use this HTML and CSS code.
HTML
<footer>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sit amet nunc eget massa congue scelerisque ac at ex. Ut odio nibh, interdum ac tempus vel, tempus vitae elit. Phasellus vel massa luctus, condimentum leo id, malesuada lectus. Aenean elit risus, consequat et dolor porta, mattis porta sem. Donec id commodo magna, sit amet mollis augue. Vestibulum id imperdiet massa. Maecenas accumsan pharetra est, quis imperdiet diam molestie eu. Aenean lobortis condimentum pharetra. Integer eget sem dictum, tempor arcu non, tincidunt purus. Sed nisi arcu, eleifend non maximus quis, porttitor id sem. Aliquam erat volutpat. Vivamus maximus tempus velit sit amet blandit. Quisque eleifend arcu at nisi elementum efficitur. Praesent consectetur nibh eget accumsan convallis. In pharetra nibh lorem, ac venenatis ipsum tincidunt venenatis. Donec eros justo, ultrices sit amet quam condimentum, placerat sollicitudin justo.
</p>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sit amet nunc eget massa congue scelerisque ac at ex. Ut odio nibh, interdum ac tempus vel, tempus vitae elit. Phasellus vel massa luctus, condimentum leo id, malesuada lectus. Aenean elit risus, consequat et dolor porta, mattis porta sem. Donec id commodo magna, sit amet mollis augue. Vestibulum id imperdiet massa. Maecenas accumsan pharetra est, quis imperdiet diam molestie eu. Aenean lobortis condimentum pharetra. Integer eget sem dictum, tempor arcu non, tincidunt purus. Sed nisi arcu, eleifend non maximus quis, porttitor id sem. Aliquam erat volutpat. Vivamus maximus tempus velit sit amet blandit. Quisque eleifend arcu at nisi elementum efficitur. Praesent consectetur nibh eget accumsan convallis. In pharetra nibh lorem, ac venenatis ipsum tincidunt venenatis. Donec eros justo, ultrices sit amet quam condimentum, placerat sollicitudin justo.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sit amet nunc eget massa congue scelerisque ac at ex. Ut odio nibh, interdum ac tempus vel, tempus vitae elit. Phasellus vel massa luctus, condimentum leo id, malesuada lectus. Aenean elit risus, consequat et dolor porta, mattis porta sem. Donec id commodo magna, sit amet mollis augue. Vestibulum id imperdiet massa. Maecenas accumsan pharetra est, quis imperdiet diam molestie eu. Aenean lobortis condimentum pharetra. Integer eget sem dictum, tempor arcu non, tincidunt purus. Sed nisi arcu, eleifend non maximus quis, porttitor id sem. Aliquam erat volutpat. Vivamus maximus tempus velit sit amet blandit. Quisque eleifend arcu at nisi elementum efficitur. Praesent consectetur nibh eget accumsan convallis. In pharetra nibh lorem, ac venenatis ipsum tincidunt venenatis. Donec eros justo, ultrices sit amet quam condimentum, placerat sollicitudin justo.
</p>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sit amet nunc eget massa congue scelerisque ac at ex. Ut odio nibh, interdum ac tempus vel, tempus vitae elit. Phasellus vel massa luctus, condimentum leo id, malesuada lectus. Aenean elit risus, consequat et dolor porta, mattis porta sem. Donec id commodo magna, sit amet mollis augue. Vestibulum id imperdiet massa. Maecenas accumsan pharetra est, quis imperdiet diam molestie eu. Aenean lobortis condimentum pharetra. Integer eget sem dictum, tempor arcu non, tincidunt purus. Sed nisi arcu, eleifend non maximus quis, porttitor id sem. Aliquam erat volutpat. Vivamus maximus tempus velit sit amet blandit. Quisque eleifend arcu at nisi elementum efficitur. Praesent consectetur nibh eget accumsan convallis. In pharetra nibh lorem, ac venenatis ipsum tincidunt venenatis. Donec eros justo, ultrices sit amet quam condimentum, placerat sollicitudin justo.
</p>
</section>
<div style="clear:both;"></div>
</footer>
CSS
html, body {
height: 100%;
background-color: green;
}
footer {
background-color: yellow;
min-height: 100%;
height: auto !important;
height: 100%;
overflow: hidden;
}
footer section {
float: left;
width: 33.33%;
background-color: red;
padding-bottom: 999999em;
margin-bottom: -999999em;
}
see demo http://jsfiddle.net/gfoff12w/3/
Note the CSS rules padding-bottom: 999999em and margin-bottom: -999999em these CSS rules will force the browser to create an "height" on the floated section elements.