I'm trying to create the following layout for my website:
<table width="80%" align="center">
<tr>
<td width="80%" bgcolor="red">MAIN CONTENT</td>
<td bgcolor="green">SIDEBAR</td>
</tr>
</table>
As you would imagine this will create a table that is 80% of the page width and the content area is 80% of that width, while the sidebar fills the rest.
But this time I want to use DIVs or SPANs or basically a TABLEless design. Now, I know I can use two DIVs and use their "float" properties to achieve this but I was hoping to see if there is something more simple and more logical like this:
<div align="center" style="width:80%">
<span style="width:80%;">
MAIN CONTENT
</span>
<span>
SIDEBAR
</span>
</div>
Unfortunately the above does not work at all and I don't know why. Can someone please show me the purest HTML implementation for it which does not use "float"?
Every site I see on the internet nowadays has at least one sidebar so I'm hoping your answer to this will help a lot of people besides me. Thanks!
You can do this without using floats by using proper markup and display: table;, display: table-cell; with CSS.
HTML:
<div id="wrap">
<div id="sidebar">
I am a sidebar!
</div>
<div id="mainContent">
I am some main content
</div>
</div>
CSS:
#wrap
{
width: 100%;
height: 400px;
display: table;
}
#sidebar
{
display: table-cell;
border: 1px dashed #f00;
}
#mainContent
{
display: table-cell;
width: 80%;
border: 1px dashed #0f0;
}
But beware, IE7 and lower do not support this CSS.
http://jsfiddle.net/57Fvk/
Using almost the same markup (one extra div) you can use floats to create the desired layout also:
HTML
<div id="wrap">
<div id="sidebar">
I am a sidebar!
</div>
<div id="mainContent">
I am some main content
</div>
<div class="clear"> </div>
</div>
CSS:
#wrap
{
width: 100%;
height: 400px;
}
#sidebar
{
width: 20%;
float: left;
background: #f00;
height: 100%;
}
#mainContent
{
width: 80%;
float: left;
background: #0f0;
height: 100%;
}
.clear
{
clear: both;
}
http://jsfiddle.net/shzLc/
Here's a very simple way to create this layout:
http://jsfiddle.net/e94zc/
HTML:
<div id="page">
<div id="content">
Content
</div>
<div id="sidebar">
Sidebar
</div>
</div>
CSS:
#page{
margin: 0 auto;
width:80%;
position: relative;
}
#content{
width:80%;
position: absolute;
top: 0;
}
#sidebar{
position: absolute;
top: 0;
left: 80%;
width: 20%;
}
Related
I'm trying to recreate: http://jsfiddle.net/MGRdP/6/
html, body{
height:100%;
}
.table {
width: 100%;
display: table;
height:100%;
}
.cell {
border: 2px solid black;
vertical-align: middle;
display: table-cell;
height:100%;
}
<div class="table">
<div class="cell">
<p>Text</p>
</div>
</div>
<div class="table">
<div class="cell">
<p>Text</p>
</div>
</div>
using Neat but my divs are not expanding to 100% of the viewport height. Using inspector, I cannot find any discrepancies. Obviously something is off here.
Can someone provide correct markup for neat that allows me to achieve the as the fiddle?
If you want two divs side by side (like the Fiddle), just make each one width:50% and float:left
html, body{
height:100%;
}
.table {
width: 50%;
display: table;
height:100%;
float:left;
}
.cell {
border: 2px solid black;
vertical-align: middle;
display: table-cell;
height:100%;
}
<div class="table">
<div class="cell">
<p>Text</p>
</div>
</div>
<div class="table">
<div class="cell">
<p>Text</p>
</div>
</div>
.table {
width: 50%;
display: table;
height:100%;
float:left;
}
this css make two div to stay side by side.
You can also use
display:inline-block;
vertical-align:top;
width:49%;
to make side by side layout;
To center content use margin:0 auto for child
and two make height as view port use-
height:100vh
jsfiddle link
I'm trying to convert my website from table layout to div layout,
while with the table layout everything was more intuaitive, I get stuck every minute with this div layout, here's my current problem -
I want the text in my left div to be padded from the left and from the top.
If I pad the left DIV itself, the whole div gets expanded (even though the container div has a 700px width defined for it); If I try to margin the text itself, for some reason it only works for creating the left margin, but it doesn't effect the top margin which stays at 0px.
here's my code:
<div id="container">
<div id="left">I want some padding here
<div id="image">image</div>
</div>
<div id="middle"></div>
<div id="right">
<div id="text">Text</div>
</div>
<br style="clear: left;" />
</div>
CSS:
#container {
border: 1px solid #DCD7D4;
width: 700px;
min-height: 680px;
position: relative;
margin-left: auto;
margin-right: auto;
}
#left {
float:left;
width: 500px;
min-height: 680px;
background-color: #F6F1ED;
}
#left #image {
position: absolute;
left: 27px;
bottom: 40px;
background: green;
width: 375px;
height: 48px;
}
#right {
float: left;
width: 194px;
min-height: 680px;
background-color: #F2EEEF;
}
#right #text {
position: absolute;
left: 523px;
top: 154px;
background: yellow;
width: 150px;
height: 70px;
}
#middle {
float:left;
background: #0C9;
background-image:url(midbg.png);
width: 6px;
min-height: 680px;
}
You can add padding to your #left div together with box-sizing: border-box and the layout should remain in tact
#left
{
padding: x px;
-moz-box-sizing: border-box;
box-sizing: border-box
}
Read up on the CSS box model here: http://css-tricks.com/the-css-box-model/
Padding will affect your overall element's specs.
ALSO, this is a great trick for dealing with funky padding of various elements:
http://www.paulirish.com/2012/box-sizing-border-box-ftw/
How about either of these solutions. They work on my browser:
<div id="container">
<div id="left"><span style="padding-left: 10px; padding-top: 10px">I want some padding here</span>
<div id="image">image</div>
</div>
<div id="middle"></div>
<div id="right">
<div id="text">Text</div>
</div>
<br style="clear: left;" />
</div>
OR
<div id="container">
<div id="left"><div style="padding-left: 10px; padding-top: 10px">I want some padding here</div>
<div id="image">image</div>
</div>
<div id="middle"></div>
<div id="right">
<div id="text">Text</div>
</div>
<br style="clear: left;" />
</div>
if border-box is not working then span should work for you, check this demo
CSS
#left > span {
padding:100px;
position:absolute;
height:100%;
border:1px solid #000;
}
HTML
<div id="left">
<span>I want some padding here</span>
<!-- rest of html -->
`
EDIT
Since, your #left has child divs inside, you can not apply padding option to it.
padding is required on text directly under #left id and not a child div,so, span is suggested as <span> is an inline element and <div> is block level element.
So here's my HTML:
...
<div class="header">
<div class="left">
</div>
<div class="center">
<img class="logo" src="linktomyimage.com/image.png" />
</div>
<div class="right">
</div>
</div>
<!-- And the desired result is: -->
[ [LEFT] [CENTER] [RIGHT] ]
The only CSS I have is:
* {
margin: 0px;
}
img.logo {
display: block; margin-left: auto; margin-right: auto;
}
I really need help to align the three divs on the whole page. Also div.center must have the same size as the image, aka width - 800px and height - 600px.
It looks much more like a table than divisions to me...
<table class="header"><tr>
<td class="left"></td>
<td class="center">
<img class="logo" src="linktomyimage.com/image.png" />
</td>
<td class="right"></td>
</tr></table>
Think about so CSS afterwards :
table.header{
width: 100%;
border-collapse: collapse;
}
table.header td{
vertical-align: top;
border: 1px solid #404040;
}
table.header td.center{
width: 800px;
height: 600px;
}
This is just a code sample, get the idea, and adapt to your own needs ^^
Add these classes to your css
.left
{
display:inline-block;
width:25%;
}
.center
{
display:inline-block;
width:50%;
}
.right
{
display:inline-block;
width:25%;
}
With the following markup, 2 solutions come to mind:
MARKUP
<div class="header">
<div class="left">
Some left test
</div>
<div class="center">
<img class="logo" src="http://placehold.it/50x50" />
</div>
<div class="right">
Some right text
</div>
</div>
Solution #1
Float left and right sides and use display-block on the center
FIDDLE
Css
.header
{
text-align: center;
width:100%;
}
.left
{
float:left
}
.right
{
float:right;
}
.center
{
display:inline-block;
}
Solution #2
Use text-align: justify; on the header element.
Then stretch the content to take up 100% width
FIDDLE
CSS
.header
{
text-align: justify;
width:100%;
}
.header > div
{
display: inline-block;
}
.header:after {
content: '';
display: inline-block;
width: 100%;
}
.left, .centre, .right {
float:left;
}
What float:left does is, is it'll make each container organize itself from the left, so you get:
[LEFT]-[CENTRE]-[RIGHT]
I'm having an issue with stretching div A based on the height of div B, OR stretching div B based on the heigt of div A (depends which has the most content).
I tried looking into faux columns, but as my divs aren't in the same 'holder' this can't work... My current code looks like this:
<div id="header">
<div id="content">CONTENT HEADER</div>
</div>
<div id="content">
<div id="column-left">
<p>INHOUD LINKER KOLOM</p>
<p> </p>
</div>
<div id="column-right">
<p>INHOUD RECHTER KOLOM</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<div class="clear"></div>
</div>
<div id="main">
<div id="content">
<div id="main-content">
<p>HOOFD INHOUD </p>
<p> </p>
<p> </p>
<p> </p>
</div>
</div>
<div class="clear"></div>
</div>
<div id="footer">
<div id="content">CONTENT FOOTER</div>
</div>
With as CSS the following:
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.clear {
clear: both;
}
#content {
position: relative;
width: 950px;
margin-left: auto;
margin-right: auto;
z-index: 10
}
#header {
position: relative;
min-width: 990px;
width: 100%;
height: 90px;
background-color: #F00;
}
#column-left {
width: 500px;
float: left;
background-color: #0F0;
}
#column-right {
width: 450px;
float: right;
background-color: #00F;
position: absolute;
margin-left: 500px;
}
#main {
min-width: 990px;
width: 100%;
background-color: #FF0;
}
#main-content {
width: 500px;
float: left;
}
#footer {
min-width: 990px;
width: 100%;
height: 90px;
background-color: #F00;
}
In my example you will see that I made the 'blue' div's content longer whereas I would like to have the 'yellow' div to stretch (so the footer will be below them both)
The other way around would also be applicable (if the 'yellow' div would contain more content, the 'blue' div should stretch... Although this can be solved with faux columns if I give a 'yellow-blue' image as background to the 'blue' div).
An example as image: http://tinypic.com/view.php?pic=jjpx0k&s=6
Can someone help me with this?
Any help would be much appreciated!
I looked at your code and you really can't achieve what you want to do because the blue div is in absolute.
The only way of doing this is by using jquery and detecting the height of the blue div and then adding margin or height to the yellow div to make the space so that the footer appears to be under the blue div...
I hope this helps.
can you please help me with some css magic.
I am trying to achieve a flixable multi column layout. something like this http://masonry.desandro.com/demos/basic-multi-column.html can I achive this with Blueprint and no javascript.
the thing with blueprint now is that is added lots of white space (see attachment)
Following is just sample one.. You just change width/height according to your requirement. Hope this helps.
CSS
----
.content {
float: left;
display: block;
width: 1000px;
background: red;
}
.sub-content {
float:left;
width: 200px;
background: blue;
margin: 10px;
}
Sample HTML
-----------
<div class="content">
<div class="sub-content" style="width: 500px; height: 300px;">
DIV 1
</div>
<div class="sub-content" style="width: 200px; height: 100px;">
DIV 2
</div>
<div class="sub-content" style="width: 500px; height: 300px;">
DIV 3
</div>
<div class="sub-content" style="width: 250px; height: 300px;">
DIV 4
</div>
</div>