I've been working on a website and I'm trying to show some text when my mouse is hovering an image. This is a pretty common thing on website today I believe. However for some reasons when I hover my image the text goes "out of bonds" of the image. (I will attach a screenshot you'll understand)
As you can see not only it goes below the image at the bottom, but also it goes through on the right of the image. I am not sure how to fix this? Is this because of the font size? I don't think so
div className='image_section'>
<h1 className='section_title-top'>SERVICES </h1>
<div className='img-container'>
<div class="image">
<img class="image__img" src={bdh1Img} alt="Bricks" />
<div class="image__overlay image__overlay--primary">
<div class="image__title">This is my title and I want three same image</div>
<p class="image__description">
this is some random text
Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet,
adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas
ligula massa, varius a, semper congue, euismod non, mi. Proin porttitor,
orci nec nonummy molestie, enim est eleifend mi, non fermentum diam nisl
sit amet erat. Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit sodales. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede pellentesque fermentum. Maecenas adipiscing ante non diam sodales hendrerit.
Ut velit mauris, egestas sed,
gravida nec, ornare ut, mi. Aenean
ut orci vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula non tempus aliquam,
nunc turpis ullamcorper nibh, in tempus sapien eros vitae ligula. Pellentesque
</p>
</div>
</div>
</div>
</div>
.image_section {
width: 100%;
background: #eee;
display: flex;
flex-direction: column;
padding: 2rem 0;
}
.section_title-top{
text-align: center;
color: #000;
padding: 2.5rem 0;
}
.img-container {
max-width: 1140px;
margin: auto;
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.image {
position: relative;
}
.image p, h2{
font-size: 14px;
}
.image__img {
display: block;
max-width: 100%;
height: auto;
}
.image__overlay {
position: absolute;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.75);
color: #ffffff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
opacity: 0;
transition: opacity 0.25s;
}
.image__overlay > * {
transform: translateY(20px);
transition: transform 0.25s;
}
.image__overlay:hover {
opacity: 1;
}
.image__overlay:hover > * {
transform: translateY(0);
}
.image__title {
font-size: 1.5em;
text-align: center;
font-weight: bold;
}
.image__description {
text-align: center;
font-size: 1.15em;
margin-top: 0.35em;
}
#media screen and (max-width: 980px) {
.img-container {
max-width: 90%;
margin: auto;
grid-template-columns: 1fr;
}
}
Thanks for any help
I think this is too much text to be on an image
you can use ellipsis property like this
for example:
.image__description {
text-align: center;
font-size: 1.15em;
margin-top: 0.35em;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3; /* this set the number of rows to show*/
-webkit-box-orient: vertical;
}
then if want the user to display the full text u can make a modal to show the full text or something
I saw that in the hover div (class name: image__overlay image__overlay--primary) you use position absulate so that it renders aspect of the main body. Add a width, it will be solved.
Related
I've been working on how to rotate a div with number text and an ::after pseudo element styled into a line. Essentially I've gotten as far as arranging it horizontally (responding to screen width), but I want the text to rotate -90deg, stick to the left side of its container, and for the line to take up the remaining height of the container (but not go outside of the container).
Should look like this:
p {
display: flex;
align-items: center;
font-size: 10vw;
font-weight: bold;
margin: 0;
}
p::after {
content: '';
flex: 1;
margin-left: 1rem;
height: 2px;
background-color: #000;
}
<div class="container">
<div class="num">
<p>01</p>
</div>
</div>
I've tried adding a transform property with rotate and translate, messing with writing-mode properties, but can't seem to get the pseudo element to lengthen dynamically with the changing height (since the container's height changes with screen size). Any tips?
Figured it out, here's the solution (styled with flexbox) for anyone with this weirdly specific problem.
section {
display: flex;
background-color: blue;
}
.wrapper-section {
display: flex;
}
.section-sum {
height: 100%;
display: flex;
flex-flow: column nowrap;
}
.vt-line {
height: 100%;
width: 2px;
background-color: #262525;
margin: 0 auto;
}
.num p {
display: inline-block;
align-items: center;
font-size: 5em;
font-weight: bold;
margin: 0;
transform: rotate(-90deg);
}
.wrapper-aboutinfo {
display: flex;
align-items: center;
}
.container-aboutimg img {
display: block;
max-width: 100%;
margin: 0 auto;
}
<section id="about">
<div class="wrapper-section">
<div class="section-sum">
<div class="vt-line"></div>
<div class="num">
<p>01</p>
</div>
</div>
<div class="wrapper-aboutinfo">
<div class="container-aboutimg">
<img src="https://images.pexels.com/photos/3861964/pexels-photo-3861964.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
</div>
<div class="info-about">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam volutpat pretium pharetra. Aliquam non ultrices neque. Praesent rhoncus sapien vitae sem ultrices, ut malesuada magna consequat. Mauris eu laoreet justo. Integer tristique porta nibh vitae ultrices. Praesent porta ligula ut nisl pellentesque congue. Sed finibus ut est et lobortis. Pellentesque velit magna, sagittis non lorem at, pulvinar tempor sem. Nam iaculis nisi nec elit efficitur, non varius sapien feugiat.
<br>
<br>
Morbi justo arcu, rhoncus non sagittis eu, faucibus id ipsum. Vivamus augue lectus, venenatis a commodo eget, ullamcorper vel lorem. Vivamus posuere sagittis eros et consectetur. In feugiat gravida lectus sed pulvinar. Etiam dapibus luctus magna, fermentum dapibus mauris vulputate in. Aliquam at massa erat. In tincidunt dictum risus, vel eleifend sem tempor id. </p>
</div>
</div>
</div>
</section>
I have a button inside a side-column that will show some text if clicked, however I noticed that text overflows the original container div:
https://jsfiddle.net/czjub804/10/
.container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
height: auto;
background-color:red;
}
.main-column {
margin-left: 8vw;
background-color:blue;
}
.side-column {
margin: 4vw auto;
align-content: flex-start;
width: 20vw;
height: auto;
background-color:purple;
}
.about-author-text {
font-family: "Merriweather";
font-weight: lighter;
font-size: 0;
padding: 0;
line-height: 2;
letter-spacing: 1px;
display: flex;
flex-direction: column;
height: 0;
flex-flow: wrap;
visibility: hidden;
transition: font-size 0.5s ease-in-out;
color: var(--light-text-color);
}
.visible {
visibility: visible;
max-height: auto;
width: inherit;
line-height: 2;
font-size: 0.9em;
padding: 0;
}
How can I make the .columns div (red background) expand its height when the text is visible?
Try removing the height: 0 set on the class .about-author-text.
It doesn't really make sense to have the container's height set to 0.
I've changed your css class for you
.about-author-text {
font-family: "Merriweather";
font-weight: lighter;
font-size: 0;
padding: 0;
line-height: 2;
letter-spacing: 1px;
display: flex;
flex-direction: column;
flex-flow: wrap;
visibility: hidden;
transition: font-size 0.5s ease-in-out;
color: var(--light-text-color);
}
I've removed the height property.
Remove the height property from the .about-author-text class.
const text = document.getElementById("about-text")
function showText() {
text.classList.toggle("visible")
}
.container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
height: auto;
background-color:red;
}
.main-column {
margin-left: 8vw;
background-color:blue;
}
.side-column {
margin: 4vw auto;
align-content: flex-start;
width: 20vw;
height: auto;
background-color:purple;
}
.about-author-text {
font-family: "Merriweather";
font-weight: lighter;
font-size: 0;
padding: 0;
line-height: 2;
letter-spacing: 1px;
display: flex;
flex-direction: column;
flex-flow: wrap;
visibility: hidden;
transition: font-size 0.5s ease-in-out;
color: var(--light-text-color);
}
.visible {
visibility: visible;
max-height: auto;
width: inherit;
line-height: 2;
font-size: 0.9em;
padding: 0;
}
.about-author-text p:first-child {
margin-top: 0;
}
<div class="container">
<div class="main-column">
helllo
</div>
<div class="side-column">
<button onclick="showText()">
About
</button>
<div id="about-text" class="about-author-text">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer auctor nec libero sit amet gravida. Maecenas blandit pulvinar nulla, et porta purus ultrices vel. Curabitur vestibulum accumsan nulla, a ullamcorper arcu tempor molestie. Nulla vitae sollicitudin sem. Suspendisse hendrerit, purus sed congue fringilla, ex mauris porta metus, imperdiet congue elit dolor et mauris. Aliquam ut turpis pretium, feugiat libero nec, finibus mi. Sed ac sagittis tortor. Cras quis tellus vel ligula vehicula tristique in ac erat. Donec mollis hendrerit elit, vel tempor nulla ornare sed.
Nullam at congue ex. Etiam velit libero, dictum in tristique non, pulvinar non orci. Nam nibh diam, porttitor et bibendum at, molestie ut metus. Praesent congue tellus sit amet elit venenatis feugiat. Nam vitae erat elit. Integer fermentum magna ut tempus accumsan. Cras vitae tortor vehicula, bibendum nulla sit amet, dignissim massa. Nunc a lorem egestas, fermentum purus in, lacinia odio. Etiam scelerisque risus sit amet magna consequat, pharetra scelerisque elit egestas. Pellentesque vitae blandit lectus, at rhoncus libero. Vivamus hendrerit tellus dolor, facilisis fringilla lorem viverra non. Integer eros est, luctus ut orci id, rutrum porta risus. Nam sollicitudin tempor nunc ut mollis.
</p>
</div>
</div>
</div>
I need to create a website (two columns) where one column contains some text (vertical centered) and the other column contains a picture (sticky to bottom).
Both of them need to be responsive (so position: fixed is not an option for the image).
I tried to achieve this by using Bootstrap and the w3 responsive framework. But both of them seem unable to put a responsive image inside a column that is always stuck to the bottom.
Any tips on how I can achieve this layout while being responsive (Picture needs to resize etc)?
Here's a solution without using flex. It's completely responsive and can be scaled both horizontally and vertically.
body {
margin: 0;
padding: 0;
}
#container {
width: 100%;
height: 100vh;
overflow: hidden;
}
#column1 {
position: relative;
width: calc(50% - 4px);
height: calc(100% - 4px);
display: inline-block;
border: 2px solid black;
}
#column1 span {
display: block;
position: relative;
top: 50%;
transform: translateY(-50%);
padding: 10px;
}
#column2 {
position: relative;
top: -50%;
left: 50%;
width: calc(50% - 2px);
height: calc(50% - 4px);
display: inline-block;
border: 2px solid black;
border-left: none;
}
<div id="container">
<div id="column1">
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus interdum bibendum laoreet. Suspendisse eu mauris urna. Vestibulum vel blandit erat. Suspendisse egestas semper urna in convallis. Aliquam lobortis, leo nec pharetra semper, elit risus aliquet metus, non malesuada massa turpis tincidunt lectus. Fusce pellentesque metus ac lectus ultricies, et fermentum tellus fringilla.</span>
</div>
<footer id="column2"></footer>
</div>
Here's a quick example of how you can achieve it with flex.
/* Std */
body {
margin: 0;
width: 100%;
height: 100%;
}
/* Flex Classes */
.flex {
display: flex;
}
.flex--row {
flex-direction: row;
}
/* Column Classes */
.column {
position: relative;
min-height: 100vh;
}
.left-column {
flex: 0.7;
background: red;
}
.right-column {
flex: 0.3;
background: blue;
}
/* Picture */
#column-picture {
width: 100%;
height: inherit;
position: absolute;
bottom: 0;
}
<div class="flex flex--row">
<div class="column left-column">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur lacinia auctor tincidunt. Sed a turpis et eros iaculis convallis quis in nisl. Donec fringilla auctor eros ut ultrices. Donec laoreet dui urna, ut pharetra neque molestie et. Ut sagittis diam a lacus euismod dignissim. Sed vulputate dui erat, at hendrerit ante commodo et. Sed gravida ex et est bibendum pretium. Aliquam a convallis dui. Maecenas magna velit, ultrices eu massa sit amet, dictum accumsan tellus. Maecenas eget placerat magna. Nullam mollis lacus tempor lorem tempor tincidunt. Aliquam erat volutpat.
</div>
<div class="column right-column">
<img id="column-picture" alt="Lion" src="https://cbs.umn.edu/sites/cbs.umn.edu/files/public/african_lion_king-wide.jpg"/>
</div>
</div>
Tell me what you think of this. #Mech
https://codepen.io/rickydam/pen/zdrmWX
HTML
<div class="left">
<div class="innerleft">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus interdum bibendum laoreet. Suspendisse eu mauris urna. Vestibulum vel blandit erat. Suspendisse egestas semper urna in convallis. Aliquam lobortis, leo nec pharetra semper, elit risus aliquet metus, non malesuada massa turpis tincidunt lectus. Fusce pellentesque metus ac lectus ultricies, et fermentum tellus fringilla. Phasellus vel quam a sem elementum volutpat vel eget neque. Nam efficitur maximus risus, ac eleifend augue tempor rutrum. Fusce vehicula non lorem vitae blandit. Donec in scelerisque sem, quis congue velit.
</p>
</div>
</div><!--
--><div class="right">
<img src="http://www.uniwallpaper.com/static/images/Sunset-Village-Wallpaper_8I7ogbf.jpg">
</div>
CSS
.left {
width: 50%;
height: 100vh;
background-color: lightgray;
display: inline-block;
vertical-align: middle;
margin: auto;
}
.innerleft {
background-color: lightblue;
height: 100vh;
display: flex;
align-items: center;
}
.left p {
margin: 20px;
padding: 10px;
background-color: gray;
}
.right {
width: 50%;
height: 100vh;
background-color: slategray;
display: inline-block;
vertical-align: top;
position: relative;
}
.right img {
position: absolute;
bottom: 0;
max-width: 100%;
}
I managed to use the Flexible Box Layout Module for a lot of things, however when it comes to paragraphs I'm experiencing this issue:
When I use a small amount of text everything works as expected:
When I use a large amount of text the layout breaks:
Here is the code I am using:
body {
width: 90%;
margin: 3em auto;
background-color: #aaa;
}
section {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
border: 1px solid black;
}
.title {
flex: 1 0 100%;
text-align: center;
background-color: #eee;
}
.image {
flex: 0 0 auto;
background-color: #ccc;
}
.image img {
display: block;
max-height: 100%;
max-width: 100%;
}
.text {
flex: 6 0 auto;
background-color: #96AED1;
}
<section>
<div class="title">
<h1>Title here</h1>
</div>
<div class="image">
<img src="http://www.macovei-sculptor.ro/img.jpg">
</div>
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer felis velit, ullamcorper eu ornare sed, vulputate quis diam. Duis ultrices rutrum sapien, in condimentum nibh sagittis sit amet. Morbi sit amet rhoncus dui, at pharetra nisi. Nunc et
lacus porttitor, pretium nisl at, sollicitudin velit. Donec felis nisl, consequat vitae egestas vestibulum, egestas non tortor. Cras mattis non sem nec aliquam. Sed dignissim sit amet sapien vitae feugiat. Pellentesque vel luctus ante, quis ornare
purus. Nulla in arcu sapien. Aenean tempor arcu ac lacinia pellentesque. Quisque vulputate maximus augue, non aliquet ligula gravida in. Donec a leo justo. Integer velit eros, blandit sit amet elit eget, efficitur mollis nulla. Suspendisse tempor
ligula facilisis scelerisque ullamcorper. Ut vehicula ligula ipsum, cursus condimentum sapien pretium ac.</p>
</div>
</section>
Why is the <p> tag not wrapping properly when using a large amount of text?
The proper solution is either to put
white-space: initial;
or
min-width: 0;
Check out the link here
*I am aware the link is about truncating texts. However, the same solution applies to wrap the texts around.
the .text's parent has flex-direction: row, so .text should have shrink set on 1 otherwise the text inside won't wrap
body {
width: 90%;
margin: 3em auto;
background-color: #aaa;
}
section {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
border: 1px solid black;
}
.title {
flex: 1 0 100%;
text-align: center;
background-color: #eee;
}
.image {
flex: 0 0 auto;
background-color: #ccc;
}
.image img {
display: block;
max-height: 100%;
max-width: 100%;
}
.text {
flex: 6 1 auto; /* FLEX-SHRINK: 1; */
background-color: #96AED1;
}
<section>
<div class="title">
<h1>Title here</h1>
</div>
<div class="image">
<img src="http://www.macovei-sculptor.ro/img.jpg">
</div>
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer felis velit, ullamcorper eu ornare sed, vulputate quis diam. Duis ultrices rutrum sapien, in condimentum nibh sagittis sit amet. Morbi sit amet rhoncus dui, at pharetra nisi. Nunc et
lacus porttitor, pretium nisl at, sollicitudin velit. Donec felis nisl, consequat vitae egestas vestibulum, egestas non tortor. Cras mattis non sem nec aliquam. Sed dignissim sit amet sapien vitae feugiat. Pellentesque vel luctus ante, quis ornare
purus. Nulla in arcu sapien. Aenean tempor arcu ac lacinia pellentesque. Quisque vulputate maximus augue, non aliquet ligula gravida in. Donec a leo justo. Integer velit eros, blandit sit amet elit eget, efficitur mollis nulla. Suspendisse tempor
ligula facilisis scelerisque ullamcorper. Ut vehicula ligula ipsum, cursus condimentum sapien pretium ac.</p>
</div>
</section>
If the parents width is not set, the text will not know when to start wrapping.
Setting either the width or max-width property will let the string know when to start wrapping
I have a solution that seems to work but I do not that it is 100% correct, here is a fiddle:
https://jsfiddle.net/2xxorq4n/1/
And here is the CSS code:
body {
width: 90%;
margin: 3em auto;
background-color: #aaa;
}
section {
border:1px solid black;
}
.title {
text-align: center;
background-color: #eee;
}
.image {
background-color: #ccc;
}
.image img {
display: block;
max-height: 100%;
max-width: 100%;
}
.text {
background-color: #96AED1;
}
/* FLEX STYLES */
section {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
.title, .image, .text {
flex: 1 100%;
}
#media all and (min-width: 600px) {
.image { flex: 1 auto; }
}
#media all and (min-width: 800px) {
.text { flex: 800 0px; }
.image { order: 1; }
.text { order: 2; }
}
Specifically, I do not think that this is correct: .text { flex: 800 0px; }. Although it seems to work, I do not think that it is supposed to work like that as the example on css tricks website which provides further information on Flexbox usage shows flex: 2 0px;:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
I use display:table and vertical-align:middle to vertically center a div with dynamic height.
CSS
.table {
display:table;
height: 100%;
width: 100%;
}
.cell {
display: table-cell;
vertical-align: middle;
text-align:center;
}
.content {
display: inline-block;
width: 100px;
overflow-y: auto; /* Useless */
}
HTML
<div class="table">
<div class="cell">
<div class="content">
Then this text becomes too long, it will cause
the .table div to expand beyond its container
even if set to height: 100%
</div>
</div>
</div>
How do I get the content div to get a vertical scroll when its height becomes greater than the table div (or rather the table div's parent)?
JS Fiddle example
Instead of a CSS tables approach, you can use the Centering in the unknown approach:
.cell, .cell:before {
height: 100%;
}
.cell:before {
content: '';
margin-right: -0.25em; /* Adjusts for spacing */
}
.cell:before, .cont {
vertical-align: middle;
display: inline-block;
}
.cont {
max-height: 100%;
overflow-y: auto;
}
.margin {
position: absolute;
left: 32px;
right: 32px;
top: 32px;
bottom: 32px;
background: yellow;
text-align: center;
}
.cell, .cell:before {
height: 100%;
}
.cell:before {
content: '';
margin-right: -0.25em; /* Adjusts for spacing */
}
.cell:before, .cont {
vertical-align: middle;
display: inline-block;
}
.cont {
width: 240px;
padding: 0px 12px;
background: #ddd;
text-align: left;
border: 1px solid #000;
max-height: 100%;
overflow-y: auto;
}
<div class="margin">
<div class="cell">
<div class="cont">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla cursus lacinia ipsum quis pharetra. Donec vitae quam placerat lectus lobortis congue. Suspendisse maximus euismod aliquam. Ut sagittis risus vitae mauris imperdiet, ac venenatis orci dignissim. Nam felis dui, commodo non venenatis in, pulvinar a lectus. Duis lacus nulla, fringilla ut malesuada vel, iaculis ut dui. Nunc venenatis imperdiet tortor, eu sollicitudin velit vulputate finibus. In placerat justo lacus, quis faucibus leo varius ornare. Mauris vestibulum ligula in est pellentesque commodo. Donec sollicitudin dui quis quam pretium, eget sollicitudin risus pellentesque. Duis eget lacus varius, finibus augue ac, auctor eros. Proin vestibulum mauris vitae urna volutpat, non ultrices felis ultricies.</p>
</div>
</div>
</div>
You can add a .row element:
<div class="table">
<div class="row">
<div class="cell">
<div class="content">Long text</div>
</div>
</div>
</div>
With this CSS:
.table {
display: table;
height: /* something */;
}
.row {
display: table-row;
height: 100%;
}
.cell {
display: table-cell;
height: 0;
}
.cont {
max-height: 100%;
overflow-y: auto;
}
This reduces the height of .cell as much as possible –making .cont overflow–, but since .row has height: 100%, it will cover .table.
.margin {
position: absolute;
left: 32px;
right: 32px;
top: 32px;
bottom: 32px;
background: yellow;
}
.table {
display: table;
width: 100%;
height: 100%;
}
.row {
display: table-row;
height: 100%;
}
.cell {
display: table-cell;
vertical-align: middle;
text-align: center;
height: 0;
}
.cont {
width: 240px;
padding: 0px 12px;
background: #ddd;
display: inline-block;
text-align: left;
border: 1px solid #000;
max-height: 100%;
overflow-y: auto;
}
<div class="margin">
<div class="table">
<div class="row">
<div class="cell">
<div class="cont">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla cursus lacinia ipsum quis pharetra. Donec vitae quam placerat lectus lobortis congue. Suspendisse maximus euismod aliquam. Ut sagittis risus vitae mauris imperdiet, ac venenatis
orci dignissim. Nam felis dui, commodo non venenatis in, pulvinar a lectus. Duis lacus nulla, fringilla ut malesuada vel, iaculis ut dui. Nunc venenatis imperdiet tortor, eu sollicitudin velit vulputate finibus. In placerat justo lacus, quis
faucibus leo varius ornare. Mauris vestibulum ligula in est pellentesque commodo. Donec sollicitudin dui quis quam pretium, eget sollicitudin risus pellentesque. Duis eget lacus varius, finibus augue ac, auctor eros. Proin vestibulum mauris
vitae urna volutpat, non ultrices felis ultricies.</p>
</div>
</div>
</div>
</div>
</div>
An alternative to achieve the same effect is to use display: flex instead of display: table
.flex {
position:absolute;
left:32px; right:32px; top:32px; bottom:32px;
display: flex;
align-items: center;
justify-content: center;
background:yellow;
}
.item {
max-height: 100%;
box-sizing: border-box;
width: 264px;
padding: 0px 12px;
background: #ddd;
border: 1px solid #000;
overflow:auto;
}
<div class="flex">
<div class="item">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla cursus lacinia ipsum quis pharetra. Donec vitae quam placerat lectus lobortis congue. Suspendisse maximus euismod aliquam. Ut sagittis risus vitae mauris imperdiet, ac venenatis orci dignissim. Nam felis dui, commodo non venenatis in, pulvinar a lectus. Duis lacus nulla, fringilla ut malesuada vel, iaculis ut dui. Nunc venenatis imperdiet tortor, eu sollicitudin velit vulputate finibus. In placerat justo lacus, quis faucibus leo varius ornare. Mauris vestibulum ligula in est pellentesque commodo. Donec sollicitudin dui quis quam pretium, eget sollicitudin risus pellentesque. Duis eget lacus varius, finibus augue ac, auctor eros. Proin vestibulum mauris vitae urna volutpat, non ultrices felis ultricies.</p>
</div>
</div>
This works in Chrome (v39), Firefox (v36), and IE11. However, IE11 doesn't seem to regrow the item div once the scrollbar has been added, even if there is space for it.
It's not the .table div that expands beyond its container. It's the .cont div.
.cont {
width: 240px;
padding: 0px 12px;
background: #ddd;
display: inline-block;
text-align: left;
border: 1px solid #000;
overflow:auto;
}
Nothing in this class limits the height to 100%, so the .cont div will expand beyond the borders of .table
Just add max-heigh:100% to limit it to 100% of the parent's (.cell) height. And then the overflow:auto (that was already there) should do the rest of the job
http://jsfiddle.net/0q78gbvh/1/
EDIT: This will not work in all browsers, because you can't set the max-height from display:table directly in those browsers.
Is this what you are looking for?
Since you have a <p> element in ur jsFiddle Eg, set a max height to the container equal to the .margin
.cont {
width: 240px;
padding: 0px 12px;
background: #ddd;
display: inline-block;
text-align: left;
border: 1px solid #000;
max-height:300px; /* Fixed max-height of container... */
overflow-y:scroll;
}
JSFiddle Example