im trying to float 4 divs side by side. they are in a parent div width = 100% and each child div is width:25% there is no margin or padding either... they are not displaying correctly!
heres the code...
<div id="bottomsections">
<div id="1a">
<h1>a</h1>
<p>This is Photoshop's version of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis sed odio sit amet nibh vulputate cursus a sit amet mauris. Morbi accumsan ipsum velit. Nam nec tellus a odio tincidunt auctor a ornare odio. Sed non mauris vitae erat consequat</p>
</div>
<div id="1b">
<h1>b</h1>
<p>This is Photoshop's version of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis sed odio sit amet nibh vulputate cursus a sit amet mauris. Morbi accumsan ipsum velit. Nam nec tellus a odio tincidunt auctor a ornare odio. Sed non mauris vitae erat consequat</p>
</div>
<div id="1c">
<h1>c</h1>
<p>This is Photoshop's version of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis sed odio sit amet nibh vulputate cursus a sit amet mauris. Morbi accumsan ipsum velit. Nam nec tellus a odio tincidunt auctor a ornare odio. Sed non mauris vitae erat consequat</p>
</div>
<div id="1d">
<h1>d</h1>
<p>This is Photoshop's version of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis sed odio sit amet nibh vulputate cursus a sit amet mauris. Morbi accumsan ipsum velit. Nam nec tellus a odio tincidunt auctor a ornare odio. Sed non mauris vitae erat consequat</p>
</div>
and css...
#bottomsections {
width:100%;
}
#1a {
width:25%;
float:left;
margin:0;
padding:0;
}
#1b {
width:25%;
float:left;
margin:0;
padding:0;
}
#1c {
width:25%;
float:left;
margin:0;
padding:0;
}
#1d {
width:25%;
float:left;
margin:0;
padding:0;
}
heres the fiddle..http://jsfiddle.net/aM2UL/1/
thanks!
Id can not start with a number:
/* change #1a to #a1 */
#a1 {
width:25%;
float:left;
margin:0;
padding:0;
}
http://jsfiddle.net/dfsq/aM2UL/3/
Refer this comprehensive answer about what characters are allowed: https://stackoverflow.com/a/449000/949476
Upd: As pointed by Allendar in comments you should also clear your floats. You can insert one more element after your floated divs with clear: both. Personally I use .clearfix class as more semantic:
.clearfix:before,.clearfix:after{content:"";display:table}
.clearfix:after{clear:both}
to be used as <div id="bottomsections" class="clearfix">...</div>
You certainly can use numbers to start IDs, but you have to select them differently.
[id="1a"], [id="1b"], [id="1c"], [id="1d"] {
width:25%;
float:left;
margin:0;
padding:0;
}
http://jsfiddle.net/aM2UL/11/
id's cannot start with numbers in any revision of HTML and/or CSS, also, all 4 of your styles are the same, so you would be better off using a class such as
div.inner {
width:25%;
float:left;
margin:0;
padding:0;
}
and set <div id="1d" class="inner">
this will keep your code smaller and more manageable and mean less changes if and when you need to do anything else to the code later on.
#bottomsections div{ float:left; width:25%}
As others have said, numbers aren't valid beginnings to ids
ids cant start with a number, try to change for #a1, or something. but if you want to apply the same properties in all divs of you main div, why you not do this way?
#bottomsections div{
width:25%;
float:left;
margin:0;
padding:0;
}
Related
I have a scrollable div and I want to put a message above it. I'm doing this by offsetting the content in the scrollable div by 30px and adding a position:absolute div that's 30px tall to the top. However, I'm running into the problem where this div covers the scroll bar of the div below it. How can I put a message at the top of a scrollable div without it covering the scroll bar?
Here is a quick example of my code. Note the scroll bar is covered by the red div:
http://jsfiddle.net/S4mXy/1
The following style of css helps you. you should have to add z-index to the sticky
#sticky
{
width:200px;
height:30px;
background-color:rgba(255, 0, 0, 0.39);
position:absolute;
z-index:-1;
}
You need to have both DIVs either absolute or relative. I moved the sticy div outside the scrollable div and removed the absolute positioning and it fixed it http://jsfiddle.net/S4mXy/3/
HTML:
<div id="sticky"></div>
<div id="scrollable">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut at felis dolor. Cras et sagittis leo. Aenean facilisis rutrum odio, in volutpat ante pulvinar nec. Fusce pulvinar magna in consequat consequat. Vivamus hendrerit adipiscing magna quis malesuada. Sed metus odio, gravida quis purus in, lobortis facilisis ligula. Donec ac tristique nibh, ullamcorper feugiat diam. Integer rhoncus vehicula ornare. Aenean ut posuere lectus. Mauris in enim posuere, volutpat erat at, blandit sapien. Cras quis adipiscing quam. Donec convallis elementum est, vitae placerat ante scelerisque ut. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut at felis dolor. Cras et sagittis leo. Aenean facilisis rutrum odio, in volutpat ante pulvinar nec. Fusce pulvinar magna in consequat consequat. Vivamus hendrerit adipiscing magna quis malesuada. Sed metus odio, gravida quis purus in, lobortis facilisis ligula. Donec ac tristique nibh, ullamcorper feugiat diam. Integer rhoncus vehicula ornare. Aenean ut posuere lectus. Mauris in enim posuere, volutpat erat at, blandit sapien. Cras quis adipiscing quam. Donec convallis elementum est, vitae placerat ante scelerisque ut.
</p>
</div>
CSS #1:
#scrollable
{
width:200px;
height:400px;
overflow-y:scroll;
}
#scrollable p
{
margin-top:30px;
}
#sticky
{
width:200px;
height:30px;
background-color:rgba(255, 0, 0, 0.39);
}
Or, make them both absolute http://jsfiddle.net/S4mXy/4/ :
CSS #2:
#scrollable
{
position:absolute;
top:35px;
width:200px;
height:400px;
overflow-y:scroll;
}
#scrollable p
{
margin-top:30px;
}
#sticky
{
position:absolute;
width:200px;
height:30px;
background-color:rgba(255, 0, 0, 0.39);
}
I'm building a 3 row liquid layout. I have a fixed height header and a footer. I also have a minimum width for the wrapper (for these 3 rows).
The problem is, I can't make the middle one (#content) resize vertically. If I make position:absolute then I lose control over scrolling. I thought I could do it using the top,bottom,margin and padding while setting the height to 100% but I couldn't.
Here's the code that I'm using to test it and here's the fiddle link: http://jsfiddle.net/inhan/kUZgY/ You will see that the lighter gray background won't expand when window is resized.
I'm willing to use CSS only and not use HTML5 features. What am I missing? Thanks for any input.
CSS
body {
margin:0;
padding:0;
border:0;
height:100%;
max-height:100%;
}
* html body { /*IE6 hack*/
padding:30px 0;
}
* html #content { /*IE6 hack*/
height:100%;
width:100%;
}
#wrapper {
width:100%;
min-width:800px;
min-height:100%;
position:absolute;
}
#header, #footer {
position:absolute;
left:0;
width:100%;
height:30px;
overflow:hidden;
background-color:gray;
color:white;
}
#header {
top:0;
}
#footer {
bottom:0;
}
#content {
margin:31px 0;
overflow:hidden;
width:100%;
background:rgba(0,0,0,.2);
}
HTML
<body>
<div id="wrapper">
<div id="header">This is header</div>
<div id="footer">This is footer</div>
<div id="content">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Suspendisse id velit vitae ligula volutpat condimentum. Aliquam erat volutpat. Sed quis velit. Nulla facilisi. Nulla libero. Vivamus pharetra posuere sapien. Nam consectetuer. Sed aliquam, nunc eget euismod ullamcorper, lectus nunc ullamcorper orci, fermentum bibendum enim nibh eget ipsum. Donec porttitor ligula eu dolor. Maecenas vitae nulla consequat libero cursus venenatis. Nam magna enim, accumsan eu, blandit sed, blandit a, eros.<br/><br/>Quisque facilisis erat a dui. Nam malesuada ornare dolor. Cras gravida, diam sit amet rhoncus ornare, erat elit consectetuer erat, id egestas pede nibh eget odio. Proin tincidunt, velit vel porta elementum, magna diam molestie sapien, non aliquet massa pede eu diam. Aliquam iaculis. Fusce et ipsum et nulla tristique facilisis. Donec eget sem sit amet ligula viverra gravida. Etiam vehicula urna vel turpis. Suspendisse sagittis ante a urna. Morbi a est quis orci consequat rutrum. Nullam egestas feugiat felis. Integer adipiscing semper ligula. Nunc molestie, nisl sit amet cursus convallis, sapien lectus pretium metus, vitae pretium enim wisi id lectus. Donec vestibulum. Etiam vel nibh. Nulla facilisi. Mauris pharetra. Donec augue. Fusce ultrices, neque id dignissim ultrices, tellus mauris dictum elit, vel lacinia enim metus eu nunc.
</div>
</div>
</body>
Extra Info
I'm actually not really interested in setting a minimum width for the whole page but some middle content will need that. So if I can, I might wanna make the whole structure respect when there's min-width property in the content that is loaded.
This should be what you're after http://jsfiddle.net/kUZgY/6/
You were just missing html {height:100%;}
I also changed the #header and #footer to position:fixed
I recreated my issue here.
The problem is that the 'left' div should be matching the combined height of 'top' and bottom' right divs. I have been reading articles and tutorials on how to achieve equal height with columns of varying content but none of them seem to apply to the 'stacked' columns.
My current nonworking solution was built on a concept taken from this article:
The only way to make the height of a div equal to the tallest column
is if that div contains all the columns. So to explain this another
way, by placing the columns inside a container we cause the container
to be the height of the tallest column. This is a very useful
structure. For this structure to work correctly in all browsers the
container div must be floated (left or right) plus each of the column
content divs must also be floated, it does not matter which way.
I am aware of the equalHeights jQuery plugin and resize, but I would very much prefer CSS solutions.
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div id='container'>
<div id='height-container'>
<div id='left'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque faucibus, nunc non semper fringilla, nibh mauris aliquam diam, sit amet suscipit purus ligula eu odio. Nulla tortor neque, sodales nec placerat vitae, laoreet a mi. In ac ullamcorper dui. Sed enim tellus, volutpat at tristique eu, condimentum volutpat tellus. Integer massa quam, egestas id vulputate id, ultrices ut felis.
</div>
<div id='right'>
<div id='top'>
Proin condimentum purus tortor, eu laoreet velit. Praesent ornare, mauris eu laoreet suscipit, nibh mauris imperdiet dolor, ut molestie erat tellus ac odio. Etiam tempor eros at neque tincidunt a feugiat massa imperdiet. Vestibulum aliquet nibh sit amet urna facilisis condimentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In ornare dolor quis neque aliquet lacinia et id tortor. Fusce eu sapien non mi aliquet condimentum id vitae ante. Phasellus sit amet eros vitae velit fringilla facilisis non at eros. In non venenatis lectus. Nam tortor tellus, vehicula non vulputate vitae, mollis a velit. Pellentesque gravida pretium ante, eu volutpat risus viverra non. Duis purus quam, venenatis nec consectetur interdum, aliquam rutrum diam. Donec interdum odio eget ante consectetur in sodales mi molestie. Nunc bibendum, turpis vel vulputate accumsan, diam tortor placerat sem, sed posuere risus purus eu massa. Nullam eleifend pulvinar massa, nec cursus velit dictum quis.
</div>
<div id='bottom'>
Praesent vel porttitor dolor. Nulla vel nisl quis nibh bibendum rutrum. In gravida lacus a tellus tempus at pretium quam iaculis. Quisque fringilla feugiat urna, ac tincidunt tellus ornare et. Aenean sit amet turpis at ante molestie accumsan. Duis vestibulum, tortor nec aliquam tincidunt, leo urna tincidunt nunc, et laoreet metus risus quis erat. Proin at sem leo, sit amet bibendum quam. Vivamus quam urna, pulvinar vel tempor eget, facilisis tristique ipsum. Aenean sed ipsum et odio convallis congue a sit amet leo. Morbi luctus odio a felis pellentesque sit amet cursus ante consectetur. <br><br>
Praesent vel porttitor dolor. Nulla vel nisl quis nibh bibendum rutrum. In gravida lacus a tellus tempus at pretium quam iaculis. Quisque fringilla feugiat urna, ac tincidunt tellus ornare et. Aenean sit amet turpis at ante molestie accumsan. Duis vestibulum, tortor nec aliquam tincidunt, leo urna tincidunt nunc, et laoreet metus risus quis erat. Proin at sem leo, sit amet bibendum quam. Vivamus quam urna, pulvinar vel tempor eget, facilisis tristique ipsum. Aenean sed ipsum et odio convallis congue a sit amet leo. Morbi luctus odio a felis pellentesque sit amet cursus ante consectetur.
</div>
</div>
</div>
</div>
</body>
</html>
CSS:
body{
text-align:justify;
}
#container{
width:1000px;
margin:0 auto;
}
#height-container{
background:orange;
float:left;
}
#left{
float:left;
width:200px;
background:#CD5555;
padding:20px;
}
#right{
width:600px;
float:right;
}
#top{
background:yellow;
padding:20px;
}
#bottom{
background:#00FF66;
padding:20px;
}
You can use display:table property for this:
#height-container{
background:orange;
display: table;
vertical-align:top;
}
#left{
display: table-cell;
width:200px;
background:#CD5555;
padding:20px;
}
#right{
width:600px;
display: table-cell;
}
Check this http://jsfiddle.net/6rBAw/2/
But it's work till IE8 & above
UPDATED
CSS
#left{
width:200px;
background:#CD5555;
}
#right{
float:right;
width:600px;
}
.clr{clear:both;}
HTML
<div id='right'></div>
<div id='left'>
<div class="clr"></div>
</div>
Check it http://jsfiddle.net/6rBAw/4/
Here is a solution which works in IE 7 as well http://jsfiddle.net/6rBAw/6/ this solution makes use of negative margin bottom and padding bottom, the only thing is you have to give the margin bottom and padding bottom value the same and a large value and give the container of the column overflow hidden property.
#container{
width:1000px;
margin:0 auto;
**overflow: hidden;**
}
#left{
float:left;
width:200px;
background:#CD5555;
**padding:20px 20px 99999px 20px;
margin-bottom: -99999px;**
}
#right{
width:600px;
float:right;
**padding-bottom: 99999px;
margin-bottom: -99999px;**
background-color: black;
height: 1000px;
}
Alright so my problem is that I can't get the center div to dynamically set its width based on browser width and still float in between the two divs.
<style type="text/css">
#container{width:100%;}
#left{min-height:70px;width:60px;float:left;}
#middle{min-height:70px;width:100%;float:left;}
#right{min-height:70px;width:60px;float:right;}
</style>
<div id="container">
<div id="left">text</div>
<div id="middle">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur fringilla enim eget augue pretium facilisis. Quisque euismod mauris eu odio tincidunt pharetra interdum enim dignissim. Phasellus eleifend viverra diam, et vestibulum orci feugiat vitae. Fusce rhoncus, dolor sit amet rhoncus pulvinar, elit libero tincidunt tortor, non elementum lacus nisl sit amet lorem.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur fringilla enim eget augue pretium facilisis. Quisque euismod mauris eu odio tincidunt pharetra interdum enim dignissim. Phasellus eleifend viverra diam, et vestibulum orci feugiat vitae. Fusce rhoncus, dolor sit amet rhoncus pulvinar, elit libero tincidunt tortor, non elementum lacus nisl sit amet lorem.</div>
<div id="right">text</div>
</div>
You could try setting your CSS up like this:
#container{width:100%;}
#left{min-height:70px;width:60px;float:left;}
#middle{min-height:70px;padding:0 60px}
#right{min-height:70px;width:60px;float:right;}
jsFiddle
You could set the width of the middle div using jQuery, as such:
$('#middle').width($('#container').width()-120);
Working Demo
Try this with some trivial javascript: http://jsfiddle.net/maniator/SjMqU/
var middle = document.getElementById('middle');
var win_width = document.body.offsetWidth;
middle.style.width = (win_width - 140) + 'px';
And this fiddle works on window resize: http://jsfiddle.net/maniator/SjMqU/4/
The best way to do it would be to put it into a table, but if you don't want that just make all the divs behave like table cells:
<style type="text/css">
div{display:table-cell;}
#container{width:100%;}
#left{min-width:60px;}
#middle{min-width:50%;}
#right{min-width:60px;}
</style>
.....
You could do something like this:
#container{width:100%;
}
#left, #middle, #right{min-height:70px;
display:inline-block;
vertical-align:top;
}
#left{width:19%;
background:red;
}
#middle{width:60%;
background:green;
}
#right{width:19%;
background:blue;
}
http://jsfiddle.net/jasongennaro/8BqP9/
What would be the best way to style a HTML 5 website (to also function in IE6)?
<header>
[ Header ]
</header>
<section>
<article>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent varius ultricies nibh faucibus tempor. Aliquam erat volutpat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent hendrerit nunc vitae nisl accumsan dictum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Integer convallis lobortis turpis posuere semper. Proin ligula mi, hendrerit sit amet feugiat eu, dapibus sed ante. Donec lacinia aliquam felis at gravida. Praesent varius lectus enim. Nulla vehicula, odio id feugiat ornare, nibh urna elementum arcu, ut suscipit odio velit vel augue. Maecenas enim dolor, tincidunt a luctus ornare, viverra ut lorem. Suspendisse imperdiet est id mi pulvinar quis interdum felis vehicula.
</article>
<aside>
[ Aside ]
</aside>
</section>
<footer>
[ Footer ]
</footer>
CSS
header {
display:block;
clear:both;
background-color:red;
height:43px;
}
section article {
display:block;
float:left;
width:800px;
background-color:green;
}
section aside {
display:block;
width:180px;
background-color:lime;
}
footer {
display:block;
clear:both;
background-color:blue;
height:43px;
}
My real question, must I now add after the tag?
Everything you need to know is at http://html5boilerplate.com/
Remember to add
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
To your head to ensure that IE can style these elements.