Two column layout: Problems with column - html

I created a simple two column layout based on this:
How to control overflow of table cell in Firefox?.
The left columns should be scrollable (top-down) and the right one should be fix.
HTML:
<div id="col1">
<div id="list">
<div class="row">Test 1</div>
<div class="row">Test 2</div>
<div class="row">Test 3</div>
<div class="row">... more rows</div>
</div>
</div><div id="col2"></div>
CSS:
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background-color: #0c0;
}
#col1 {
width: 25%;
height: 100%;
display:inline-block;
background-color: #c00;
}
#col1>#list {
width: 100%;
overflow: auto;
}
#col1>#list>.row {
padding: 5px;
border-bottom: 1px solid #ccc;
}
#col2 {
width: 75%;
height: 100%;
display:inline-block;
background-color: #00c;
}
Please see this demo:
http://jsfiddle.net/bitas/qRtjN/
Firefox 18.0.2 shows it nearly as expected. In other browsers the left column doesn't start at the top of the page but in the lower left corner.
It works as expected if I remove the "div#list". What's wrong with this div? How I can I fix it?

I have modified your CSS a bit and it does work. Here it is:
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background-color: #0c0;
}
#col1 {
width: 25%;
height: 1000px;
display:inline-block;
background-color: #c00;
}
#col1>#list {
width: 100%;
height: 100%;
overflow: auto;
}
#col1>#list>.row {
padding: 5px;
border-bottom: 1px solid #ccc;
}
#col2 {
width: 75%;
height: 100px;
display:inline-block;
background-color: #00c;
position:fixed;
top:0;
right:0;
}

Adding this CSS will correct the alignment of your columns:
#col1, #col2 {
vertical-align: text-top;
}
http://jsfiddle.net/qRtjN/13/

Related

remove unwanted spaces between 2divs with css

Hi i has created this simple design:
body{
background: url("../imgs/bg_pattern.gif") scroll 0 0% repeat, url("../imgs/1.jpg") no-repeat scroll 0 0% / 100% 100%;
margin: auto;
}
#panel{
height: 100%;
width: 300px;
background-color: #232325;
float: right;
}
#audio{
width: 100%;
height: 11%;
background-color: red;
}
#term{
width: 100%;
height: 11%;
background-color: blue;
}
#content{
width: 100%;
height: 67%;
background-color: green;
}
#footer{
width: 100%;
height: 11%;
background-color: pink;
}
.term{
background-color: black;
height: 100%;
width: 25%;
display: inline-block;
border-right: solid red;
}
.term:first-child{
margin-left: 0;
}
.term:last-child{
border-right: none;
}
<div id="panel">
<div id="header">
<div id="audio"></div>
<div id="term">
<div class="term"></div>
<div class="term"></div>
<div class="term"></div>
<div class="term"></div>
</div>
</div>
<div id="content"></div>
<div id="footer"></div>
</div>
But when I see the result, the divs which are in the term div have some space between each other. Setting the padding and margin to zero doesn't remove the space.
What should I do to remove the space to set the divs exactly near to each other?
One solution is to use in term container display: flex:
body {
background: url("../imgs/bg_pattern.gif") scroll 0 0% repeat, url("../imgs/1.jpg") no-repeat scroll 0 0% / 100% 100%;
margin: auto;
}
#panel {
height: 100%;
width: 300px;
background-color: #232325;
float: right;
}
#audio {
width: 100%;
height: 11%;
background-color: red;
}
#term {
width: 100%;
height: 11%;
background-color: blue;
display: flex;/*Add display flex*/
}
#content {
width: 100%;
height: 67%;
background-color: green;
}
#footer {
width: 100%;
height: 11%;
background-color: pink;
}
.term {
background-color: black;
height: 100%;
width: 25%;
display: inline-block;
border-right: solid red;
}
.term:first-child {
margin-left: 0;
}
.term:last-child {
border-right: none;
}
<div id="panel">
<div id="header">
<div id="audio"></div>
<div id="term">
<div class="term">asd</div>
<div class="term">asd</div>
<div class="term">asd</div>
<div class="term">asd</div>
</div>
</div>
<div id="content"></div>
<div id="footer"></div>
</div>
Reference
flex
the problem is that Inline-block have some default spaces ,
use Float to left better than Inline-block and use a clearfix class :
#term{
width: 100%;
height: 11%;
background-color: blue;
**overflow: hidden;**
}
.term{
background-color: black;
height: 100%;
width: 25%;
**float : left ;**
border-right: solid red;
}
http://jsfiddle.net/n0zxmgoy/
As stated earlier, any white space between inline blocks is retained in the layout, so one way
of getting rid of it is to make sure that the inline block elements have no intervening space
in the HTML mark-up.
Also, you need to set a reference height so that the height percentage values work as expected.
I did this by adding height: 100% to the html and body tags.
Also, make sure to add a height value to the #header element, which makes the arithmetic
a bit easier to deal with.
A subtle point involves the right border on the .term elements. You can either use the
CSS calc value or box-sizing: border-box, you can try either.
html, body {
height: 100%; /* this may be needed... */
}
body{
background: url("../imgs/bg_pattern.gif") scroll 0 0% repeat, url("../imgs/1.jpg") no-repeat scroll 0 0% / 100% 100%;
margin: auto;
}
#panel{
height: 100%;
width: 300px;
background-color: #232325;
float: right;
}
#header {
width: 100%;
height: 22%;
}
#audio{
width: 100%;
height: 11%;
background-color: red;
}
#term{
width: 100%;
height: 50%;
background-color: blue;
}
#content{
width: 100%;
height: 67%;
background-color: green;
}
#footer{
width: 100%;
height: 11%;
background-color: pink;
}
.term{
background-color: black;
height: 100%;
width: calc(25% - 2px);
/* box-sizing: border-box; optional alternative */
display: inline-block;
border-right: 2px solid red;
}
.term:first-child{
margin-left: 0;
}
.term:last-child{
border-right: none;
width: 25%; /* you need to consider this... */
}
<div id="panel">
<div id="header">
<div id="audio"></div>
<div id="term">
<div class="term"></div><div class="term"></div><div class="term"></div><div class="term"></div>
</div>
</div>
<div id="content"></div>
<div id="footer"></div>
</div>

