Show scrollbar in an absolutely-positioned modal window - html

I've been trying to style an absolutely-positioned, reactive modal window that can pop up with a potentially large amount of content.
However, I can't seem to get the content part of the modal window to become vertically scroll-able. I've played around with all sorts of div layouts and overflow CSS settings, but can't figure out a way to get the result I need.
Specifically, I need ONLY the "modal-content" div of the modal window to be vertically scroll-able, and for the scrollbar NOT to extend up into the "modal-head" div. The modal-content div should also take up all available vertical space, while modal-head only takes up however much space is necessary for the title and button.
JSFiddle:
https://jsfiddle.net/xe7p5uzv/12/
HTML:
<div class="modal">
<div class="modal-head">
<h1>Modal Title</h1>
<button>Exit Modal Window</button>
</div>
<div class="modal-content">
Modal content here. Dapibus sagittis adipiscing at facilisis augue amet eleifend ipsum netus facilisi ullamcorper ligula tristique facilisi. Lacinia vestibulum a suspendisse a lorem mi vel erat condimentum consectetur enim elementum vehicula a porttitor lacus adipiscing sit potenti elementum adipiscing iaculis a vulputate at. Orci ullamcorper purus id sociis nibh mi sodales parturient enim a iaculis ridiculus a elementum consectetur primis scelerisque fusce vestibulum. Dictum dictumst tristique enim scelerisque libero consequat ornare nisl et ligula dignissim lorem vehicula nunc parturient. Praesent consequat nisi consectetur tempus et cras vestibulum a quisque nulla ullamcorper a suspendisse augue a suspendisse. Himenaeos mi ultricies mollis a vestibulum leo elit montes ad lobortis a malesuada leo eleifend. <br/><br/>
Suspendisse pretium scelerisque parturient nulla pharetra facilisi suspendisse orci sodales venenatis ipsum proin aenean nunc curabitur posuere curabitur netus dolor sociosqu lobortis pharetra adipiscing conubia. Mus sapien est leo cubilia parturient nunc lectus duis erat cubilia scelerisque praesent vulputate nam sodales eros congue condimentum ad a. Parturient consequat hac ad nisi natoque interdum eu convallis mi dignissim eu elementum tempor euismod congue sem ut adipiscing quis vestibulum a vitae ullamcorper tincidunt turpis parturient tellus suspendisse. Duis et mus nascetur parturient conubia in suscipit a dui malesuada nisi scelerisque sem mus vestibulum morbi. Commodo a elit porttitor a metus a mattis scelerisque porttitor ut tempus eros accumsan quis condimentum. Per consectetur etiam habitant enim ad massa ut condimentum urna iaculis conubia nisi et orci fames adipiscing lacinia in gravida dapibus dui. <br/>
</div>
</div>
<div>
Regular page content here. Malesuada ac nam curabitur ullamcorper dictumst varius neque a curae est a sed odio in eu ullamcorper aliquet faucibus dis turpis eros in laoreet malesuada sit non vitae. Dis orci iaculis mauris penatibus a fringilla in dis diam habitasse pharetra scelerisque vehicula netus. Eu non nascetur enim litora sem ad suscipit vel enim ad non consequat adipiscing ultrices senectus a a sodales tellus pretium. A fermentum ullamcorper a proin vestibulum suspendisse sed a purus a vestibulum a nostra condimentum consectetur. Fames at at nam a ultrices parturient adipiscing mus pretium consequat ornare ultrices ullamcorper condimentum vestibulum vestibulum a augue vestibulum sem urna laoreet fringilla inceptos.
</div>
CSS:
html {
font-size: 24px;
}
body {
margin: 0px;
padding: 12px;
}
.modal-bg {
z-index: 2;
width: 100vw;
height: 100vh;
background: rgba(0,0,0,0.8);
}
.modal {
z-index: 3;
position: absolute;
top: 48px;
right: 48px;
bottom: 48px;
left: 48px;
border: 4px solid red;
background-color: white;
overflow: hidden;
display: flex;
flex-wrap: wrap;
}
.modal-head {
background-color: grey;
width: 100%;
padding: 12px;
display: flex;
justify-content: space-between;
}
.modal-content {
width: 100%;
padding: 12px;
overflow-y: scroll;
}
Any ideas on how to accomplish this?

html {
font-size: 24px;
}
body {
margin: 0px;
padding: 12px;
}
h1{font-size: 14px}
.modal-bg {
z-index: 2;
width: 100vw;
height: 100vh;
background: rgba(0,0,0,0.8);
}
.modal {
z-index: 3;
position: absolute;
top: 48px;
right: 48px;
bottom: 48px;
left: 48px;
border: 4px solid red;
background-color: white;
display: flex;
flex-wrap: wrap;
overflow: hidden
}
.modal-head {
background-color: grey;
width: 100%;
padding: 12px;
display: flex;
justify-content: space-between;
}
.modal-content {
width: 100%;
padding: 12px;
overflow-y: scroll;
height: 100px
}
<div class="modal">
<div class="modal-head">
<h1>Modal Title</h1>
<button>Exit Modal Window</button>
</div>
<div class="modal-content">
Modal content here. Dapibus sagittis adipiscing at facilisis augue amet eleifend ipsum netus facilisi ullamcorper ligula tristique facilisi. Lacinia vestibulum a suspendisse a lorem mi vel erat condimentum consectetur enim elementum vehicula a porttitor lacus adipiscing sit potenti elementum adipiscing iaculis a vulputate at. Orci ullamcorper purus id sociis nibh mi sodales parturient enim a iaculis ridiculus a elementum consectetur primis scelerisque fusce vestibulum. Dictum dictumst tristique enim scelerisque libero consequat ornare nisl et ligula dignissim lorem vehicula nunc parturient. Praesent consequat nisi consectetur tempus et cras vestibulum a quisque nulla ullamcorper a suspendisse augue a suspendisse. Himenaeos mi ultricies mollis a vestibulum leo elit montes ad lobortis a malesuada leo eleifend. <br/><br/>
Suspendisse pretium scelerisque parturient nulla pharetra facilisi suspendisse orci sodales venenatis ipsum proin aenean nunc curabitur posuere curabitur netus dolor sociosqu lobortis pharetra adipiscing conubia. Mus sapien est leo cubilia parturient nunc lectus duis erat cubilia scelerisque praesent vulputate nam sodales eros congue condimentum ad a. Parturient consequat hac ad nisi natoque interdum eu convallis mi dignissim eu elementum tempor euismod congue sem ut adipiscing quis vestibulum a vitae ullamcorper tincidunt turpis parturient tellus suspendisse. Duis et mus nascetur parturient conubia in suscipit a dui malesuada nisi scelerisque sem mus vestibulum morbi. Commodo a elit porttitor a metus a mattis scelerisque porttitor ut tempus eros accumsan quis condimentum. Per consectetur etiam habitant enim ad massa ut condimentum urna iaculis conubia nisi et orci fames adipiscing lacinia in gravida dapibus dui. <br/>
</div>
</div>

