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>
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.
I am having trouble with the following html and css trying to get the z-index to keep my secondary-panel on top of the scroll but still static with its content.
JSFiddle - without scroll bar: https://jsfiddle.net/kyp0gd2r/1/
JSFiddle - with scroll bar: https://jsfiddle.net/kyp0gd2r/2/
HTML & CSS:
body {
background: green;
}
.single-pump-view-container-wrapper {
position: relative;
border: 3px solid purple;
height: calc(100% - 3px);
}
.inner-wrapper {
display: flex;
margin: 0 0 0 1em;
height: calc(100% - 2em - 3px);
overflow: hidden;
}
.single-pump-controller {
width: 290px;
background: yellow;
}
.data-channel-panel-area {
margin: 1em 10px 0 10px;
width: 570px;
background: blue;
overflow-y: auto;
overflow-x: hidden;
}
.container-wrapper {
position: relative;
width: 534px;
margin-bottom: 18px;
}
.secondary-panel {
position: absolute;
left: calc(100% - 120px);
top: 15px;
width: 300px;
height: 30px;
background: red;
z-index: 999;
}
.right-area {
display: flex;
flex-direction: column;
flex: 1 1 0%;
box-sizing: border-box;
padding-right: 18px;
padding-top: 1em;
width: 100%;
background: gray;
}
div {
display: block;
}
html,
body {
height: 100%;
width: 100%;
overflow: hidden;
}
body {
margin: 0;
font-family: Roboto, "Helvetica Neue", sans-serif;
}
<body>
<div style="padding: 0px 5px;height: calc(100% - 135px);">
<div class="single-pump-view-container-wrapper">
<div class="inner-wrapper">
<div class="single-pump-controller">left</div>
<div class="data-channel-panel-area">
<div class="container-wrapper">
<p>Title Goes Here</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquet nisi eget metus vestibulum gravida. Praesent pulvinar hendrerit est, et eleifend sem vulputate id. Suspendisse ex purus, vestibulum ut enim ut, euismod finibus ex. Curabitur a sapien in est malesuada sollicitudin. Donec aliquam odio nec lacinia interdum. Morbi luctus imperdiet libero, id placerat velit consectetur vitae. Nulla congue ut mi id tincidunt. Vestibulum dolor ipsum, auctor tristique nisl sed, tincidunt mollis risus. Suspendisse sollicitudin, nisl vel semper gravida, neque lectus laoreet erat, quis fermentum dui tortor a nibh. Donec sed massa volutpat, pharetra lacus eget, tempus mauris. Nam sed posuere ipsum, a porta leo. Vestibulum a odio ut quam tristique mollis. Morbi tristique faucibus elementum. Morbi nibh est, dapibus ut libero nec, mattis cursus ligula.</p>
<div class="secondary-panel">ssss</div>
</div>
<div class="container-wrapper">
<p>Title Goes Here</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquet nisi eget metus vestibulum gravida. Praesent pulvinar hendrerit est, et eleifend sem vulputate id. Suspendisse ex purus, vestibulum ut enim ut, euismod finibus ex. Curabitur a sapien in est malesuada sollicitudin. Donec aliquam odio nec lacinia interdum. Morbi luctus imperdiet libero, id placerat velit consectetur vitae. Nulla congue ut mi id tincidunt. Vestibulum dolor ipsum, auctor tristique nisl sed, tincidunt mollis risus. Suspendisse sollicitudin, nisl vel semper gravida, neque lectus laoreet erat, quis fermentum dui tortor a nibh. Donec sed massa volutpat, pharetra lacus eget, tempus mauris. Nam sed posuere ipsum, a porta leo. Vestibulum a odio ut quam tristique mollis. Morbi tristique faucibus elementum. Morbi nibh est, dapibus ut libero nec, mattis cursus ligula.</p>
<div class="secondary-panel">ssss</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquet nisi eget metus vestibulum gravida. Praesent pulvinar hendrerit est, et eleifend sem vulputate id. Suspendisse ex purus, vestibulum ut enim ut, euismod finibus ex. Curabitur a sapien in est malesuada sollicitudin. Donec aliquam odio nec lacinia interdum. Morbi luctus imperdiet libero, id placerat velit consectetur vitae. Nulla congue ut mi id tincidunt. Vestibulum dolor ipsum, auctor tristique nisl sed, tincidunt mollis risus. Suspendisse sollicitudin, nisl vel semper gravida, neque lectus laoreet erat, quis fermentum dui tortor a nibh. Donec sed massa volutpat, pharetra lacus eget, tempus mauris. Nam sed posuere ipsum, a porta leo. Vestibulum a odio ut quam tristique mollis. Morbi tristique faucibus elementum. Morbi nibh est, dapibus ut libero nec, mattis cursus ligula.</p>
</div>
</div>
<div class="right-area"></div>
</div>
</div>
</div>
</body>
Stack-blitz version: (Did this one to test that it was not angular causing my issue, also closest to actual code)
https://stackblitz.com/edit/angular-ivy-wezlub?file=src%2Fstyles.css
In .data-channel-panel-area, overflow-y: auto; cannot be used in combination with e.g. overflow-x: visible;. See MDN:
Setting one axis to visible (the default) while setting the other to a different value results in visible behaving as auto
auto will scroll on overflow. One alternative would be to set both axes to visible, then implement your own scrollbar for .data-channel-panel-area, though it may not be worth going that far. Another approach might be to move .secondary-panel elements out of .data-channel-panel-area, then position them with a JavaScript scroll event.
In any case, consider that it might be bad UX to have an element appearing over a scrollbar and under probably wouldn't look good.
This will solve your problem
var secondary_panel = document.getElementsByClassName('secondary-panel');
document.getElementsByClassName('data-channel-panel-area')[0].addEventListener('scroll', function() {
var scrolled = this.scrollTop;
if (scrolled >= 18 && scrolled <= 231) {
secondary_panel[0].style.position = "fixed";
secondary_panel[0].style.top = scrolled * 0.0001 + 'px';
secondary_panel[0].style.marginTop = "25px";
secondary_panel[0].style.marginLeft = "-240px";
} else {
secondary_panel[0].style.position = "absolute";
secondary_panel[0].style.top = '15px';
secondary_panel[0].style.marginTop = "0px";
secondary_panel[0].style.marginLeft = "0px";
}
if (scrolled >= 286 && scrolled <= 490) {
secondary_panel[1].style.position = "fixed";
secondary_panel[1].style.top = scrolled * 0.0001 + 'px';
secondary_panel[1].style.marginTop = "25px";
secondary_panel[1].style.marginLeft = "-240px";
} else {
secondary_panel[1].style.position = "absolute";
secondary_panel[1].style.top = '15px';
secondary_panel[1].style.marginTop = "0px";
secondary_panel[1].style.marginLeft = "0px";
}
})
body {
background: green;
}
.single-pump-view-container-wrapper {
position: relative;
border: 3px solid purple;
height: calc(100% - 3px);
}
.inner-wrapper {
display: flex;
margin: 0 0 0 1em;
height: calc(100% - 2em - 3px);
overflow: hidden;
}
.single-pump-controller {
width: 290px;
background: yellow;
}
.data-channel-panel-area {
margin: 1em 10px 0 10px;
width: 570px;
background: blue;
overflow-y: auto;
overflow-x: hidden;
}
.container-wrapper {
position: relative;
width: 534px;
margin-bottom: 18px;
}
.secondary-panel {
position: absolute;
left: calc(100% - 120px);
top: 15px;
width: 300px;
height: 30px;
background: red;
z-index: 999;
}
.right-area {
display: flex;
flex-direction: column;
flex: 1 1 0%;
box-sizing: border-box;
padding-right: 18px;
padding-top: 1em;
width: 100%;
background: gray;
}
div {
display: block;
}
html,
body {
height: 100%;
width: 100%;
overflow: hidden;
}
body {
margin: 0;
font-family: Roboto, "Helvetica Neue", sans-serif;
}
<body>
<div style="padding: 0px 5px;height: calc(100% - 135px);">
<div class="single-pump-view-container-wrapper">
<div class="inner-wrapper">
<div class="single-pump-controller">left</div>
<div class="data-channel-panel-area">
<div class="container-wrapper">
<p>Title Goes Here</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquet nisi eget metus vestibulum gravida. Praesent pulvinar hendrerit est, et eleifend sem vulputate id. Suspendisse ex purus, vestibulum ut enim ut, euismod finibus ex. Curabitur
a sapien in est malesuada sollicitudin. Donec aliquam odio nec lacinia interdum. Morbi luctus imperdiet libero, id placerat velit consectetur vitae. Nulla congue ut mi id tincidunt. Vestibulum dolor ipsum, auctor tristique nisl sed, tincidunt
mollis risus. Suspendisse sollicitudin, nisl vel semper gravida, neque lectus laoreet erat, quis fermentum dui tortor a nibh. Donec sed massa volutpat, pharetra lacus eget, tempus mauris. Nam sed posuere ipsum, a porta leo. Vestibulum a
odio ut quam tristique mollis. Morbi tristique faucibus elementum. Morbi nibh est, dapibus ut libero nec, mattis cursus ligula.</p>
<div class="secondary-panel">ssss</div>
</div>
<div class="container-wrapper">
<p>Title Goes Here</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquet nisi eget metus vestibulum gravida. Praesent pulvinar hendrerit est, et eleifend sem vulputate id. Suspendisse ex purus, vestibulum ut enim ut, euismod finibus ex. Curabitur
a sapien in est malesuada sollicitudin. Donec aliquam odio nec lacinia interdum. Morbi luctus imperdiet libero, id placerat velit consectetur vitae. Nulla congue ut mi id tincidunt. Vestibulum dolor ipsum, auctor tristique nisl sed, tincidunt
mollis risus. Suspendisse sollicitudin, nisl vel semper gravida, neque lectus laoreet erat, quis fermentum dui tortor a nibh. Donec sed massa volutpat, pharetra lacus eget, tempus mauris. Nam sed posuere ipsum, a porta leo. Vestibulum a
odio ut quam tristique mollis. Morbi tristique faucibus elementum. Morbi nibh est, dapibus ut libero nec, mattis cursus ligula.</p>
<div class="secondary-panel">ssss</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquet nisi eget metus vestibulum gravida. Praesent pulvinar hendrerit est, et eleifend sem vulputate id. Suspendisse ex purus, vestibulum ut enim ut, euismod finibus ex. Curabitur
a sapien in est malesuada sollicitudin. Donec aliquam odio nec lacinia interdum. Morbi luctus imperdiet libero, id placerat velit consectetur vitae. Nulla congue ut mi id tincidunt. Vestibulum dolor ipsum, auctor tristique nisl sed, tincidunt
mollis risus. Suspendisse sollicitudin, nisl vel semper gravida, neque lectus laoreet erat, quis fermentum dui tortor a nibh. Donec sed massa volutpat, pharetra lacus eget, tempus mauris. Nam sed posuere ipsum, a porta leo. Vestibulum a
odio ut quam tristique mollis. Morbi tristique faucibus elementum. Morbi nibh est, dapibus ut libero nec, mattis cursus ligula.</p>
</div>
</div>
<div class="right-area"></div>
</div>
</div>
</div>
</body>
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>
i have no idea how to put yellow(bottom) div exactly under the pink(left) one.
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AutoDealer</title>
<style>
.container{
width: 860px;
height: 1074px;
margin-right: auto;
margin-left: auto;
border: 1px solid red;
}
.nav{
}
.wrapper{
display: block;
overflow: hidden;
border: 1px solid green;
}
.left{
width: 399px;
float: left;
background-color: pink;
}
.right{
height:350px;
width: 449px;
float: left;
overflow: hidden;
background-color: blue;
overflow: hidden;
}
.bottom{
clear: both;
width: 399px;
background-color: yellow;
}
</style>
</head>
<body>
<div class="container">
<div class="nav"></div>
<div class="wrapper">
<div class="left">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ultricies aliquet tellus sit amet ultrices. Sed faucibus, nunc vitae accumsan laoreet, enim metus varius nulla, ac ultricies felis ante venenatis justo. In hac habitasse platea dictumst. In cursus enim nec urna molestie, id mattis elit mollis. In sed eros eget nibh congue vehicula. Nunc vestibulum enim risus, sit amet suscipit dui auctor et. Morbi orci magna, accumsan at turpis a, scelerisque congue eros. Morbi non mi vel nibh varius blandit sed et urna.</p>
</div>
<div class="right">
<p>Quisque vulputate mi id turpis luctus, quis laoreet nisi vestibulum. Morbi facilisis erat vitae augue ornare convallis. Fusce sit amet magna rutrum, hendrerit purus vitae, congue justo. Nam non mi eget purus ultricies lacinia. Fusce ante nisl, efficitur venenatis urna ut, pellentesque egestas nisl. In ut faucibus eros, sed viverra ex. Vestibulum aliquet accumsan massa, at feugiat ipsum interdum blandit. Morbi et orci hendrerit orci consequat ornare ac et sapien. Nulla vestibulum lectus bibendum, efficitur purus in, venenatis nunc. Nunc tincidunt velit sit amet orci pellentesque maximus. Quisque a tempus lectus.</p>
</div>
<div class="bottom">
<p>ucibus eros, sed viverra ex. Vestibulum aliquet accumsan massa, at feugiat ipsum interdum blandit. Morbi et orci hendrerit orci consequat ornare ac et sapien. Nulla vestibulum lectus bibendum, efficitur purus in, venenatis nunc. Nunc tincidunt velit sit amet orci pellentesq</p></div>
</div>
</div>
</body>
</html>
clear: both is causing the div to do just that, clear both sides and force itself into a position where the blue element isn't right next to it.
Remove that and it'll be right under the one above it.
Hi please check the update code
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AutoDealer</title>
<style>
.container{
width: 860px;
height: 1074px;
margin-right: auto;
margin-left: auto;
border: 1px solid red;
}
.nav{
}
.wrapper{
display: block;
overflow: hidden;
border: 1px solid green;
}
.left{
width: 399px;
float: left;
background-color: pink;
}
.right{
height:350px;
width: 449px;
float: left;
overflow: hidden;
background-color: blue;
overflow: hidden;
}
.bottom{
width: 399px;
background-color: yellow;
}
.pull-left
{
float:left
}
</style>
</head>
<body>
<div class="container">
<div class="nav"></div>
<div class="wrapper">
<div class="pull-left">
<div class="left">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ultricies aliquet tellus sit amet ultrices. Sed faucibus, nunc vitae accumsan laoreet, enim metus varius nulla, ac ultricies felis ante venenatis justo. In hac habitasse platea dictumst. In cursus enim nec urna molestie, id mattis elit mollis. In sed eros eget nibh congue vehicula. Nunc vestibulum enim risus, sit amet suscipit dui auctor et. Morbi orci magna, accumsan at turpis a, scelerisque congue eros. Morbi non mi vel nibh varius blandit sed et urna.</p>
</div>
<div class="bottom">
<p>ucibus eros, sed viverra ex. Vestibulum aliquet accumsan massa, at feugiat ipsum interdum blandit. Morbi et orci hendrerit orci consequat ornare ac et sapien. Nulla vestibulum lectus bibendum, efficitur purus in, venenatis nunc. Nunc tincidunt velit sit amet orci pellentesq</p>
</div>
</div>
<div class="right">
<p>Quisque vulputate mi id turpis luctus, quis laoreet nisi vestibulum. Morbi facilisis erat vitae augue ornare convallis. Fusce sit amet magna rutrum, hendrerit purus vitae, congue justo. Nam non mi eget purus ultricies lacinia. Fusce ante nisl, efficitur venenatis urna ut, pellentesque egestas nisl. In ut faucibus eros, sed viverra ex. Vestibulum aliquet accumsan massa, at feugiat ipsum interdum blandit. Morbi et orci hendrerit orci consequat ornare ac et sapien. Nulla vestibulum lectus bibendum, efficitur purus in, venenatis nunc. Nunc tincidunt velit sit amet orci pellentesque maximus. Quisque a tempus lectus.</p>
</div>
</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.