have 3 divs to each other with spacers in between

I have 3 divs that I want next to each other on my page. If the container is 700px in width, they all connect well. But I want to have a max width of 800px on my container. And in that case, I want all my divs to space out (1st div to the left, 2nd div in the center and 3rd div on the right). I need to connect those divs with 2 spacers that I've got (1 to connect div 1 and 2. The other to connect 2 and 3).
Once I have achieved that, I want a second div (content) to float above the first div (background). But I have already achieved that.
I have tried a few things, but I can't find a solution, if anyone could help me, I would appreciate it!
Here are my code snippet:
* {
margin: 0;
padding: 0;
}
.container {
width: 800px;
margin: 0 auto;
background: #efefef;
height: 800px;
}
.content {
position: relative;
z-index: 100;
top: 0;
}
.background {
position: absolute;
z-index: 0;
top: 0;
width: inherit;
}
.bg-left {
height: 190px;
width: 268px;
background: url(images/left-1.png);
float: left;
}
.bg-left-spacer {
height: 190px;
width: 1px;
background: url(images/left-spacer.png);
float: left;
}
.bg-connector {
height: 190px;
width: 133px;
background: url(images/connector.png);
float: left;
margin: 0 auto;
}
.bg-right-spacer {
height: 190px;
min-width: 1px;
background: url(images/right-spacer.png);
float: left;
background-repeat: repeat-x;
}
.bg-right {
height: 190px;
width: 297px;
background: url(images/right-1.png);
float: left;
}
<div class='container'>
<div class='content'>
<h1>testheader</h1>
<p>testtext</p>
</div>
<div class='background'>
<div class='bg-left'></div>
<div class='bg-left-spacer'></div>
<div class='bg-connector'></div>
<div class='bg-right-spacer'></div>
<div class='bg-right'></div>
</div>
</div>
You could achieve it like this:
JSFiddle - DEMO
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
position: relative;
min-width: 700px;
max-width: 800px;
margin: 0 auto;
background: #efefef;
height: 800px;
}
.content {
position: relative;
z-index: 100;
top: 0;
}
.background {
position: absolute;
width: 100%;
z-index: 0;
top: 0;
display: table;
table-layout: fixed;
}
.bg-left {
height: 190px;
width: 268px;
background: url(images/left-1.png);
border: 1px solid #000;
display: table-cell;
}
.bg-connector {
height: 190px;
width: 133px;
background: url(images/connector.png);
border: 1px solid #000;
display: table-cell;
}
.bg-right {
height: 190px;
width: 297px;
background: url(images/right-1.png);
border: 1px solid #000;
display: table-cell;
}
.space {
display: table-cell;
width: 100%;
height: 190px;
background: #F00;
}
<div class='container'>
<div class='content'>
<h1>testheader</h1>
<p>testtext</p>
</div>
<div class='background'>
<div class='bg-left'></div>
<div class="space"></div>
<div class='bg-connector'></div>
<div class="space"></div>
<div class='bg-right'></div>
</div>
</div>
You should use percantages to achieve that:
.bg-left {
height: 190px;
width: calc( 100% / 3 - 1px );
background: url(images/left-1.png);
}
This way .bg-left is 33.3% in width -1px for the spacer.
DEMO: http://jsfiddle.net/6aor5u4m/