Related

Flex-wrap positioning really weirdly when wrapping

I've been trying to make a website with an image and a div next to each other, and make them responsive so it goes under the div when the screen size changes. It's been working so far, but whenever the image goes under the div, the size changes drastically and gets really weird.
Here's the code used
body{
margin: 0;
font-family: HebrewRegular;
background-color: white;
}
#font-face {
font-family: HebrewRegular;
src: url("Adobe Hebrew Regular.otf") format("opentype");
font-weight: bold;
}
.top-container{
background-color: white;
background-image: url("https://picsum.photos/400/200");
padding: 170px;
text-align: center;
background-position: center;
background-repeat: no-repeat;
background-size:contain;
position: relative;
max-width: 100%;
}
.menuBar{
background-color: rgb(168, 123, 81);
padding: 30px 40px;
text-align: left;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
.sticky + .content {
padding-top: 102px;
}
.flex-container {
display: flex;
flex-wrap: wrap;
}
.flex1 {
background-color:rgba(230,199,177,255);
width: 50%;
margin: 10px;
text-align: center;
font-size: 15px;
line-height: 25px;
}
.flex2 {
background-image: url("https://picsum.photos/400/200");
background-size:contain;
background-repeat: no-repeat;
width: 600px;
margin: 10px;
text-align: center;
margin-top: 100px;
}
<body>
<div class = "top-container"></div>
<div class = "menuBar" id = "menuBar"> MenuBar</div>
<div class = "mainContent">
<div class="flex-container">
<div class = "flex1">
<h3> Welcome to Charm Thai Restaurant Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ultrices ligula quis nibh dignissim interdum. Proin consequat sem et lacus accumsan aliquam. Vestibulum sodales pretium ex at cursus. Maecenas efficitur finibus dictum. Duis nec quam ultrices, laoreet magna vel, auctor nunc. Sed ultricies lacus consequat velit lacinia, in consequat sapien pretium. Vestibulum sagittis ornare odio at elementum.
Vestibulum sodales mauris ut tempor posuere. Nulla orci dolor, porta sed risus viverra, consectetur hendrerit sapien. Phasellus tristique ante augue, id efficitur nisi placerat nec. Nam rhoncus erat quis feugiat sollicitudin. Mauris id magna sit amet risus bibendum pretium. Donec in mauris mi. Morbi dignissim porttitor iaculis. Praesent mollis placerat velit, et blandit nibh venenatis nec. Fusce ut ultrices sem. Nunc eget lectus quis mauris dignissim tempor id placerat tellus. Nam vitae semper augue.
Quisque rutrum laoreet urna eget posuere. Nulla cursus tincidunt elit et placerat. Duis sed pellentesque magna, non lacinia tortor. Nam nisl dui, rutrum et sollicitudin quis, condimentum quis augue. Aenean varius, nisi at luctus dapibus, diam magna dictum ex, ac sodales ex ex sit amet ligula. Donec pulvinar varius est. Nam vitae rutrum dolor. Donec lacinia, ex nec tempus venenatis, ligula justo dapibus diam, cursus semper augue mauris ac odio. Aliquam a arcu nec lacus rhoncus facilisis. Vestibulum sollicitudin lorem id metus auctor, sit amet ullamcorper mauris fringilla.
In in erat eu eros volutpat bibendum sit amet fermentum enim. Vestibulum dictum orci sed tincidunt posuere. Donec viverra nunc ut sem viverra, et vestibulum mauris feugiat. Donec imperdiet quam dui, vitae vehicula ipsum hendrerit non. Phasellus nec augue eu erat posuere varius in quis odio. Nunc justo turpis, scelerisque non leo vel, laoreet ornare neque. Donec a neque ac nibh ultricies tristique id vel magna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque viverra ante in magna fringilla, vel sodales lectus feugiat. Donec sodales, odio eget dictum scelerisque, urna massa fringilla quam, nec pharetra erat dui at massa. Maecenas suscipit velit id scelerisque consectetur. Praesent ac egestas enim. Vestibulum nulla turpis, hendrerit nec sodales vitae, congue at felis. Cras auctor ac quam sed fermentum. Quisque libero est, aliquam ac lorem a, semper molestie mi. Cras suscipit eu erat eget hendrerit.
</h3>
</div>
<div class = "flex2">2</div>
</div>
</body>
<script src="index.js"></script>
<!-- rgb(255, 209, 218); -->
Define a height or min-height to the image container. I also used flex instead of width to have a better result on wrap
body {
margin: 0;
font-family: HebrewRegular;
background-color: white;
}
.top-container {
background-color: white;
background-image: url("https://picsum.photos/400/200");
padding: 170px;
text-align: center;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
position: relative;
}
.menuBar {
background-color: rgb(168, 123, 81);
padding: 30px 40px;
text-align: left;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
.sticky+.content {
padding-top: 102px;
}
.flex-container {
display: flex;
flex-wrap: wrap;
}
.flex-container > * {
flex:300px; /* added this */
}
.flex1 {
background-color: rgba(230, 199, 177, 255);
margin: 10px;
text-align: center;
font-size: 15px;
line-height: 25px;
}
.flex2 {
background-image: url("https://picsum.photos/400/200");
background-size: contain;
background-repeat: no-repeat;
min-height: 300px; /* added this */
margin: 10px;
text-align: center;
}
<div class="top-container"></div>
<div class="menuBar" id="menuBar"> MenuBar</div>
<div class="mainContent">
<div class="flex-container">
<div class="flex1">
<h3> Welcome to Charm Thai Restaurant Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ultrices ligula quis nibh dignissim interdum. Proin consequat sem et lacus accumsan aliquam. Vestibulum sodales pretium ex at cursus. Maecenas efficitur
finibus dictum. Duis nec quam ultrices, laoreet magna vel, auctor nunc. Sed ultricies lacus consequat velit lacinia, in consequat sapien pretium. Vestibulum sagittis ornare odio at elementum. Vestibulum sodales mauris ut tempor posuere. Nulla
orci dolor, porta sed risus viverra, consectetur hendrerit sapien. Phasellus tristique ante augue, id efficitur nisi placerat nec. Nam rhoncus erat quis feugiat sollicitudin. Mauris id magna sit amet risus bibendum pretium. Donec in mauris mi.
Morbi dignissim porttitor iaculis. Praesent mollis placerat velit, et blandit nibh venenatis nec. Fusce ut ultrices sem. Nunc eget lectus quis mauris dignissim tempor id placerat tellus. Nam vitae semper augue. Quisque rutrum laoreet urna eget
posuere. Nulla cursus tincidunt elit et placerat. Duis sed pellentesque magna, non lacinia tortor. Nam nisl dui, rutrum et sollicitudin quis, condimentum quis augue. Aenean varius, nisi at luctus dapibus, diam magna dictum ex, ac sodales ex ex
sit amet ligula. Donec pulvinar varius est. Nam vitae rutrum dolor. Donec lacinia, ex nec tempus venenatis, ligula justo dapibus diam, cursus semper augue mauris ac odio. Aliquam a arcu nec lacus rhoncus facilisis. Vestibulum sollicitudin lorem
id metus auctor, sit amet ullamcorper mauris fringilla. In in erat eu eros volutpat bibendum sit amet fermentum enim. Vestibulum dictum orci sed tincidunt posuere. Donec viverra nunc ut sem viverra, et vestibulum mauris feugiat. Donec imperdiet
quam dui, vitae vehicula ipsum hendrerit non. Phasellus nec augue eu erat posuere varius in quis odio. Nunc justo turpis, scelerisque non leo vel, laoreet ornare neque. Donec a neque ac nibh ultricies tristique id vel magna. Orci varius natoque
penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque viverra ante in magna fringilla, vel sodales lectus feugiat. Donec sodales, odio eget dictum scelerisque, urna massa fringilla quam, nec pharetra erat dui at massa. Maecenas
suscipit velit id scelerisque consectetur. Praesent ac egestas enim. Vestibulum nulla turpis, hendrerit nec sodales vitae, congue at felis. Cras auctor ac quam sed fermentum. Quisque libero est, aliquam ac lorem a, semper molestie mi. Cras suscipit
eu erat eget hendrerit.
</h3>
</div>
<div class="flex2">2</div>
</div>
the problem is the height of your element,
by default all html elements get height:auto; and it means take as much as your children need
so your second box has nothing but a '2' inside of it, that's why it only gets 18px height!
if this is true, then how it is working fine on wider devices?
That's flexbox's magic!
by default the align-items property of flex has stretch value, which means if the flex item has no explicit height, it should stretch and fill the parent's height, your first item has some text in it, right? so first item grows as much as necessary for his text and this causes your flexbox to grow up and wrap the children inside of it and align-items property forces your second box to grow and get the height, so it will get enough height to be visible on larger devices...
how to fix this??
you can use min-height or max-height or both!
or
you can use #media for smaller devices and set height for your second element to make it bigger
or
you can use an img tag instead of background and set specific height for it and use object-fit to maintain your image's aspect ratio
or
you can use padding or <br /> to make your second division big enough to make it's background visible
currently these are all options I can think of, if any better solution came to my mind, I'll let you know

position sticky is not working after setting float left of other elements

header position sticky is not working after adding float:left on the other element. The position sticky is working if I remove the float:left from main>div. I searched it on google but I didn't find any solution for this. Here is the code
<!doctype html>
<html lang="en">
<head>
<style>
.header {
height: 100px;
position: sticky;
top: 0;
width: 100%;
background-color: pink;
}
main>div {
float: left;
/*If I don't use it, the sticky header works*/
height: 1500px
}
.first {
background: linear-gradient(to top, red, yellow);
width: 300px;
top: 0;
}
.second {
background: linear-gradient(to top, khaki, gray);
width: calc(100% - 600px);
}
.third {
background: linear-gradient(to top, tomato, green);
width: 300px;
}
</style>
</head>
<body>
<header class="header">
sticky header
</header>
<main>
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
</main>
</body>
</html>
Check the same code on Jsfiddle https://jsfiddle.net/habibulislam6862/53yv1rzw/2/
if you start a "float" you also have to clear it
try adding below line after
<div style="clear:both;"></div>
So final code will be as below; Feel free to externalize style into a class
<header class="header">
sticky header
</header>
<main>
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
</main>
<div style="clear:both;"></div>
you can also use a sudo element (like "after" in css) to do the same https://www.w3schools.com/cssref/sel_after.asp
If this is for a layout, you might want to include the -x-sticky for browser compatibility and have your column in percentages to make them responsive.
Example, run code snippet below:
body{
box-sizing: border-box;
padding: 0;
margin: 0;
}
header {
height: 60px;
width: 100%;
background-color: pink;
position: -webkit-sticky;
position: -ms-sticky;
position: -moz-sticky;
position: -o-sticky;
position: sticky;
top: 0px;
z-index: 1;
}
main {
display: flex;
width: 100%;
height: 1500px;
}
.first {
background: linear-gradient(to top, red, yellow);
min-width: 20%;
}
.second {
background: linear-gradient(to top, khaki, gray);
flex-grow: 1;
}
.third {
background: linear-gradient(to top, tomato, green);
min-width: 20%;
}
<header>
sticky header
</header>
<main>
<div class="first"></div>
<div class="second"><p>Lorem ipsum dolor sit amet consectetur adipiscing elit, vitae tincidunt nascetur donec porttitor aenean et nunc, ut dictum inceptos facilisis commodo cum. Duis magnis parturient sollicitudin diam augue placerat imperdiet neque, euismod cum nostra erat lacus et conubia, facilisi pellentesque molestie risus mus dapibus vel. Malesuada vestibulum habitasse class sodales viverra mauris fermentum tortor massa bibendum augue libero, euismod montes sed dis magna vel leo praesent mattis platea eleifend. Neque commodo maecenas odio curae cubilia potenti habitant congue porttitor, integer libero mattis nisl sed mauris donec litora magnis, nulla dignissim platea hac dui varius tellus tincidunt.</p> <p>Dignissim proin arcu magna vitae id nam volutpat natoque semper sem, aliquet erat aliquam sociosqu scelerisque eget urna mollis sagittis. Posuere arcu sociosqu mi ad lacinia vitae ac nascetur tempor pharetra aptent fringilla, turpis sodales himenaeos malesuada mattis nisl diam sapien quisque cum. Enim dictum etiam mollis egestas et magna blandit dignissim, ullamcorper parturient odio suspendisse curabitur habitasse dui facilisi, laoreet ridiculus est ad vehicula curae nullam.</p> <p>Facilisis odio mauris consequat mattis faucibus aliquam eu semper condimentum, imperdiet natoque magna leo malesuada lacinia posuere placerat tellus, suscipit dapibus pharetra porta eros diam feugiat dictum. Suscipit euismod fermentum interdum bibendum nullam porttitor, pharetra dis mollis vivamus leo elementum commodo, facilisi rhoncus aptent ligula maecenas. Sodales pellentesque purus parturient mollis mauris tellus id vehicula, velit ac quam sociosqu molestie sollicitudin neque eleifend, mus porttitor aenean penatibus libero fringilla sagittis.</p> <p>Phasellus ornare eros per nam sollicitudin taciti himenaeos, senectus auctor fusce varius magna hendrerit. Urna proin lacus conubia tortor venenatis mauris nec facilisi, fringilla arcu non accumsan pellentesque neque ut dictum euismod, curae tempor eu felis habitasse mi dui. Viverra vehicula ultrices etiam maecenas fusce pulvinar dis sem litora, luctus molestie suscipit tristique imperdiet gravida pretium augue, vel velit nibh hac mus nam consequat eros.</p> <p>Metus feugiat nisl felis fames condimentum facilisi posuere tempus ultricies scelerisque porttitor aptent, justo tempor magnis ultrices phasellus cras nascetur interdum augue aenean iaculis. Lacinia diam lectus lacus facilisis nisl accumsan magna curae nullam placerat bibendum dictum, vehicula dui integer non viverra iaculis interdum vitae at suscipit egestas. Ac aptent fermentum netus eros vulputate phasellus iaculis, cum inceptos velit suspendisse morbi viverra, ante fringilla faucibus donec placerat nullam. Aliquam diam integer vivamus ligula nam cras cursus tristique libero, mattis nisi vestibulum litora enim suspendisse inceptos fames facilisi, erat penatibus ridiculus taciti duis bibendum tortor ornare.</p> <p>Lectus dui sagittis et nascetur nec hendrerit convallis, dapibus curabitur fermentum varius scelerisque nullam platea, metus elementum mattis id semper dignissim. Ridiculus habitasse at sociosqu gravida dui metus velit aptent praesent, dapibus purus egestas et diam nisi pulvinar porttitor, ullamcorper hac integer cubilia sagittis lobortis justo tristique. Penatibus diam convallis velit sapien, ornare nascetur morbi laoreet vulputate, vitae lectus potenti.</p> <p>Egestas nostra mus montes suscipit morbi mattis vestibulum, sapien penatibus laoreet luctus eu feugiat. Integer a fringilla aenean quisque diam nostra, nisl volutpat commodo augue gravida massa, praesent elementum pulvinar curabitur proin.</p></div>
<div class="third"></div>
</main>

How to reorder my elements and/or float text around the image?

I have been given the following markup that cannot change.
<div class="container">
<div class="image">
<img src="some image"/>
</div>
<h3>Some Header the is in the wrong place</h3>
<p class="blurbThing"></p>
<div class="description">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean porttitor massa sed nisi eleifend, a molestie felis convallis. Curabitur luctus orci eget rhoncus eleifend. Vestibulum dui odio, feugiat non commodo vitae, luctus a nisl. Aliquam tempor nibh
ac ante ullamcorper egestas. In ut risus quis elit ullamcorper sollicitudin in vel ante. Phasellus id magna sed erat elementum iaculis non sed dolor. Aliquam erat volutpat. Curabitur quis lectus mauris. Vivamus dictum libero nulla, vel egestas libero
dictum ut. Maecenas aliquam lectus vitae arcu lacinia, sed aliquet erat porttitor. Maecenas maximus nunc vel nulla dictum finibus.
</p>
<p>
Aliquam erat volutpat. Donec quam mi, condimentum at dolor sodales, facilisis mollis lacus. Nulla condimentum sagittis elit quis mollis. Vestibulum ultrices, risus eu sagittis tristique, purus augue egestas erat, eget auctor massa augue vitae mauris.
Nulla at lacinia justo. Aenean nec arcu euismod, condimentum lectus vitae, rhoncus nisi. Fusce lorem tortor, tincidunt sed interdum eu, euismod ut purus.
</p>
<p>
Donec ultrices eleifend pulvinar. Donec accumsan felis vel nunc porta pretium. Aenean tellus velit, ultrices quis viverra eget, vehicula vel odio. Ut nec iaculis dolor, eu aliquam felis. Proin quis maximus metus. Phasellus tincidunt tristique pulvinar.
Nunc tincidunt aliquet tincidunt.
</p>
<p>
Nullam ac consequat lorem. Praesent rhoncus consequat arcu ut tempus. Sed non mi fringilla, aliquet lectus in, sagittis dolor. Integer eu lacus consectetur, fringilla eros quis, blandit tellus. Quisque eu arcu dui. Integer finibus varius ultricies. Nulla
vitae metus in velit suscipit cursus. Vestibulum ornare ac diam quis semper. Ut nunc massa, commodo ac lorem ut, faucibus tincidunt nulla. Proin sed urna eget diam ultricies consectetur ac eu tortor.
</p>
<p>
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam erat volutpat. Nunc lobortis feugiat laoreet. Maecenas ligula nulla, ornare hendrerit tempus id, venenatis vitae lacus. Cras cursus a nulla ac dapibus. Class
aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Quisque et lacinia est. Sed quam orci, luctus eu eros et, congue bibendum ipsum. Nunc non sodales est.
</p>
</div>
<hr class="clear">
</div>
So the goal is to get the html to render as per the following snippet:
.container {
max-width: 700px;
background-color: white;
border-radius: 5px;
padding: 15px;
text-align: left;
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.5);
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.5);
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.5);
}
.container > .image {
max-width: 40%;
min-width: 40%;
min-height: 100px;
float:right;
}
.container > .description {
max-width: 100%;
text-align: left;
}
.container > .description > * {
padding-right: 15px;
}
.container > .description > p {
margin-bottom: 8px;
}
.container > h3 {
width: 100%;
text-align: left;
font-weight: 600;
font-size: 20px;
}
.container > hr {
display: none;
}
.container > .image > img{
object-fit: cover;
object-position: center center;
max-width: 100%;
}
<div class="container">
<h3>Some Header the is in the wrong place</h3>
<div class="image">
<img src="some image"/>
</div>
<p class="blurbThing"></p>
<div class="description">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean porttitor massa sed nisi eleifend, a molestie felis convallis. Curabitur luctus orci eget rhoncus eleifend. Vestibulum dui odio, feugiat non commodo vitae, luctus a nisl. Aliquam tempor nibh
ac ante ullamcorper egestas. In ut risus quis elit ullamcorper sollicitudin in vel ante. Phasellus id magna sed erat elementum iaculis non sed dolor. Aliquam erat volutpat. Curabitur quis lectus mauris. Vivamus dictum libero nulla, vel egestas libero
dictum ut. Maecenas aliquam lectus vitae arcu lacinia, sed aliquet erat porttitor. Maecenas maximus nunc vel nulla dictum finibus.
</p>
<p>
Aliquam erat volutpat. Donec quam mi, condimentum at dolor sodales, facilisis mollis lacus. Nulla condimentum sagittis elit quis mollis. Vestibulum ultrices, risus eu sagittis tristique, purus augue egestas erat, eget auctor massa augue vitae mauris.
Nulla at lacinia justo. Aenean nec arcu euismod, condimentum lectus vitae, rhoncus nisi. Fusce lorem tortor, tincidunt sed interdum eu, euismod ut purus.
</p>
<p>
Donec ultrices eleifend pulvinar. Donec accumsan felis vel nunc porta pretium. Aenean tellus velit, ultrices quis viverra eget, vehicula vel odio. Ut nec iaculis dolor, eu aliquam felis. Proin quis maximus metus. Phasellus tincidunt tristique pulvinar.
Nunc tincidunt aliquet tincidunt.
</p>
<p>
Nullam ac consequat lorem. Praesent rhoncus consequat arcu ut tempus. Sed non mi fringilla, aliquet lectus in, sagittis dolor. Integer eu lacus consectetur, fringilla eros quis, blandit tellus. Quisque eu arcu dui. Integer finibus varius ultricies. Nulla
vitae metus in velit suscipit cursus. Vestibulum ornare ac diam quis semper. Ut nunc massa, commodo ac lorem ut, faucibus tincidunt nulla. Proin sed urna eget diam ultricies consectetur ac eu tortor.
</p>
<p>
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam erat volutpat. Nunc lobortis feugiat laoreet. Maecenas ligula nulla, ornare hendrerit tempus id, venenatis vitae lacus. Cras cursus a nulla ac dapibus. Class
aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Quisque et lacinia est. Sed quam orci, luctus eu eros et, congue bibendum ipsum. Nunc non sodales est.
</p>
</div>
<hr class="clear">
</div>
Note in the above snippet I have moved the <h3> tag to the top inside the container and everything is fine and dandy. However I cannot change this in my scenario.
I can use jQuery/JavaScript to do it, but I really don't want to, and would like to use CSS only.
I have tried using a flexbox approach to get it to re order but then I cannot get the text to wrap around the bottom of the image, e.g.
.container {
max-width: 700px;
background-color: white;
border-radius: 5px;
padding: 15px;
text-align: left;
display: flex;
flex-direction: row;
flex-wrap: wrap;
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.5);
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.5);
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.5);
}
.container > .image {
max-width: 40%;
min-width: 40%;
min-height: 100px;
order: 4;
}
.container > .specials-info {
order: 2;
}
.container > .description {
max-width: 60%;
text-align: left;
order: 3;
}
.container > .description > * {
padding-right: 15px;
}
.container > .description > p {
margin-bottom: 8px;
}
.container > h3 {
width: 100%;
text-align: left;
font-weight: 600;
font-size: 20px;
order: 1;
}
.container > hr {
display: none;
}
.container > .image > img{
object-fit: cover;
object-position: center center;
max-width: 100%;
}
<div class="container">
<div class="image">
<img src="some image"/>
</div>
<h3>Some Header the is in the wrong place</h3>
<p class="blurbThing"></p>
<div class="description">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean porttitor massa sed nisi eleifend, a molestie felis convallis. Curabitur luctus orci eget rhoncus eleifend. Vestibulum dui odio, feugiat non commodo vitae, luctus a nisl. Aliquam tempor nibh
ac ante ullamcorper egestas. In ut risus quis elit ullamcorper sollicitudin in vel ante. Phasellus id magna sed erat elementum iaculis non sed dolor. Aliquam erat volutpat. Curabitur quis lectus mauris. Vivamus dictum libero nulla, vel egestas libero
dictum ut. Maecenas aliquam lectus vitae arcu lacinia, sed aliquet erat porttitor. Maecenas maximus nunc vel nulla dictum finibus.
</p>
<p>
Aliquam erat volutpat. Donec quam mi, condimentum at dolor sodales, facilisis mollis lacus. Nulla condimentum sagittis elit quis mollis. Vestibulum ultrices, risus eu sagittis tristique, purus augue egestas erat, eget auctor massa augue vitae mauris.
Nulla at lacinia justo. Aenean nec arcu euismod, condimentum lectus vitae, rhoncus nisi. Fusce lorem tortor, tincidunt sed interdum eu, euismod ut purus.
</p>
<p>
Donec ultrices eleifend pulvinar. Donec accumsan felis vel nunc porta pretium. Aenean tellus velit, ultrices quis viverra eget, vehicula vel odio. Ut nec iaculis dolor, eu aliquam felis. Proin quis maximus metus. Phasellus tincidunt tristique pulvinar.
Nunc tincidunt aliquet tincidunt.
</p>
<p>
Nullam ac consequat lorem. Praesent rhoncus consequat arcu ut tempus. Sed non mi fringilla, aliquet lectus in, sagittis dolor. Integer eu lacus consectetur, fringilla eros quis, blandit tellus. Quisque eu arcu dui. Integer finibus varius ultricies. Nulla
vitae metus in velit suscipit cursus. Vestibulum ornare ac diam quis semper. Ut nunc massa, commodo ac lorem ut, faucibus tincidunt nulla. Proin sed urna eget diam ultricies consectetur ac eu tortor.
</p>
<p>
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam erat volutpat. Nunc lobortis feugiat laoreet. Maecenas ligula nulla, ornare hendrerit tempus id, venenatis vitae lacus. Cras cursus a nulla ac dapibus. Class
aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Quisque et lacinia est. Sed quam orci, luctus eu eros et, congue bibendum ipsum. Nunc non sodales est.
</p>
</div>
<hr class="clear">
</div>
In summary is there a way to achieve Snippet 1 with out altering the original HTML and without using JavaScript?
Edit 1
Just to clarify a bit in the image below on the left is Snippet 1. It is what I want to end up with (but the markup is different in that the <h3> tag is higher). On the right is Snippet 2, as close as I can get without editing the markup (which I cannot do) / using JavaScript (I can do but would rather use CSS only).
Note that I have used a flexbox to reorder the items, but at that point I cannot use a float on the image container.
Edit 2
A bit more clarification(apologies)
The header(h3) must sit at the top and take 100% of the width. (no wrapping by just padding the image down).
The Image will be 45% of the width but will change in height depending on diffent use cases.
The Content of description will be x no of p tags with varying content.
You can achieve this pretty easily with just using the float property on the image container and some margin-top. I won't go through line-by-line with what CSS properties I've changed, but here is a JSFiddle that doesn't change your HTML and achieves the layout you want. It has the added benefit of far fewer lines of CSS than using flex.
Note: Since I don't know what size your image actually is, I chose an explicit size based on your what your image looked like.
.container {
max-width: 700px;
background-color: white;
border-radius: 5px;
padding: 15px;
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.5);
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.5);
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.5);
}
.container .image {
margin-top: 70px;
}
.container > .image {
float: right;
width: 300px; /* just an example size */
height: 150px; /* just an example size */
background: grey; /* This is just to show you where the image would be */
}
.container > .description > * {
padding-right: 15px;
}
.container > .description > p {
margin-bottom: 8px;
}
.container > h3 {
width: 100%;
font-weight: 600;
font-size: 20px;
white-space: nowrap;
}
<div class="container">
<div class="image">
<img src="some image"/>
</div>
<h3>Some Header the is in the wrong place</h3>
<p class="blurbThing"></p>
<div class="description">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean porttitor massa sed nisi eleifend, a molestie felis convallis. Curabitur luctus orci eget rhoncus eleifend. Vestibulum dui odio, feugiat non commodo vitae, luctus a nisl. Aliquam tempor nibh
ac ante ullamcorper egestas. In ut risus quis elit ullamcorper sollicitudin in vel ante. Phasellus id magna sed erat elementum iaculis non sed dolor. Aliquam erat volutpat. Curabitur quis lectus mauris. Vivamus dictum libero nulla, vel egestas libero
dictum ut. Maecenas aliquam lectus vitae arcu lacinia, sed aliquet erat porttitor. Maecenas maximus nunc vel nulla dictum finibus.
</p>
<p>
Aliquam erat volutpat. Donec quam mi, condimentum at dolor sodales, facilisis mollis lacus. Nulla condimentum sagittis elit quis mollis. Vestibulum ultrices, risus eu sagittis tristique, purus augue egestas erat, eget auctor massa augue vitae mauris.
Nulla at lacinia justo. Aenean nec arcu euismod, condimentum lectus vitae, rhoncus nisi. Fusce lorem tortor, tincidunt sed interdum eu, euismod ut purus.
</p>
<p>
Donec ultrices eleifend pulvinar. Donec accumsan felis vel nunc porta pretium. Aenean tellus velit, ultrices quis viverra eget, vehicula vel odio. Ut nec iaculis dolor, eu aliquam felis. Proin quis maximus metus. Phasellus tincidunt tristique pulvinar.
Nunc tincidunt aliquet tincidunt.
</p>
<p>
Nullam ac consequat lorem. Praesent rhoncus consequat arcu ut tempus. Sed non mi fringilla, aliquet lectus in, sagittis dolor. Integer eu lacus consectetur, fringilla eros quis, blandit tellus. Quisque eu arcu dui. Integer finibus varius ultricies. Nulla
vitae metus in velit suscipit cursus. Vestibulum ornare ac diam quis semper. Ut nunc massa, commodo ac lorem ut, faucibus tincidunt nulla. Proin sed urna eget diam ultricies consectetur ac eu tortor.
</p>
<p>
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam erat volutpat. Nunc lobortis feugiat laoreet. Maecenas ligula nulla, ornare hendrerit tempus id, venenatis vitae lacus. Cras cursus a nulla ac dapibus. Class
aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Quisque et lacinia est. Sed quam orci, luctus eu eros et, congue bibendum ipsum. Nunc non sodales est.
</p>
</div>
<hr class="clear">
</div>
Used some CSS hacks to achieve the first layout in Flexbox.
Flexbox does not allow wrapping of text around the images, since it takes its own row or column.
Give the parent container position: relative and the child item image position: absolute and align with the top and left values.
You can adjust the width from the 2nd paragraph to last to occupy 100% width.
.container {
background-color: white;
border-radius: 5px;
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.5);
display: flex;
flex-flow: row wrap;
max-width: 700px;
padding: 15px;
position: relative;
text-align: left;
}
.container > .image {
max-width: 40%;
min-height: 100px;
min-width: 40%;
order: 4;
position: absolute;
right: 0;
top: 100px;
}
.container > .specials-info {
order: 2;
}
.container > .description {
order: 3;
text-align: left;
}
.container > .description > * {
padding-right: 15px;
}
.container > .description > p {
margin-bottom: 8px;
}
.container > h3 {
font-size: 20px;
font-weight: 600;
order: 1;
text-align: left;
width: 100%;
}
.container > hr {
display: none;
}
.container > .image > img {
max-width: 100%;
object-fit: cover;
object-position: center center;
}
.description > p:not(:first-child) {
width: 100%;
}
.description > p:first-child {
max-width: 60%;
}
<div class="container">
<div class="image">
<img src="http://placehold.it/200x200" />
</div>
<h3>Some Header the is in the wrong place</h3>
<p class="blurbThing"></p>
<div class="description">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean porttitor massa sed nisi eleifend, a molestie felis convallis. Curabitur luctus orci eget rhoncus eleifend. Vestibulum dui odio, feugiat non commodo vitae, luctus a nisl. Aliquam tempor nibh
ac ante ullamcorper egestas. In ut risus quis elit ullamcorper sollicitudin in vel ante. Phasellus id magna sed erat elementum iaculis non sed dolor. Aliquam erat volutpat. Curabitur quis lectus mauris. Vivamus dictum libero nulla, vel egestas libero
dictum ut. Maecenas aliquam lectus vitae arcu lacinia, sed aliquet erat porttitor. Maecenas maximus nunc vel nulla dictum finibus.
</p>
<p>
Aliquam erat volutpat. Donec quam mi, condimentum at dolor sodales, facilisis mollis lacus. Nulla condimentum sagittis elit quis mollis. Vestibulum ultrices, risus eu sagittis tristique, purus augue egestas erat, eget auctor massa augue vitae mauris.
Nulla at lacinia justo. Aenean nec arcu euismod, condimentum lectus vitae, rhoncus nisi. Fusce lorem tortor, tincidunt sed interdum eu, euismod ut purus.
</p>
<p>
Donec ultrices eleifend pulvinar. Donec accumsan felis vel nunc porta pretium. Aenean tellus velit, ultrices quis viverra eget, vehicula vel odio. Ut nec iaculis dolor, eu aliquam felis. Proin quis maximus metus. Phasellus tincidunt tristique pulvinar.
Nunc tincidunt aliquet tincidunt.
</p>
<p>
Nullam ac consequat lorem. Praesent rhoncus consequat arcu ut tempus. Sed non mi fringilla, aliquet lectus in, sagittis dolor. Integer eu lacus consectetur, fringilla eros quis, blandit tellus. Quisque eu arcu dui. Integer finibus varius ultricies. Nulla
vitae metus in velit suscipit cursus. Vestibulum ornare ac diam quis semper. Ut nunc massa, commodo ac lorem ut, faucibus tincidunt nulla. Proin sed urna eget diam ultricies consectetur ac eu tortor.
</p>
<p>
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam erat volutpat. Nunc lobortis feugiat laoreet. Maecenas ligula nulla, ornare hendrerit tempus id, venenatis vitae lacus. Cras cursus a nulla ac dapibus. Class
aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Quisque et lacinia est. Sed quam orci, luctus eu eros et, congue bibendum ipsum. Nunc non sodales est.
</p>
</div>
<hr class="clear">
</div>
Use this margin-top for .image class in snippet1
.container > .image {
max-width: 40%;
min-width: 40%;
min-height: 100px;
float:right;
margin-top:72px;
}

