CSS Grid Responsive layout, make the site move with the menu - css

i saw a website that had a cool effect when the hamburger menu opened, the site moved with the menu, how do i achieve that?
Currently i have this: https://jsfiddle.net/xwvL2a70/1/
/* grid */
.container {
display: grid;
grid-template-columns: 1fr;
grid-gap: 10px;
}
/* items */
.container > * {
color: #353535;
font-size: 1.2em;
line-height: 1.5;
padding: 20px;
background: #d0cfc5;
}
/* nav styles */
.container nav {
background: #136fd2;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav a {
color: #d0cfc5
}
nav a:hover {
text-decoration: none;
}
/* media query for grid layout */
#media only screen and (min-width: 600px) {
/* grid */
.container {
grid-template-columns: repeat(4, 1fr);
}
/* specific item styles */
.container header,
.container nav,
.container footer {
grid-column: span 4;
}
.container section {
grid-column: span 3;
}
/* nav styles */
nav ul li {
display: inline-block;
padding: 0 20px 0 0;
}
/* hide toggle */
.toggle {
display: none;
}
}
/* media query for nav styles */
#media only screen and (max-width: 599px) {
#nav {
transition: transform .3s ease-in-out;
top: 0;
bottom: 0;
position: fixed;
width: 300px;
right: -340px;
}
#nav:target {
transform: translateX(-340px);
}
.close {
text-align: right;
display: block;
text-decoration: none;
font-size: 3em;
position: relative;
top: -30px;
}
.open {
text-align: left;
}
}
I would like to make an animation like this site: https://vizir.com.br/
When you click the menu, the content moves to the left with it.
I dont know if its an easy question, im really new to this and just looking to learn some neat effects, is it hard to create a menu/website animation like this?

I think what you may be looking for is this link here How To Side Navigation
Specifically this part here, which is not only changing the width of the sidenav with a nice transition, but also changing the margin on the main content
/* Set the width of the side navigation to 250px and the left margin of the
page content to 250px */
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
}
/* Set the width of the side navigation to 0 and the left margin of the page content to 0 */
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft = "0";
}