fill remaining space with div width auto

hey guys thanks for the upcoming support how do I set the blue to fill up the remaining width of the whole maininfo div? I tried setting the width:auto
<div class="maininfo">
<div class="large">2</div>
<div class="smallblock">
<div class="smalltop">3</div>
<div class="small">4</div>
</div>
<div class="smallblock">
<div class="smalltop">5</div>
<div class="small">6</div>
</div>
</div>
.maininfo {
width: 600px;
}
.large {
float: left;
height: 95px;
background-color: blue;
width:auto;
}
.smallblock {
float: right;
height: 90px;
margin: 0 0 0 5px;
width: 20%;
}
.small {
background-color: red;
height: 50%;
width: 100%;
}
.smalltop {
background-color: red;
height: 50%;
width: 100%;
margin-bottom:5px;
}
UPDATED MY JFIDDLE BUT NOW IT MAKES 2 LINES: http://jsfiddle.net/4ykf5frk/11/
If just .maininfo, merely add a 'background: blue;' property to your style declaration:
.maininfo {
background-color: blue;
width: 600px;
}
Otherwise, just add a 'background: blue;' property for the 'body' element:
body {
background-color: blue;
}

How do I define a content 100% while having a sidebar?

I have this structure for my website as below. How do I define red area as 100%, while it has a sidebar with 260px width and the sidebar is fixed.
If you can use CSS3 you can use calc:
#wrapper {
width: calc(100% - 260px);
}
#sidebar {
width: 260px;
}
#sidebar {
position: fixed;
width: 260px;
}
#wrapper {
width: 100%;
box-sizing: border-box;
padding-left: 260px;
}
Please see if this will work for you:
Demo: http://jsfiddle.net/dDULw/2/
HTML
<div id="outer">
<div id="sidebar">
sidebar
</div>
<div id="wrapper">
wrapper
</div>
</div>
CSS
#outer {
overflow: hidden;
border: 3px solid #000;
width: 600px;
height: 300px;
}
#sidebar {
float: left;
border: 5px solid blue;
width: 130px;
height: 250px;
}
#wrapper {
overflow: hidden;
border: 5px solid red;
height: 250px;
}

How to get this 2 columns layout (were one fits to content)

