I'm trying to achieve a 3-column fixed-fluid-fixed layout. Also, the height of the layout must take up the whole screen so that it looks like 3 solid columns going from top-to-bottom.
Summary:
Left-column: fixed-width
Center-column: resizeable-width
Right-column: fixed-width
- The height for all 3 columns takes up entire screen.
- All 3 columns are always equal length.
My problem is getting the last part to work. I can not get all 3 columns to be equal height.
Here is my HTML/CSS:
<style type="text/css">
.parent {
margin-bottom:20px;
position:relative;
background-color: green;
}
.main {
margin-left:20%;
background:#ddd;
padding: 10px;
height: 100%;
}
.side {
position:absolute;
width:20%;
top:0;
bottom:0;
background-color: green;
}
.left {
left:0;
background-color: red;
}
.right {
right:0;
background-color: blue;
}
</style>
<div class="parent">
<div class="side left">
Sub Content
</div>
<div class="main">
Main Content<br>
<img src="" width="200" height="600">
</div>
<div class="side right">
Sub Content
</div>
</div>
Is this what you need? http://jsfiddle.net/3MfBa/
HTML:
<div class="side left">
Sub Content
</div>
<div class="main">
Main Content<br>
<img src="" width="200" height="600">
</div>
<div class="side right">
Sub Content
</div>
CSS:
.main {
position: absolute;
top:0;
bottom:0;
left:20%;
right:20%;
background:#ddd;
padding: 10px;
overflow: auto;
}
.side {
position:absolute;
width:20%;
top:0;
bottom:0;
background-color: green;
}
.left {
left:0;
background-color: red;
}
.right {
right:0;
background-color: blue;
}
Alternative CSS (http://jsfiddle.net/DgPRZ/):
body { margin:0; padding:0;}
.main {
margin-left:20%;
margin-right:20%;
background:#ddd;
padding: 10px;
}
.side {
position:fixed;
width:20%;
top:0;
bottom:0;
background-color: green;
}
.left {
left:0;
background-color: red;
}
.right {
right:0;
background-color: blue;
}
ALT VERSION 2 (http://jsfiddle.net/B4X4p/2/):
HTML:
<div class="container">
<div class="col side left">
Sub Content
</div>
<div class="col main">
<div class="main-content">
Main Content<br>
</div>
</div>
<div class="col side right">
Sub Content
</div>
</div>
CSS:
html, body { margin:0; padding:0; height:100%;}
.container, .container > div.col {
display: flex;
flex: 1 0 auto;
}
.container {
width:100%;
min-height:100%;
}
.main {
width: 60%;
background:#ddd;
float:left;
}
.main-content {
padding: 10px;
}
.side {
width:20%;
background-color: green;
min-height:100%;
float:left;
}
.left {
background-color: red;
}
.right {
background-color: blue;
}
To maintain column width you've to use either bootstrap or any framework or custom CSS that I've written below. It can be done with jquery as per your scenario.
.left-column,.right-column,.center-column{width:25%;display:inline-block;height:100vh;}
.center-column{width:50% !important;}
This will make side columns 25% and center one 50%; vh stands for viewport height. It will give you full height based on your viewport without any positioning hack.
T0 make only center part resizable. I guess you need jquery.
I recommend using Bootstrap it's easy to use and implement.
With Bootstrap you could have something like this:
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4></div>
<div class="col-lg-4 col-md-4 col-sm-4></div>
<div class="col-lg-4 col-md-4 col-sm-4></div>
</div>
And this would do the trick. Bootstrap uses a grid layout system and it is responsive. Read more at getbootstrap.com
Related
On a current project I have a similar structure (here I have very simplified the structure):
http://jsfiddle.net/6j5ouhz4/3/
HTML
<div class="container">
<div class="columns">
<div class="column1">
<div class="openFlexbox"> OPEN </div>
<div class="flexbox">TEST
<span class="close">X</span>
</div>
</div>
<div class="column1">
<div class="openFlexbox"> OPEN </div>
<div class="flexbox">TEST
<span class="close">X</span>
</div>
</div>
<div class="column1">
<div class="openFlexbox"> OPEN </div>
<div class="flexbox">TEST
<span class="close">X</span>
</div>
</div>
<div class="column1">
<div class="openFlexbox"> OPEN </div>
<div class="flexbox">TEST
<span class="close">X</span>
</div>
</div>
</div>
</div>
CSS
.container {
border:1px solid black;
width:600px;
min-height:200px;
margin: 0 auto;
background: #ddd;
display:flex;
display: -ms-flexbox;
}
.columns {
column-gap: 8em;
column-count: 2;
}
.column1 {
display: block;
border:1px solid red;
width:200px;
height: 200px;
margin:10px;
position:relative;
}
.flexbox {
display:none;
position: fixed;
top:0;
left:0;
width:100%;
height:100%;
background: #aaa;
font-size:30px;
text-align:center;
z-index: 9999
}
.flexbox.open {
display:block;
}
.close {
border:1px solid #fff;
padding: 5px;
}
.openFlexbox {
background: #a6dbea;
padding: 10px 0;
text-align:center;
display:inline-block;
position:absolute;
width: 100px;
left: 50%;
margin-left:-50px;
top: 40%;
}
JS
jQuery('.openFlexbox').on('click',function(e) {
jQuery(this).next('.flexbox').addClass('open');
});
jQuery('.close').on('click',function() {
jQuery('.flexbox').removeClass('open');
});
Firefox and Chrome don't have any problem, on Microsoft edge the modalbox appear "halfsize" occupying the half area of column where this block is located (in this example instead, it does not appear at all).
Actually, by removing the relative position, the problem disappears, but the "position: relative" I use to center the button..
but the way, the relative position shouldn't effect the fixed positions.
There is a fix for this problem?
the 'openflexbox' does not cover the whole area but maybe this would work for you?
css:
.flexbox {
display:none;
/*position: fixed;*/
top:0;
left:0;
width:100%;
height:100%;
background: #aaa;
font-size:30px;
text-align:center;
z-index: 9999;
}
js:
jQuery('.openFlexbox').on('click',function(e) {
jQuery(this).next('.flexbox').addClass('open');
$('.openFlexbox').css('display', 'none');
});
jQuery('.close').on('click',function() {
jQuery('.flexbox').removeClass('open');
$('.openFlexbox').css('display', 'inline-block');
});
I have a section element with 3 divs inside, I want to center horizontally 'div 2', but the problem is the adyacent divs are not the same size so "justify-content:center" doesn't works.
I know here (under the title "Center a flex item when adjacent items vary in size") is a solution, but it doesn't work for me.
Here is the revelant code:
HTML
<section>
<div id="div1">DIV 1</div>
<div id="div2">DIV 2</div>
<div id="div3">DIV 3</div>
</section>
CSS
section{
display:flex;
position:relative;
}
#div1{
width:260px;
}
#div2{
position:absolute;
left:50%;
transform(translateX:-50%,0);
}
#div3{
margin-left:auto;
width:50px;
}
Here is also a codepen.
My goal is center 'div2' and move the rest of divs to the left and right edges respectively.
Any help would be appreciated.
<section>
<div id="div1">DIV 1</div>
<div id="div2_wrap">
<div id="div2">DIV 2</div>
</div>
<div id="div3">DIV 3</div>
</section>
section{
display: flex;
position:relative;
padding:5px;
height: 500px;
background:yellow;
}
div{
padding:5px;
background:coral;
}
#div1{
width:260px;
}
#div2_wrap{
position: absolute;
left:50%;
height: 100%;
align-items: center;
display: flex;
}
#div2 {
background-color: #000fff;
}
#div3{
margin-left:auto;
width:50px;
}
You can wrap your divs around another parent div and set them to have equal widths first. Then align your children divs inside it's parent. Like this:
HTML:
<section>
<div class="wrapper" id="div1">
<div class="innerDiv">DIV 1</div>
</div>
<div class="wrapper" id="div2">
<div class="innerDiv">DIV 2</div>
</div>
<div class="wrapper" id="div3">
<div class="innerDiv">DIV 3</div>
</div>
</section>
CSS:
section{
display:flex;
padding:5px;
background:yellow;
text-align:center;
}
.wrapper{
display:flex;
flex-grow:1;
flex-wrap:wrap;
}
.innerDiv{
padding:5px;
background:coral;
}
#div1{
justify-content:flex-start;
}
#div1 .innerDiv{
flex:1;
}
#div2{
justify-content:center;
}
#div3{
justify-content:flex-end;
}
#div3 .innerDiv{
width:50px;
}
Codepen here
Or you can go with the old school more browser compatible way, and also keeping your HTML code same.
section {
padding: 5px;
background: yellow;
text-align: center;
position: relative;
float: left;
box-sizing: border-box;
width: 100%;
}
div {
padding: 5px;
display: inline-block;
background: coral;
}
#div1 {
width: 260px;
float: left;
}
#div2 {
left: 50%;
margin-left: -0.5em;
position: absolute;
}
#div3 {
float: right;
width: 50px;
}
Codepen Here
I have a layout where I have 3 columns.
<div id="wrapper">
<div id="logo"></div>
<div id="search-input"></div>
<div id="user-name"></div>
</div>
How can I place these 3 blocks in one line without JS, calc and flexbox if I need:
logo should be fixed
user-name should have auto width
search-input should places on the left free space between logo and user-name blocks. It has to be fluid container.
Use flexbox:
#wrapper {
display: flex;
/* flex-direction: row; <-- by default */
}
#logo {
flex: 0 0 200px;
background-color: lightgreen;
}
#user-name {
flex: none;
background-color: lightblue;
}
#search-input {
flex: 1 0 auto;
background-color: lightgrey;
}
<div id="wrapper">
<div id="logo">logo</div>
<div id="search-input">input</div>
<div id="user-name">user name</div>
</div>
May be this is what you want. you can add content of user-name to see how it work.
.wraper{
width: 100%;
border: 1px solid red;
}
#logo{
float:left;
width:250px;
height: 50px;
border:1px solid #CCC;
display:block;
background-color:yellow;
}
#search-input{
margin-left:260px;
min-height:50px;
display:block;
background-color:red;
}
#user-name{
float:right;
display:block;
height:50px;
background-color:#FFF;
}
#search-input > .inner{
height:50px;
background-color:red;
margin-right:20px;
}
#user-name > .inner{
background-color:green;
min-width:150px;
height:50px;
margin-left:10px;
}
<div id="wrapper">
<div id="logo">Logo</div>
<div id="user-name">
<div class="inner">
user name
</div>
</div>
<div id="search-input">
<div class="inner">
search input
</div>
</div>
</div>
<div id="wrapper">
<div id="logo"></div>
<div id="search-input"></div>
<div id="user-name"></div>
</div>
<style>
#logo{float:left;padding:2px}
#search-input{width:50%;float:left;padding:2px}
#user-name{width:auto;float:left;padding:2px}
</style>
#wrapper{
display:block;
}
#logo{
display:inline-block;
width:30%;
float:left;
}
#search-input{
width:50%;
display:inline-block;
float:left;
}
#user-name{
width:auto;
display:inline-block;
float:left;
}
This will keep them in one line.
Example:
<div class="container">
<div>variable</div>
<div>fixed</div>
<div>variable with min-width</div>
<div>fixed</div>
<div>variable</div>
</div>
I want the whole thing to be as wide as the viewport.
I know how to do that for three columns, but I am completely lost with the five column version. I do not even have a concept of how that could work. The usual three column style involves absolute positioning of the fixed columns, but that would not work since the outermost columns are of variable width. I am lost.
Any ideas?
This is what I tried:
HTML:
<div class="container">
<div class="left">var</div>
<div class="inner_container">
<div class="inner_left">fix</div>
<div class="middle">var</div>
<div class="inner_right">fix</div>
</div>
<div class="right">var</div>
</div>
CSS:
.container {
position:relative;
}
.container div {
background: yellow;
}
.container .left,
.container .right {
background: orange;
width: 15%;
}
.inner_container {
position:relative;
}
.inner_container div {
margin:0 50px;
background:lightgreen;
}
.inner_container .inner_left,
.inner_container .inner_right {
background:lightblue;
position:absolute;
top:0;
width:50px;
}
.inner_container .inner_left {
left:-50px;
}
.inner_container .inner_right {
right:-50px;
}
The "inner_container" is basically the usual three column solution. If I set the inner_container to "left: 15%" the whole inner container is moved to the right, but still on its own "line".
flexbox can do that.
* {
box-sizing: border-box;
}
.container div {
height: 75px;
border:1px solid grey;
}
.container {
display: flex;
}
.variable {
background: lightgreen;
flex: 1 0 auto
}
.fixed {
background: lightblue;
flex: 0 0 150px;
}
.min-width {
flex-basis:250px;
min-width:250px;
background: pink;
}
<div class="container">
<div class="variable">variable</div>
<div class="fixed">fixed</div>
<div class="variable min-width">variable with min-width</div>
<div class="fixed">fixed</div>
<div class="variable">variable</div>
</div>
Codepen Demo
I am not sure why contactBox is overlapping the mainInfo box.The contact box is also not stretching to its parent container which is 960px.
CSS
.mainInfo {
position:relative;
height:500px;
background-color: pink;
padding:30px 0 0 30px;
}
.col-6 .imagePlaceholder {
width:300px;
height:420px;
background-color: red;
}
.col-6 .about {
position: absolute;
top:30px;
left:414px;
padding:1em;
}
.contactBox {
height:450px;
background-color:green;
}
Here is a JS fiddle:
http://jsfiddle.net/2zm47/
I would probably code this css differently, but checkout the
.mainInfo {
position:relative;
height:500px;
background-color: pink;
padding:30px 0 0 30px;
}
.col-6 .imagePlaceholder {
width:300px;
height:420px;
background-color: red;
}
.col-6 .about {
position: absolute;
top:30px;
left:414px;
padding:1em;
}
.contactBox {
height:450px;
background-color:green;
}
I hope this helps. I put a note in the JS section of the fiddle.
http://jsfiddle.net/emersive/84WeT/1/
Your HTML is messed up. Should be like:
<div class="container">
<div class="mainInfo">
<div class="col-6">
<div class="imagePlaceholder"></div>
</div>
<div class="col-6">
<div class="about">
<p>...</p>
<p>...</p>
</div>
</div>
</div>
<div class="contactBox"></div>
</div>