I tried to work on your issue and it resolves. Please have a look at my Codepen https://codepen.io/navdeepsingh/pen/VyVPeP
const open = document.querySelector('#open');
open.addEventListener('click', function() {
document.querySelector('body').classList.add('menu-opened');
});
const close = document.querySelector('#close');
close.addEventListener('click', function() {
document.querySelector('body').classList.remove('menu-opened');
});
/* grid */
.container {
display: grid;
grid-template-columns: 1fr;
grid-gap: 10px;
transition: all .3s ease-in-out;
}
/* items */
.container > * {
color: #353535;
font-size: 1.2em;
line-height: 1.5;
padding: 20px;
background: #d0cfc5;
}
/* nav styles */
.container nav {
background: #136fd2;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav a {
color: #d0cfc5
}
nav a:hover {
text-decoration: none;
}
/* media query for grid layout */
#media only screen and (min-width: 600px) {
/* grid */
.container {
grid-template-columns: repeat(4, 1fr);
}
/* specific item styles */
.container header,
.container nav,
.container footer {
grid-column: span 4;
}
.container section {
grid-column: span 3;
}
/* nav styles */
nav ul li {
display: inline-block;
padding: 0 20px 0 0;
}
/* hide toggle */
.toggle {
display: none;
}
}
/* media query for nav styles */
#media only screen and (max-width: 599px) {
#nav {
transition: transform .3s ease-in-out;
top: 0;
bottom: 0;
position: fixed;
width: 300px;
right: -340px;
}
#nav:target {
transform: translateX(-340px);
}
.close {
text-align: right;
display: block;
text-decoration: none;
font-size: 3em;
position: relative;
top: -30px;
}
.open {
text-align: left;
}
section {
postion: fixed;
}
body.menu-opened .container {
margin: 0 80% 0 -80%;
}
}
<div class="support-grid"></div>
<div class="container">
<header role="banner">
<a class="toggle open" id="open" href="#nav">open</a>
<h1>Header</h1>
</header>
<nav id="nav" role="navigation">
<a class="toggle close" id="close" href="#">×</a>
<ul>
<li>
Item 1
</li>
<li>
Item 2
</li>
<li>
Item 3
</li>
</ul>
</nav>
<section role="main">
<article>
<h2>Article</h2>
<p>Curabitur orci lacus, auctor ut facilisis nec, ultricies quis nibh. Phasellus id diam sollicitudin, malesuada turpis id, gravida erat. Maecenas placerat elit vel hendrerit convallis. Sed in mauris ut justo vulputate viverra feugiat ac dui. Fusce feugiat arcu in vehicula vehicula. Donec varius justo at nulla aliquet volutpat.</p>
<p>Ut id rutrum eros. Nulla tristique, magna et mattis vulputate, mi eros suscipit turpis, nec bibendum turpis nunc feugiat sapien. Nunc arcu est, lacinia id diam quis, sagittis euismod neque. Nullam fringilla velit sed porta gravida. Proin eu vulputate libero. Ut a lacinia enim. Etiam venenatis mauris et orci tempor congue. Sed tempor eros et ultricies congue. Aenean sed efficitur orci. Nulla vel tempus mi.</p>
<p>Ut cursus suscipit augue, id sagittis nibh faucibus eget. Etiam suscipit ipsum eu augue ultricies, at rhoncus mi faucibus. In et tellus vitae leo scelerisque fringilla nec at nunc.</p>
</article>
</section>
<aside>
<h3>Aside</h3>
</aside>
<footer>
<h3>Footer</h3>
</footer>
</div>
`

Related

Float left bug in Firefox when when parent is absolutly positioned?

I have an unusual layout requirement but Ive got it working in Chrome, Edge and IE11, only Firefox doen't work making me think it could be a bug with the browser.
Here is how the page should look:
But this is how it looks is Firefox:
Update: I also got this working on Chrome without float: left and instead using width: fit-content, however this and width: -moz-fit-content still don't work on Firefox.
The floated div with the red boarder doenst appear to be floated at all. As a result the blue box is off screen.
* {
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
}
.wrapper {
overflow: hidden;
}
.cont {
display: flex;
background: grey;
margin-left: auto;
margin-right: auto;
max-width: 1000px;
}
.col {
flex-basis: 50%;
min-height: 600px;
position: relative;
}
.col-1 {
display: flex;
flex-direction: column;
justify-content: center;
}
.col1-inner {
position: absolute;
top: 40px;
left: 0;
bottom: 40px;
right: -2000px;
}
img {
max-width: 100%;
width: auto;
height: 100%;
}
.content {
border: 2px solid red;
float: left;
height: 100%;
position: relative;
}
.content:after {
content: "";
background: blue;
display: flex;
width: 100px;
height: 100px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
<div class="wrapper">
<div class="cont">
<div class="col col-1">
<h1>Content</h1>
<p>Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff </p>
</div>
<div class="col">
<div class="col1-inner">
<div class="content">
<img src="https://images.unsplash.com/photo-1580152040915-ad6ceeaeb8c1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3450&q=80" />
</div>
</div>
</div>
</div>
</div>
https://codepen.io/_j_i_m_fb_/pen/GRgaKQE
Lame answer to the actual question
This is an edge case due to the large fixed units used. Chrome is collapsing the div when float is used. Firefox is not. To determine which browser is technically correct we must look at the appropriate specification. How boring is that... instead, here is a...
... possible solution for what you desire
I have created an alternative example with CSS Grid.
HTML
Simple layout. The body is used instead of an extra div, with two divs for the left and right column:
<body>
<div class="content">
<h1>Content</h1>
<p>Contents</p>
</div>
<div class="image">
<img src="https://placehold.it/3450x2300" />
</div>
</body>
CSS
The body:
body {
display: grid;
grid-template-columns: auto auto;
}
Establish the grid.
Create two equal width columns
The content div:
.content {
display: grid;
align-content: center;
max-width: 600px;
min-width: 400px;
background: grey;
padding: 0 20px;
margin: 0 0 0 auto;
}
Establish the inner grid
Vertically center the contents
Use appropriate max and min widths
Instead of justify-items: end, the left auto margin provides the horizontal centering. This is so the background doesn't stretch all the way to the left.
The image div:
.image {
position: relative;
max-width: 700px;
min-width: 500px;
background: linear-gradient(to right, grey 0, grey 50%, transparent 50%);
}
Position the pseudo-element in relation to this div
Restrict the width of the image so it doesn't get too large
Restrict the width of the image so it doesn't get too small
Create the background colour with a gradient that covers only a percentage of the image div
The img is contained like so:
img {
max-width: 100%;
padding: 40px 0;
}
Restrict width of image to parent div
Pad out as desired
Example
* {
box-sizing: border-box;
}
body {
margin: 0;
display: grid;
grid-template-columns: auto auto;
}
.content {
display: grid;
align-content: center;
max-width: 600px;
min-width: 400px;
background: grey;
padding: 0 20px;
margin: 0 0 0 auto;
}
.image {
position: relative;
max-width: 700px;
min-width: 300px;
background: linear-gradient(to right, grey 0, grey 50%, transparent 50%);
}
.image::after {
content: "";
height: 100px;
width: 100px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: blue;
position: absolute;
}
img {
max-width: 100%;
padding: 40px 0;
}
<div class="content">
<h1>Content</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id bibendum enim. Integer blandit arcu lobortis, ultricies quam vitae, elementum urna. Nunc a mauris ex. Aenean egestas neque urna, eu euismod massa ultrices sit amet. Praesent imperdiet
dictum ante, quis viverra nibh volutpat eu. Sed tempor, quam in molestie tincidunt, eros massa condimentum arcu, ut tempus mauris ligula et arcu. Donec nec faucibus neque, sit amet tincidunt nulla. Nullam et mattis ipsum. Sed euismod porttitor justo
eu aliquet. Sed hendrerit finibus dignissim. Morbi id ipsum imperdiet, fringilla urna posuere, fermentum justo. Mauris eleifend, orci et eleifend consectetur, augue lacus hendrerit diam, eget dictum lacus sem vitae augue.</p>
</div>
<div class="image">
<img src="https://placehold.it/3450x2300" />
</div>

Css Grid and Hamburger Menu

im learning css in general and i am failling very, - v e r y - hard at it...
im trying to do a simple thing with my css grid, just animate the hidden menu right to left, instead of left to right, but i dont know what i must change to do it..
Can you guys help me? Here the fiddle: https://jsfiddle.net/xwvL2a70/
/* grid */
.container {
display: grid;
grid-template-columns: 1fr;
grid-gap: 10px;
}
/* items */
.container > * {
color: #353535;
font-size: 1.2em;
line-height: 1.5;
padding: 20px;
background: #d0cfc5;
}
/* nav styles */
.container nav {
background: #136fd2;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav a {
color: #d0cfc5
}
nav a:hover {
text-decoration: none;
}
/* media query for grid layout */
#media only screen and (min-width: 600px) {
/* grid */
.container {
grid-template-columns: repeat(4, 1fr);
}
/* specific item styles */
.container header,
.container nav,
.container footer {
grid-column: span 4;
}
.container section {
grid-column: span 3;
}
/* nav styles */
nav ul li {
display: inline-block;
padding: 0 20px 0 0;
}
/* hide toggle */
.toggle {
display: none;
}
}
/* media query for nav styles */
#media only screen and (max-width: 599px) {
#nav {
transition: transform .3s ease-in-out;
top: 0;
bottom: 0;
min-height: 100vh; /* override Safari bug */
position: fixed; /* or choose `absolute` depending on desired behavior*/
width: 300px;
left: -340px;
}
#nav:target {
transform: translateX(340px);
}
.close {
text-align: right;
display: block;
text-decoration: none;
font-size: 3em;
position: relative;
top: -30px;
}
.open {
text-align: left;
}
}
You just need to change your left: -340px; to right: -340px; and then your transform: translateX(340px); to transform: translateX(-340px);. Both of these are within the media query.
Here's a working example (if you view in full screen and scale the window width down to preview):
/* grid */
.container {
display: grid;
grid-template-columns: 1fr;
grid-gap: 10px;
}
/* items */
.container > * {
color: #353535;
font-size: 1.2em;
line-height: 1.5;
padding: 20px;
background: #d0cfc5;
}
/* nav styles */
.container nav {
background: #136fd2;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav a {
color: #d0cfc5
}
nav a:hover {
text-decoration: none;
}
/* media query for grid layout */
#media only screen and (min-width: 600px) {
/* grid */
.container {
grid-template-columns: repeat(4, 1fr);
}
/* specific item styles */
.container header,
.container nav,
.container footer {
grid-column: span 4;
}
.container section {
grid-column: span 3;
}
/* nav styles */
nav ul li {
display: inline-block;
padding: 0 20px 0 0;
}
/* hide toggle */
.toggle {
display: none;
}
}
/* media query for nav styles */
#media only screen and (max-width: 599px) {
#nav {
transition: transform .3s ease-in-out;
top: 0;
bottom: 0;
position: fixed;
width: 300px;
right: -340px;
}
#nav:target {
transform: translateX(-340px);
}
.close {
text-align: right;
display: block;
text-decoration: none;
font-size: 3em;
position: relative;
top: -30px;
}
.open {
text-align: left;
}
}
<div class="support-grid"></div>
<div class="container">
<header role="banner">
<a class="toggle open" href="#nav">open</a>
<h1>Header</h1>
</header>
<nav id="nav" role="navigation">
<a class="toggle close" href="#">×</a>
<ul>
<li>
Item 1
</li>
<li>
Item 2
</li>
<li>
Item 3
</li>
</ul>
</nav>
<section role="main">
<article>
<h2>Article</h2>
<p>Curabitur orci lacus, auctor ut facilisis nec, ultricies quis nibh. Phasellus id diam sollicitudin, malesuada turpis id, gravida erat. Maecenas placerat elit vel hendrerit convallis. Sed in mauris ut justo vulputate viverra feugiat ac dui. Fusce feugiat arcu in vehicula vehicula. Donec varius justo at nulla aliquet volutpat.</p>
<p>Ut id rutrum eros. Nulla tristique, magna et mattis vulputate, mi eros suscipit turpis, nec bibendum turpis nunc feugiat sapien. Nunc arcu est, lacinia id diam quis, sagittis euismod neque. Nullam fringilla velit sed porta gravida. Proin eu vulputate libero. Ut a lacinia enim. Etiam venenatis mauris et orci tempor congue. Sed tempor eros et ultricies congue. Aenean sed efficitur orci. Nulla vel tempus mi.</p>
<p>Ut cursus suscipit augue, id sagittis nibh faucibus eget. Etiam suscipit ipsum eu augue ultricies, at rhoncus mi faucibus. In et tellus vitae leo scelerisque fringilla nec at nunc.</p>
</article>
</section>
<aside>
<h3>Aside</h3>
</aside>
<footer>
<h3>Footer</h3>
</footer>
</div>

Different background color for left and right with content that entends to the bottom edge

I am trying to set up a page that has two background colors. One color for the left half of the page and another for the right half of the page and content that sits in the middle that is centered horizontally. If the content in the page does not fill the entire browser window vertically, the content ends and I can see the two background colors below it. Is there a way to extend the content vertically to always fill the browser window? I know sticky footers works well, but I can't seem to get it to work with what I am doing.
Here is my HTML:
<div id="wrapper">
<div id="left"></div>
<div id="right"></div>
<div id="container">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. </p>
</div>
</div>
<div id="footer">Footer footer footer</div>
This is my CSS:
html, body {
margin: 0; padding: 0; border: 0;
}
#left, #right {
position: fixed;
width: 50%;
height: 100%;
top: 0;
}
#left {
background: #014c8d;
left: 0;
}
#right {
background: #0f2451;
right: 0;
}
#container {
background: #fff;
width: 70%;
max-width: 500px;
height: 100%;
margin: 0 auto;
padding: 10px;
position: relative;
}
#wrapper {
position: relative;
background: #006d46;
}
#footer {
background: #006d46;
position: relative;
}
I have a jsfiddle to show what I currently have: http://jsfiddle.net/snPYb/1/
You just have to add height:100%; to your wrapper and html,body :
html, body {
margin: 0; padding: 0; border: 0;
height:100%;
}
#wrapper {
position: relative;
background: #006d46;
height:100%;
}
FIDDLE
EDIT #1 :
Try this :
html, body {
margin: 0; padding: 0; border: 0;
display:table;
height:100%;
width:100%;
}
Added display:table and width:100%
FIDDLE
http://jsfiddle.net/snPYb/3/
What you were missing was the height:100% on the wrapper as well.

Fixed Element Overflow

I'm trying to get the #sidebar element to scroll overflow once the browser window is shorter than it's minimum height but can't seem to get it working. Any idea why?
http://jsfiddle.net/q5jKM/1/
CSS - Sorry I cant get this funky formatting working.
html,body{height:100%;margin:0}
#sidebar {
width: 20em;
position:fixed;
top: 0;
bottom: 0;
left: 0;
z-index:2;
color: #ffffff;
background-color: #333333;
overflow:auto;
min-height: 34em;
}
#sidebar .nav {
width: 3em;
float: right;
overflow: auto;
background-color: #2e2e2e;
border-left: 2px groove #454545;
height: 100%;
position:relative;
}
#sidebar .content {
height: 100%;
width: 16.875em; /* 17-(2/16) - 20em - .nav - nav border*/
float:left;
position:relative;
}
#sidebar .top {
position:absolute;
top:0;
}
#sidebar .bottom {
position:absolute;
bottom:0;
}
#sidebar .middle {
position: absolute;
bottom: 12em; /* 3.125*3 */
top: 16em; /* 3.125*4 */
background: green;
}
.content .middle {
overflow:auto;
}
#sidebar .content > div {width: 16.875em; } /*.top .middle .bottom*/
#sidebar .nav > div {width:3em; } /*.top .middle .bottom*/
/*table-cell trying get vertical-align working*/
#sidebar .table-cell {display:table-cell;}
#sidebar .middle .table-cell {vertical-align: middle;}
#sidebar .content p, #sidebar .content li, #sidebar .content img {font-size: .75em; color: #dddddd;}
#sidebar ul {margin:0; padding: 0;}
#sidebar .nav li {
padding: .5625em;
list-style:none;
}
#sidebar .nav li img {
height: 1.875em;
width: 1.875em
}
#sidebar .nav .top li { border-bottom: 2px groove #454545 }
#sidebar .nav .bottom li { border-top: 2px groove #454545 }
.content li {
position:relative;
display:block;
background-color: #444;
padding: .72em;
border-radius: .8em;
border-bottom: 1px solid #292929;
border-top: 1px solid #4c4c4c;
text-align: center;
font-size: 1em;
letter-spacing: .1em;
font-weight: normal;
height: 1.2em;
}
.content li:after {
content:"";
position:absolute;
display:block;
width:0;
top:.11em; /* controls vertical position */
right:-.852em; /* value = - border-left-width - border-right-width */
border-style:solid;
border-width:1.2em 0 1.2em 1.2em;
border-color:transparent #444;
}
.content .top li{margin: .95em 0 1.9em 0;}
.content .bottom li{margin: 1.9em 0 .95em 0;}
.content .logo {
text-align: center;
padding: 1em 0 2em 0;
width: 100%;
border-bottom: 2px groove #454545;
}
.content p.welcome {
text-align: center;
line-height: 1.5em;
margin: 1em 0;
}
HTML
<div id="sidebar">
<div class="nav">
<div class="top">
<ul>
<li><img src="_images/attributes/attribute2.svg"></li>
<li><img src="_images/attributes/attribute2.svg"></li>
<li><img src="_images/attributes/attribute2.svg"></li>
<li><img src="_images/attributes/attribute2.svg"></li>
</ul>
</div>
<div class="middle"><div class="table-cell"><p>test</p></div></div>
<div class="bottom">
<ul>
<li><img src="_images/attributes/attribute2.svg"></li>
<li><img src="_images/attributes/attribute2.svg"></li>
<li><img src="_images/attributes/attribute2.svg"></li>
</ul>
</div>
</div>
<div class="content">
<div class="top">
<ul>
<li>SIDEBAR LINK</li>
<li>SIDEBAR LINK</li>
<li>SIDEBAR LINK</li>
<li>SIDEBAR LINK</li>
</ul>
</div>
<div class="middle"><div class="table-cell">
<div class="logo"><img src="_images/g.svg"></div>
<p class="welcome">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris dictum tellus viverra neque bibendum in mattis ante dignissim. Nam mattis feugiat lorem porttitor adipiscing. Aliquam erat volutpat. Nunc feugiat magna vitae mauris egestas euismod. In hac habitasse platea dictumst. Praesent magna sem, malesuada non fermentum vel, luctus quis mauris. Duis quam purus, ornare vitae eleifend sed, malesuada eget libero. Phasellus sed lorem risus, nec placerat urna. In magna turpis, accumsan ac egestas quis, dictum vel massa. Nulla vitae magna arcu. Maecenas sit amet vestibulum urna. Integer feugiat dignissim leo sed ornare. Maecenas auctor ultricies dui, pulvinar tincidunt velit feugiat quis. Sed egestas ornare elit, et fringilla quam viverra ut.</p>
</div></div>
<div class="bottom">
<ul>
<li>SIDEBAR LINK</li>
<li>SIDEBAR LINK</li>
<li>SIDEBAR LINK</li>
</ul>
</div>
</div>
</div>
Got it!
Add: - So that #sidebar's is equal to the browser window.
#sidebar{height:100%}
And add: - To provide content that overflows.
#sidebar .nav, #sidebar .content {min-height:34em}
Once the browser window becomes shorter than 34ems #sidebar will overflow.
You just need to add a CSS media query rule:
#media all and (min-height: 34em) {
#sidebar{
overflow: scroll;
}
}
Once the browser height is less than 34em, then the overflow: scroll rule will be added to the #sidebar.
Use overflow scroll instead of auto
See this http://jsfiddle.net/q5jKM/2/
I got this to work using jquery - you need to get the height of the browser and adjust the css overflow to scroll when it reaches a certain height
var heightToScroll = 600;
var viewHeight = $(window).height();
$(window).resize(function() {
if(viewHeight < heightToScroll){
$('#sidebar').css("overflow","scroll");
}
});
http://jsfiddle.net/q5jKM/3/

CSS how to vertical align div in a div against a sibling div (inline-block)

http://jsfiddle.net/LdTpg/3/
<div class="a">
<div class="b">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec justo nunc, vehicula nec auctor a, lacinia dapibus tortor. Praesent id mi id dui sodales laoreet. Maecenas ut aliquet urna. Donec porttitor turpis eu velit viverra in tincidunt nisi viverra. Curabitur mi ligula, facilisis ut cursus vel, fermentum sit amet nibh. Ut in nisl cursus quam molestie scelerisque non a nulla. Morbi eu diam nibh, eu dictum orci. Nunc est neque, dignissim ut fermentum id, sagittis eget urna.
</div>
<div class="c">
<div class="d" style="background: grey; height: 100%; width: 100%;"></div>
<div class="e">Vertical Align This</div>
</div>
</div>
Styles:
​.a {
border:1px solid red;
overflow:hidden;
}
.a div {
display:inline-block;
}
.b {
width:200px;
border:1px solid blue;
float:left;
position:absolute;
}
.c {
width: 100%;
margin-left: 200px;
position:relative;
}
.d {
position:absolute;
top:0;
left:0;
}
.e {
position: relative;
}
​
So basically
I know the width of the left div (container B) but not its height
The width of the right div (container C) has to take up the remaining space
I do not know the height or width of the outer div (container A)
There is an element (container D) inside the right div (container C) that must be placed under another element (container E)
Container D should be the same dimensions as container C
Container E should have text that is both horizontally and vertically center (with respect to container C)
I have tried various CSS settings including messing with the line height, display (inline-block vs block), heights/widths as %, floats...
It is unclear what the height of C should be in your information of what you desire (you do not address that).
If C is an arbitrary height
It can be done as this fiddle is configured (works in IE7+).
.a {
border:1px solid red;
overflow:hidden;
}
.a div {
display:inline-block;
}
.b {
width:200px;
border:1px solid blue;
float:left;
}
.c {
overflow: hidden;
position:relative;
height: 100px; /* arbitrary height */
line-height: 100px; /* match arbitrary height */
text-align: center;
}
.a .c {display: block;}
.d {
position:absolute;
top:0;
left:0;
}
.e {
position: relative;
vertical-align: middle;
}
If C is supposed to match B's flexible height
It can be done as this fiddle is configured (works in IE8+; note: Chrome shows a slight variation compared to Firefox and IE on how it calculates the absolute position of the D element). This solution removes your 100% inline styling on D's width and height.
.a {
border:1px solid red;
overflow:hidden;
display: table;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
min-width: 100%;
position: relative;
}
.a div {
display: table-cell;
}
.b {
width:200px;
border:1px solid blue;
}
.c {
text-align: center;
vertical-align: middle;
}
.d {
position:absolute;
top:1px;
right: 1px;
bottom: 1px;
left: 203px;
}
.a .e {
display: inline-block;
}
.e {
position: relative;
}

Resources