CSS: centered content, left aligned background image

i need to implement the following layout:
the content wrapper has a fixed size and will be centered:
.content
{
width:960px;
margin:0px auto;
}
the problem is, how to implement the left-aligned background bar from the sub-navigation (see arrow)?
i dont want to use javascript + onresize or something.
any ideas?
thanks
my markup looks like
a standard page layout
<div class="wrapper">
<header class="header">
<strong>Header:</strong> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tortor. Praesent dictum, libero ut tempus dictum, neque eros elementum mauris, quis mollis arcu velit ac diam. Etiam neque. Quisque nec turpis. Aliquam arcu nulla, dictum et, lacinia a, mollis in, ante. Sed eu felis in elit tempor venenatis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut ultricies porttitor purus. Proin non tellus at ligula fringilla tristique. Fusce vehicula quam. Curabitur vel tortor vitae pede imperdiet ultrices. Sed tortor.
</header><!-- .header-->
<main class="content">
<strong>Content:</strong> Sed placerat accumsan ligula. Aliquam felis magna, congue quis, tempus eu, aliquam vitae, ante. Cras neque justo, ultrices at, rhoncus a, facilisis eget, nisl. Quisque vitae pede. Nam et augue. Sed a elit. Ut vel massa. Suspendisse nibh pede, ultrices vitae, ultrices nec, mollis non, nibh. In sit amet pede quis leo vulputate hendrerit. Cras laoreet leo et justo auctor condimentum. Integer id enim. Suspendisse egestas, dui ac egestas mollis, libero orci hendrerit lacus, et malesuada lorem neque ac libero. Morbi tempor pulvinar pede. Donec vel elit.
</main><!-- .content -->
<footer class="footer">
<strong>Footer:</strong> Mus elit Morbi mus enim lacus at quis Nam eget morbi. Et semper urna urna non at cursus dolor vestibulum neque enim. Tellus interdum at laoreet laoreet lacinia lacinia sed Quisque justo quis. Hendrerit scelerisque lorem elit orci tempor tincidunt enim Phasellus dignissim tincidunt. Nunc vel et Sed nisl Vestibulum odio montes Aliquam volutpat pellentesque. Ut pede sagittis et quis nunc gravida porttitor ligula.
</footer><!-- .footer -->
.wrapper {
width: 960px;
margin: 0 auto;
min-height: 100%;
height: auto !important;
height: 100%;
}
/* Header
-----------------------------------------------------------------------------*/
.header {
height: 47px;
background: #FFE680;
}
/* Middle
-----------------------------------------------------------------------------*/
.content {
padding: 0 0 100px;
}
/* Footer
-----------------------------------------------------------------------------*/
.footer {
width: 960px;
margin: -100px auto 0;
height: 100px;
background: #BFF08E;
position: relative;
}
You can try this
HTML
<div class="outer">
<div class="bar">test</div>
<div class="cnt">Test</div>
</div>
CSS
* {margin: 0}
.bar {
background: #ccc;
margin-right: calc((100% - 960px)/2)
}
.cnt {
background: yellow;
min-height: 600px;
width: 960px;
margin: 0 auto
}
a standard page layout
<div class="wrapper">
<header class="header">
<strong>Header:</strong> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tortor. Praesent dictum, libero ut tempus dictum, neque eros elementum mauris, quis mollis arcu velit ac diam. Etiam neque. Quisque nec turpis. Aliquam arcu nulla, dictum et, lacinia a, mollis in, ante. Sed eu felis in elit tempor venenatis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut ultricies porttitor purus. Proin non tellus at ligula fringilla tristique. Fusce vehicula quam. Curabitur vel tortor vitae pede imperdiet ultrices. Sed tortor.
</header><!-- .header-->
<main class="content">
<strong>Content:</strong> Sed placerat accumsan ligula. Aliquam felis magna, congue quis, tempus eu, aliquam vitae, ante. Cras neque justo, ultrices at, rhoncus a, facilisis eget, nisl. Quisque vitae pede. Nam et augue. Sed a elit. Ut vel massa. Suspendisse nibh pede, ultrices vitae, ultrices nec, mollis non, nibh. In sit amet pede quis leo vulputate hendrerit. Cras laoreet leo et justo auctor condimentum. Integer id enim. Suspendisse egestas, dui ac egestas mollis, libero orci hendrerit lacus, et malesuada lorem neque ac libero. Morbi tempor pulvinar pede. Donec vel elit.
</main><!-- .content -->
<footer class="footer">
<strong>Footer:</strong> Mus elit Morbi mus enim lacus at quis Nam eget morbi. Et semper urna urna non at cursus dolor vestibulum neque enim. Tellus interdum at laoreet laoreet lacinia lacinia sed Quisque justo quis. Hendrerit scelerisque lorem elit orci tempor tincidunt enim Phasellus dignissim tincidunt. Nunc vel et Sed nisl Vestibulum odio montes Aliquam volutpat pellentesque. Ut pede sagittis et quis nunc gravida porttitor ligula.
</footer><!-- .footer -->
.wrapper {
width: 960px;
margin: 0 auto;
min-height: 100%;
height: auto !important;
height: 100%;
}
/* Header
-----------------------------------------------------------------------------*/
.header {
height: 47px;
background: #FFE680;
}
/* Middle
-----------------------------------------------------------------------------*/
.content {
padding: 0 0 100px;
}
/* Footer
-----------------------------------------------------------------------------*/
.footer {
width: 960px;
margin: -100px auto 0;
height: 100px;
background: #BFF08E;
position: relative;
}

