I have a main div with CSS:
.border {
border-radius: 25px;
border: 8px solid #2C3E50;
padding: 50px;
width: 500px;
height: 500px;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
}
And two buttons, side by side, inside the div, with CSS to make it animate on hover/press. How would I make the buttons to be at the bottom of the div, no matter of what the content is in the div? Position: absolute, doesn't work for me.
Try position: absolute or relative and then alter the bottom and right properties.
Also, have you checked to make sure that no other styles are overwriting your preferred styles? Chrome's developer tools are an awesome way to find this out.
For html:
<div id="wrapper">
<button></button>
</div>
You can apply style:
#wrapper {
position: relative;
}
#wrapper > button {
position: absolute;
bottom: 0;
}
To place the <button> element at the bottom of the wrapper <div>. Take note that you must declare position: relative or position: absolute on the containing element ( the wrapper ) for position: absolute to place a child element (the button) with respect to its bottom.
Try this
.border {
border-radius: 25px;
border: 8px solid #2C3E50;
padding: 50px;
width: 500px;
height: 500px;
margin: 0 auto;
position: relative;
}
.inner-border-normal {
float: left;
}
.inner-border-bottom {
position: absolute;
bottom: 50px;
}
.button {
width: 100px;
height: 32px;
border: 1px solid #CCCCCC;
border-radius: 4px;
background: #F2F2F2;
cursor: pointer;
}
<div class="border">
<div class="inner-border-normal">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin id erat interdum ex dapibus sodales nec id nibh. Sed egestas bibendum erat quis ultricies. Ut auctor iaculis odio quis tempor. In maximus nisi et ex consectetur scelerisque. Nam et nunc sit amet massa faucibus commodo. Etiam at tortor nisl. Integer at justo sit amet ex ornare rutrum a sed felis. Mauris eu risus dolor. Curabitur non ullamcorper lacus. Curabitur ultricies aliquet ex, non maximus erat convallis eget. Nulla pretium ex quis commodo tempus. Nunc non vestibulum neque, vitae venenatis lorem. Nunc eget maximus ante. Sed aliquam ac arcu sed pharetra.</div>
<div class="inner-border-bottom">
<input type="button" class="button" value="Press">
<input type="button" class="button" value="Press">
</div>
</div>
Related
Say there's a div called 'div1', and it has words in it. I set the height of div1 to 'fit-content', so no matter how few or how many words are inside of div1, div1 will always contain them.
Now, say this div1 is itself contained inside of another div that I'll call 'outerDiv'.
Then say there are two small boxes we'll call 'box1' and 'box2', and I want them both at the bottom corners of 'outerDiv'.
I want box1 and box2 to always stay underneath div1, no matter how long div1 gets. Therefore, the height of outerDiv should always be longer than the height of div1.
If, taking all the above, my code currently looks like this:
#outerDiv {
position: relative;
background: darkblue;
height: 400px;
width: 400px;
}
#box1 {
position: absolute;
background: orange;
height: 100px;
width: 100px;
border: 3px darkblue solid;
bottom: 0;
left: 0;
}
#box2 {
position: absolute;
background: orange;
height: 100px;
width: 100px;
border: 3px darkblue solid;
bottom: 0;
right: 0;
}
#div1 {
position: absolute;
background: white;
height: fit-content;
width: 250px;
left: 75px;
top: 100px;
}
<div id="outerDiv">
<div id="box1">
</div>
<div id="box2">
</div>
<div id="div1">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel fringilla est ullamcorper eget nulla. Pharetra vel turpis nunc eget lorem dolor. At consectetur lorem donec massa sapien. Massa
tempor nec feugiat nisl pretium fusce id velit. Orci ac auctor augue mauris augue neque gravida. Molestie a iaculis at erat pellentesque. Nisl vel pretium lectus quam id leo in. Quisque non tellus orci ac auctor augue mauris augue neque. Vestibulum
sed arcu non odio euismod.
</div>
</div>
Then how can I set the height of outerDiv so that box1 and box2 are always underneath div1, no matter how long div1 becomes?
Thanks in advance!
When parent div(#outerDiv) has the relative position and child(#div1) has an absolute position then parent div can not resize itself to the child's size. So I changed some attributes and commented unnecessary parts. Also, I added contenteditable="true" style="outline: none;" to div1 and now it is easy to change size of the text and see the result:
#outerDiv {
position: relative;
background: darkblue;
/* height: 400px; */
width: 400px;
padding-top: 100px;
padding-bottom: 106px; /*height of boxes + 6px border top and bottom*/
}
#box1 {
position: absolute;
background: orange;
height: 100px;
width: 100px;
border: 3px darkblue solid;
bottom: 0;
left: 0;
}
#box2 {
position: absolute;
background: orange;
height: 100px;
width: 100px;
border: 3px darkblue solid;
bottom: 0;
right: 0;
}
#div1 {
/* position: absolute; */
margin: 0 auto;
background: white;
/* height: fit-content; */
width: 250px;
/* left: 75px;
top: 100px; */
}
<div id="outerDiv">
<div id="box1">
</div>
<div id="box2">
</div>
<div id="div1" contenteditable="true" style="outline: none;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel fringilla est ullamcorper eget nulla. Pharetra vel turpis nunc eget lorem dolor. At consectetur lorem donec massa sapien. Massa
tempor nec feugiat nisl pretium fusce id velit. Orci ac auctor augue mauris augue neque gravida. Molestie a iaculis at erat pellentesque. Nisl vel pretium lectus quam id leo in. Quisque non tellus orci ac auctor augue mauris augue neque. Vestibulum
sed arcu non odio euismod.
</div>
</div>
I have a situation in which I have a child div (.timeline) that needs to increase height as the parent divs (.tea-history) height increases. But when I tried using height:inherit; it did not work since the child div inherits height as auto from the parent div, when I tried doing it with height:100%; it would use the height of the entire page.
Anyone got an idea on how this could be fixed so the .timeline class will increase height when the parent div increases height.
.tea-history {
display: flex;
flex-direction: column;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
margin-bottom: 20px;
height: 800px; /*Currently i have set the height to 800 so the timeline is visible*/
width: 90%;
margin-top: 70px;
}
.tea-history .timeline {
position: absolute;
height: inherit;
width: 3px;
border-radius: 20px;
background-color: #7aaa62;
margin-top: 50px;
margin-left: 50px;
}
.tea-history .frame {
width: 80%;
display: grid;
grid-template-columns: 20px auto;
gap: 33px;
margin-top: 30px;
margin-left: 42px;
}
.tea-history .frame .timeline-dot {
display: flex;
align-items: center;
}
.tea-history .timeline-dot .outer-dot {
position: absolute;
height: 15px;
width: 15px;
border-radius: 50%;
border: #000 solid 3px;
}
.tea-history .timeline-dot .inner-dot {
position: absolute;
height: 10px;
width: 10px;
border-radius: 50%;
background-color: #000000;
margin-top: 2px;
margin-left: 2px;
}
<div class="tea-history">
<h3 class="heading">History</h3>
<div class="timeline"></div>
<div class="frame">
<div class="timeline-dot"><span class="outer-dot"><span class="inner-dot"></span></span>
</div>
<div class="content">
<h4>2035 - 2054</h4>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Metus aliquam eleifend mi in nulla posuere sollicitudin aliquam. Volutpat sed cras ornare arcu dui vivamus. Nec nam aliquam sem
et tortor consequat. Ac odio tempor orci dapibus ultrices in. Massa placerat duis ultricies lacus sed turpis tincidunt id. Egestas diam in arcu cursus euismod quis viverra nibh. Elit eget gravida cum sociis natoque. Nunc lobortis mattis aliquam
faucibus purus in. Turpis massa sed elementum tempus egestas. Sit amet nisl purus in mollis nunc sed id semper. Imperdiet nulla malesuada pellentesque elit.
</p>
</div>
</div>
</div>
Because absolute positioned elements are removed from the flow and ignored by other elements. So you can't set the parents height according to an absolutely positioned element that's why inherit didn't work.
You either have to use fixed heights or you need to involve JS.
And here is a tricky way to do it:
Duplicate the content of .tea-history and .timeline in relative divs with display:none value in parent div. So let's say .tea-history_duplicate and .timeline_duplicate. Put .timeline_duplicate on top and .tea-history_duplicate at the bottom.
When your jquery calls the absolute div, just set the according to relative div (.timeline_duplicate or .timeline_duplicate) with the property of display:block; and visibility:hidden;. The relative child will still be invisible but will make the parent's div higher.
Hum, hey ! I got something that I tried to fix for almost four hours, but I couldn't find it. The worst thing is that i'm almost sure that it is a stupid thing to remove or to replace, but I don't know. So Is there is a way to make my background stopping on the last image or if it's a problem in my code, is there is a way to fix it? I'm placing the code. Thanks in advance ! (my code may be horrible, sorry if that's the case ^^)
<!DOCTYPE html>
<html lang="en-fr">
<head>
<meta charset="UTF-8">
<title>RealTea</title>
<style>
body {
background-color: #FFFFFF;
background-size: cover;
background-position: center;
width: 1030px;
height: auto;
}
#Menu {
background-image: url('http://image.noelshack.com/fichiers/2015/17/1429647024-liens.png');
opacity: 0.9;
background-repeat: no-repeat;
width: 1341px;
position: relative;
bottom: auto;
}
nav {
font-size: 25px;
font-family: Verdana;
color: #FFFFFF;
text-align: center;
}
a {
color: #FFFFFF;
font-family: Verdana;
left: -80px;
}
a:hover {
color: #FFFFFF;
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
IMG.displayed {
position: relative;
left: auto;
width: 1340px;
}
p.newsletter {
font-family: Homizio;
font-size: 29px;
color: #339900;
position: relative;
text-align: center;
left: 520px;
bottom: -20px;
width: 314px;
height: 385px;
}
p.Communaute {
font-family: Homizio;
font-size: 29px;
color: #339900;
position: relative;
text-align: center;
left: 140px;
bottom: 393px;
width: 314px;
height: 385px;
}
p.inscription {
font-family: Homizio;
font-size: 29px;
color: #339900;
position: relative;
text-align: center;
left: 908px;
bottom: 808px;
width: 314px;
height: 385px;
}
img.Bambou {
position: relative;
bottom: 680px;
margin-left: auto;
margin-right: auto;
}
img.nouveau {
position: relative;
bottom: 1090px;
left: -600px;
opacity: 0.6;
}
p.actu {
font-family: Homizio;
font-weight: bold;
font-size: 28.5px;
color: #000000;
opacity: 0.6;
position: relative;
text-align: left;
bottom: 1100px;
right: -15px;
width: 661px;
height: 377px;
}
p.infos {
font-family: Homizio;
font-weight: bold;
font-size: 28.5px;
color: #339900;
position: relative;
bottom: 1600px;
left: 120px;
text-align: right;
}
p.plusinfos {
font-family: Homizio;
font-size: 29px;
color: #339900;
position: relative;
text-align: left;
right: -780px;
bottom: 1620px;
width: 559px;
height: 359px;
}
img.newlet {
width: 399px;
height: 68px;
position: relative;
bottom: 1750px;
right: -860px;
}
p.newletter {
width: 347px;
font-size: 24px;
font-family: Homizio;
height: 32px;
color: #000000;
position: relative;
bottom: 1821px;
left: 780px;
text-align: right;
}
img.images {
position: relative;
left: 150px;
right: 150px;
bottom: -50px;
}
</style>
</head>
<body>
<nav id="Menu">
Accueil
Forum
Contact
</nav>
<a href="file:///C:/Users/Ewan/Desktop/Travail%20Real%20Tea/Site%20entier.html#">
<img class="displayed" src="http://image.noelshack.com/fichiers/2015/17/1429658354-papierheaderfini.png" alt="jfl">
</a>
<div id="milieu">
<img class="images" src="http://image.noelshack.com/fichiers/2015/17/1429702366-thes.png" alt="tea" width="1050">
<p> </p>
<img class="images" src="http://image.noelshack.com/fichiers/2015/17/1429703603-news.png" alt="selection" width="1050">
<p class="newsletter">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi at libero in magna commodo sodales. Maecenas diam nisl, elementum ut quam nec, pharetra auctor neque. Suspendisse potenti. Mauris imperdiet purus vitae pulvinar malesuada. Aliquam sit amet ligula sit amet dui aliquam lobortis. Morbi pretium nisl non risus fringilla fringilla. Proin ac lobortis mauris.</p>
<p class="Communaute">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi at libero in magna commodo sodales. Maecenas diam nisl, elementum ut quam nec, pharetra auctor neque. Suspendisse potenti. Mauris imperdiet purus vitae pulvinar malesuada. Aliquam sit amet ligula sit amet dui aliquam lobortis. Morbi pretium nisl non risus fringilla fringilla. Proin ac lobortis mauris.</p>
<p class="inscription">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi at libero in magna commodo sodales. Maecenas diam nisl, elementum ut quam nec, pharetra auctor neque. Suspendisse potenti. Mauris imperdiet purus vitae pulvinar malesuada. Aliquam sit amet ligula sit amet dui aliquam lobortis. Morbi pretium nisl non risus fringilla fringilla. Proin ac lobortis mauris.</p>
<img class="Bambou" src="http://image.noelshack.com/fichiers/2015/17/1429706567-bambou.png" alt="lol">
<img class="nouveau" src="http://image.noelshack.com/fichiers/2015/17/1429707724-nouveau.png" alt="nouveautés">
<p class="actu">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur egestas rhoncus auctor. In sed porta nisl, sit amet vestibulum massa. Etiam vehicula, magna et elementum faucibus, leo nulla bibendum eros, nec interdum magna nibh et ipsum. Duis fermentum, augue varius efficitur tincidunt, lacus elit egestas ex, ultrices hendrerit diam velit quis elit. Integer a sem in tortor eleifend lobortis. Nam mauris libero, varius eget dignissim eu, tempor id elit. In justo elit, molestie eu augue ut, pharetra interdum ipsum. Aliquam tincidunt euismod sem id euismod. Donec dui dolor,</p>
<p class="infos"> Plus d'infos sur nous :</p>
<p class="plusinfos">Pellentesque cursus convallis risus, vitae venenatis nibh tristique at. Maecenas imperdiet varius urna et consectetur. Quisque viverra dolor arcu, eu viverra arcu aliquam ut. Nullam suscipit mi quis erat gravida aliquet. Aenean et rutrum leo. Nulla facilisi. Sed posuere.</p>
<img class="newlet" src="http://image.noelshack.com/fichiers/2015/17/1429709917-newsletter.png" alt="newlet">
<p class="newletter">Adresse mail :</p>
</div>
</body>
</html>
Your issue is with how all your elements are being positioned. For example the paragraph with class actu. It has a position: relative:
p.actu {
font-family: Homizio;
font-weight: bold;
font-size: 28.5px;
color: #000000;
opacity: 0.6;
position: relative; /* Issue */
text-align: left;
bottom: 1100px; /* Issue */
right: -15px; /* Issue */
width: 661px;
height: 377px;
}
Which actually means the element is still position "statically" on the page but you used bottom: 1100px and right: -15px to make it look like its visually not there. The browser will still recognize that the element is there along with all the element you visually moved. So if you look at the wrapper with id milieu its actual height is 3046px accounting for all the elements that's there just visually not.
The solution is as simple as removing all the position: relative, bottom, right, left, and top. Of course this will make your site look nothing like you intended. You need better practice on structuring your site.
It looks like you're using position: relative; to do things like placing images (using <img> tags) as backgrounds to some paragraphs of text. Trying to do things like that will just introduce problems.
You should use the built in functionality of HTML and CSS. A better way to do the background thing is to use the background CSS attribute on the <p> tag (or on a container element) and to avoid position: relative; completely.
For instance:
.my-text {
background: #ddd url('img/background.jpg') no-repeat;
padding: 10px;
}
<div class='my-text'>
<p>Lorem ipsum... some stuff...</p>
</div>
The real problem here is that there is no layout design on this webpage. The positions of the paragraphs are just hacked on there. I suggest going through some quick tutorials on HTML and CSS layouts. (Here is an example of one.)
I'm trying to overlay an icon on top of an element's border. My current solution involves absolute positioning. I can hack it to fit as close to center as possible by using something like left: 40% but as soon as I resize the window, it moves out of the center.
Here's a JSFiddle showing what I've got so far. You'll see that if you resize the window, the icon moves out of center. https://jsfiddle.net/83on2jr9/
Is there an easier approach to this?
You could use margin:0 auto; with position:absolute; - providing that you have some other values set:
.landing-section2 .landing-icon {
position: absolute;
top:-16px;
right:0;
bottom:0;
left:0;
width:50px;
height:50px;
margin:0 auto;
}
JSFiddle
You can use calc in the .landing-section2 .landing-icon class :
left: calc(50% - 32px);
JSFiddle
Use a CSS transform. This is responsive and works for any size element and doesn't require any magic number for widths and margins.
.landing-section2 .landing-icon {
color: #357ca3;
font-size: 3em;
background: #2c2c2c;
z-index: 1000;
position: absolute;
padding-left: 10px;
padding-right: 10px;
left: 50%;
top: 0;
transform:translate(-50%,-50%);
}
JSfiddle Demo
Support is IE9 and up CanIUse.com
I find that when using absolute positioning, it's easier to use it as included in the JSFiddle I updated below. Basically, I wrap the "icon" in a span and attain much greater control.
.landing-section2 .landing-icon {
color: #357ca3;
font-size: 3em;
z-index: 1000;
position: absolute;
top: -28px;
left: 0;
width: 100%;
text-align: center;
}
.landing-icon span {
display: inline-block;
padding: 8px;
background: #2c2c2c;
}
Here is the updated Fiddle with working code: https://jsfiddle.net/83on2jr9/7/
I think, put 'margin-left: -32px' is easy way to move it to center without changing many other options.
also, it moves dynamically.
you can use display and margin too without position :) https://jsfiddle.net/83on2jr9/10/
.landing-section2 {
padding: 50px;
background-color: #2c2c2c;
text-align: center;
}
.landing-section2 .col-sm-4 > div {
border: 1px solid #357ca3;
padding: 20px;
position: relative;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
margin-bottom:2em;
}
.landing-section2 h3 {
color: white;
margin-top: 30px;
}
.landing-section2 p {
color: #ccc;
}
.landing-section2 .landing-icon {
color: #357ca3;
font-size: 3em;
background: #2c2c2c;
display:table;
margin:-1em auto 0;
padding:0 5px;
}
<div class='landing-section2'>
<div class='container'>
<div class='row'>
<div class='col-sm-4 landing-section2-pillar'>
<div>
<div class='landing-icon'>#</div>
<h3>
Section 1
</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas nunc nulla, fringilla et auctor et, congue sit amet nibh. Aenean vel est ante. Suspendisse quis tortor laoreet ligula vehicula commodo. Morbi suscipit, neque id vulputate mollis, orci sapien aliquam sem, ac laoreet ex nisi id leo.</p>
</div>
</div>
<div class='col-sm-4 landing-section2-pillar'>
<div>
<div class='landing-icon'>#</div>
<h3>
Section 2
</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas nunc nulla, fringilla et auctor et, congue sit amet nibh. Aenean vel est ante. Suspendisse quis tortor laoreet ligula vehicula commodo. Morbi suscipit, neque id vulputate mollis, orci sapien aliquam sem, ac laoreet ex nisi id leo.</p>
</div>
</div>
<div class='col-sm-4 landing-section2-pillar'>
<div>
<div class='landing-icon'>#</div>
<h3>
Section 3
</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas nunc nulla, fringilla et auctor et, congue sit amet nibh. Aenean vel est ante. Suspendisse quis tortor laoreet ligula vehicula commodo. Morbi suscipit, neque id vulputate mollis, orci sapien aliquam sem, ac laoreet ex nisi id leo.</p>
</div>
</div>
</div>
</div>
</div>
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