Please note
the vertical scrollbars should show up when needed
left columns fits to width
right column takes the rest of the space
Here is one approach that uses CSS only.
The HTML looks like:
<div id="pageWrapper">
<header>Header</header>
<div id="contentWrapper">
<div class="table-wrap">
<div class="cell col1">
<div class="content">Column 1: Shrink-to-Fit Width</div>
</div>
<div class="cell col2">
<div class="content">Column 2: Variable Width</div>
</div>
</div>
</div>
<div id="footerWrapper">Footer</div>
</div>
and the CSS:
html, body {
height: 100%;
margin: 0;
}
body {
background-color: #E3E3E3;
}
#pageWrapper {
margin: 0 auto;
position: relative;
width: 90%; /*set to 100% or smaller or fixed width... */
height: 100%;
}
header {
display:block;
width: 100%;
height: 100px;
background: yellow;
}
#contentWrapper {
width: 100%;
position: absolute;
top: 100px;
bottom: 100px;
left: 0;
background: beige;
}
#footerWrapper {
width: 100%;
position: absolute;
height: 100px;
bottom: 0px;
left: 0;
background: gray;
}
.table-wrap {
width: 100%;
height: 100%;
}
.table-wrap .cell {
height: 100%;
}
.table-wrap .col1 {
float: left;
border: 1px dotted blue;
max-width: 80%; /* This is critical or else Column 2 can disappear */
}
.table-wrap .col1 .content {
height: inherit;
display: inline-block;
overflow-y: auto;
}
.table-wrap .col2 {
}
.table-wrap .col2 .content {
height: inherit;
overflow-y: auto;
}
See demo at: http://jsfiddle.net/audetwebdesign/kbAwf/
How This Works
Use absolute positioning to place the header, main content area and footer within the view port area.
Within the content area (#contentWrapper), the .table-wrap container has two cells, one which is floated left (column 1). This allows column 2 to fill the rest of the width.
To get the shrink-to-fit width for column 1, set display: inline-block to the inner .content container.
Finally, use overflow-y: auto for the scroll bars. (You can also use the scroll value.)
You need to set a maximum width to .col1 so that .col2 does not get pushed out of the view port. I set it to 80% but you can adjust it.
Also, note that an inline-block will expand as much as possible to flow its content, which is why you need to constrain it.
You man want to set a minimum width on #pageWrapper to prevent the layout from shrinking to something that is less than useful.
Like this
DEMO1
DEMO1 CSS
html, body {
height:100%;
}
header{
width: 100%;
background: yellow;
position: fixed;
top: 0;
height: 60px !important;
opacity:.8;
}
.content {
position:relative;
height: 100%;
/*width:600px; Sizing - any length */
padding:60px 0 30px 0; /* Header height and footer height */
margin:0 auto 0 auto; /* Center content */
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
-o-box-sizing:border-box;
-ms-box-sizing:border-box;
box-sizing:border-box;
}
.sidebar1, .sidebar2 {
background: red;
top:60px;
bottom:30px;
width: 70%;
position:absolute;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
-o-box-sizing:border-box;
-ms-box-sizing:border-box;
box-sizing:border-box;
overflow-y:scroll;
}
.sidebar1 {
left:0;
width:30%;
}
.sidebar2 {
right: 0;
}
#scrollable2 {
background:green;
height: 100%;
min-width: 300px;
margin-left: 100px;
margin-right: 100px;
overflow:auto;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
-o-box-sizing:border-box;
-ms-box-sizing:border-box;
box-sizing:border-box;
}
footer {
width: 100%;
background: yellow;
position: fixed;
bottom: 0;
height: 30px;
}
DEMO2
HTML
<div class="main">
<div class="header"></div>
<div class="mid">
<div class="left"></div>
<div class="right"></div>
</div>
<div class="footer"></div>
</div>
CSS
body, html {
width: 100%;
height: 100%;
background-color: black;
padding: 0;
margin: 0;
}
.main {
background-color: white;
top: 4px;
left: 4px;
right: 4px;
bottom: 4px;
}
.main, .header, .left, .right, .mid, .footer {
position: absolute;
}
.header {
height: 100px;
top: 0px;
left: 0px;
right: 0px;
border-bottom: 4px solid black;
}
.mid {
top: 104px;
left: 0px;
right: 0px;
bottom: 14px;
}
.left {
overflow-y:auto;
width: 100px;
top: 0px;
bottom: 0px;
}
.right {
overflow-y:auto;
top: 0px;
bottom: 0px;
left: 100px;
right: 0px;
border-left: 4px solid black;
}
.footer {
left: 0px;
right: 0px;
bottom: 0px;
height: 10px;
border-top: 4px solid black;
}
Working Fiddle (as shown in your post)