make the last div in a container have the rest of the height ( preferrably no javascript )

I want divBody2 to fill the rest of the height in the div. Using a table was not initially my intention, but I was unable to do it without a table, so I thought of using one. Still the solution seems to elude me.
html:
<div id="divContainer" class="Container">
<div id="divContainerLeft" class="ContainerLeft">
<table>
<tr style="height: 1%;">
<td>
<div style="background-color: white;">Header1</span>
</td>
</tr>
<tr style="height: 1%;">
<td>
<div id="divBody1" class="Body1">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rhoncus, felis interdum condimentum consectetur, nisl libero elementum eros, vehicula congue lacus eros non diam. Cum sociis natoque penatibus et magnis dis </p>
</div>
</td>
</tr>
<tr style="height: 1%;">
<td>
<div style="background-color: white;">Header2</span>
</td>
</tr>
<tr style="height: 100%;">
<td>
<div id="divBody2" class="Body1" style="background-color: red;">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rhoncus, felis interdum condimentum consectetur, nisl libero elementum eros, vehicula congue lacus eros non diam. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus mauris lorem, lacinia id tempus non, imperdiet et leo. Cras sit amet erat sit amet lacus egestas placerat. Aenean ultricies ultrices mauris ac congue. In vel tortor vel velit tristique tempus ac id nisi. Proin quis lorem velit. Nunc dui dui, blandit a ullamcorper vitae, congue fringilla lectus. Aliquam ultricies malesuada feugiat. Vestibulum placerat turpis et eros lobortis vel semper sapien pulvinar.</p>
<p>Pellentesque rhoncus aliquet porta. Sed vel magna eu turpis pharetra consequat ut vitae lectus. In molestie sollicitudin mi sit amet convallis. Aliquam erat volutpat. Nullam feugiat placerat ipsum eget malesuada. Nulla facilisis nunc non dolor vehicula pretium. Sed dui magna, sodales id pharetra non, ullamcorper eu sapien. Mauris ac consectetur leo. Mauris consequat, lectus ut bibendum pulvinar, leo magna feugiat enim, eu commodo lacus sem vel ante. Sed tempus metus eget leo mollis vulputate. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>
<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed pulvinar rhoncus quam, vel semper tellus viverra id. Nulla rutrum porttitor odio, a rutrum purus gravida non. Etiam ac purus augue, eget vestibulum purus. Aenean venenatis ullamcorper augue, non consequat elit tempor sed. Donec velit sapien, volutpat sed ultricies egestas, semper a ante. Fusce dapibus, quam eget auctor suscipit, nibh leo posuere ante, at auctor nisi lacus in sem. Morbi interdum consectetur euismod. Cras accumsan est lacus. Nulla eleifend, eros vel consequat commodo, arcu nunc malesuada nunc, quis sagittis felis sem ac turpis.</p>
<p>Nulla rhoncus elementum convallis. Mauris condimentum aliquet egestas. Ut iaculis nisi eget tellus accumsan venenatis. Maecenas imperdiet aliquam porta. Aenean ultrices dolor sed quam laoreet varius. Curabitur condimentum blandit erat, quis accumsan eros interdum vitae. Curabitur ligula arcu, sollicitudin vitae iaculis sed, blandit sit amet enim. Morbi ullamcorper, metus vel mollis tristique, arcu turpis malesuada nisi, at dignissim lorem odio a orci. Proin ultrices, ipsum ut vestibulum interdum, libero felis auctor mi, vitae convallis nisl justo ac tellus. Integer nec lacinia turpis. Etiam massa nisl, rhoncus quis rutrum in, pretium eu leo. Proin a velit ut nulla laoreet vestibulum. Curabitur eu elit vitae felis auctor tincidunt. Curabitur tincidunt, metus sed sollicitudin cursus, quam elit commodo erat, ut tempor erat sapien vitae velit. Morbi nec viverra erat.</p>
</div>
</td>
</tr>
</table>
</div>
css:
.Container {
position: absolute;
top: 2%;
left: 2%;
height: 96%;
width: 96%;
overflow: visible;
background-color: cyan;
border: 0px solid #000000;
}
.ContainerLeft {
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 200px;
overflow: visible;
border: 0px solid black;
padding: 0px;
margin: 0px;
background-color: green;
}
.ContainerLeft table {
position: relative;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
border: 1px solid #000000;
border-spacing: 2px;
background-color: cyan;
}
.ContainerLeft tr {
border: 0px solid #000000;
}
.ContainerLeft td {
vertical-align: top;
border: 0px solid #000000;
}
.Body1 {
position: relative;
left: 0px;
top: 0px;
height: auto;
right: 0px;
border: 0px solid black;
background-color: #FFFFFF;
}
jsfiddle:
http://jsfiddle.net/p25hF/2/
is there any way to achieve this? i have set the table height to 100% of the parent container, but if the text ( or subdiv ) is large enough the table gets bigger than the parent container.
the problem doesn't seem to exist for the width ( width: 100% ), only for the height.
And for some reason i can't imagine, trying bottom: 0px; doesn't work either.
As explained in this question, there is no way to do it with CSS(2).
However, if you don't need to support older browsers, you can use flexbox. It is pretty simple. Assuming the following HTML:
<div class="outer">
<div class="inner"></div>
<div class="inner"></div>
<div class="inner"></div>
</div>
You can get the desired behaviour with a few lines of CSS:
.outer {
height: 200px;
display: flex;
justify-content: flex-start;
}
.inner {
overflow: auto;
flex-shrink: 0;
flex-grow: 0;
}
.inner:last-child {
flex-shrink: 1;
flex-grow: 1;
}
See a working example here: http://jsfiddle.net/ECf9M/1/ (requires a modern browser).