IE6 CSS Float Dropdown Issue - css

I'm struggling with an IE6 float issue. (I know IE6 sucks but my huge company uses it..) I've created a simple, header, body, footer layout, with a content area and sidebar within the body. Essentially a common blog layout.
I've had no problem achieving this in IE6 but within the content area I've tried to create a featured area div across the top, then below it two divs side by side. It looks fine in modern browsers but in IE6 it puts the 2nd div below the 1st. Like the divs are too big for the container so it pushes the 2nd. But that shouldn't be the issue since they are both small enough (width, padding, margin) to fit..
And here's my code:
HTML
<body>
<div id="page-wrap">
<div id="header">
</div>
<div id="content">
<div id="feature">
</div>
<div class="clear"></div>
<div id="#1">
</div>
<div id="#2">
</div>
</div><!--Content End-->
<div id="sidebar">
</div>
<div class="clear"></div>
<div id="footer">
</div>
</div><!--Body Content End-->
</div><!--Page Wrap End-->
</body>
CSS
#page-wrap {
width: 960px;
margin: 0 auto;
background-color: #fff;
}
#header {
width: 954px;
height: 50px;
padding: 10px 0;
margin: 0 3px 2px 3px;
border-bottom: #7E7871 dotted 3px;
}
#content {
float: left;
width: 650px;
margin: 0;
padding: 15px 5px 0 15px;
}
#feature {
width: 650px;
margin: 0;
}
#content #1 {
border-right: thin solid #CCC;
width: 305px;
margin: 0;
padding: 0;
float: left;
}
#content #2 {
width: 305px;
margin: 0;
padding: 0;
float: right;
}
#sidebar {
float: right;
width: 250px;
padding: 0 10px 20px 10px;
margin: 0;
background: url(../_images/bg_aside.gif) repeat-y;
}

Since you haven't provided much detail as to how your HTML/CSS doesn't work in your browser, the only error I can find in your code is you have a stray </div>:
<body>
<div id="page-wrap">
<div id="header">
</div>
<div id="content">
<div id="feature">
</div>
</div>
<div class="clear"></div>
<div id="programs">
</div>
<div id="discounts">
</div>
<div class="clear"></div>
--> </div><!-- THIS ONE! -->
<div id="sidebar">
</div>
<div class="clear"></div>
<div id="footer">
</div>
</div><!-- Body content end -->
</div><!-- Page wrap end -->
</body>

One of the reasons it will dip below is due to content being larger than the div.
However, your css does not match the provided HTML. It's hard to debug some of this without the actual content.
Assuming #2 and #1 are #discounts and #programs, I suggest adding an overflow: scroll; to see how it changes.

Related

Horizontally align div with an element outside its parent

This image shows what I am trying to do.
Basically, I have a header and footer inside the body. I have a div1 inside a header which has a size that can vary. I want to align div2, which is inside the footer, so that its right border is matches the right border of div1.
The following HTML can explain the structure.
<body>
<div id="header">
<div id="div1">
</div>
</div>
<div id="footer">
<div id="div2">
</div>
</div>
This would be the css.
#div1 {
overflow: auto;
display: grid;
float: start;
}
#div2 {
width: 20px;
// ??????
}
There's no float: start. You just be better off having a common container, as how it is in Bootstrap and other frameworks to "contain" your code. So your page might be rendered well this way:
body {
font-family: 'Segoe UI';
background: #ffa500;
}
#header {
background-color: #fcc;
padding: 10px;
}
#footer {
background-color: #f99;
padding: 10px;
}
.container {
max-width: 65%;
overflow: hidden;
}
#div1 {
padding: 10px;
background-color: #99f;
}
#div2 {
padding: 10px;
background-color: #ccf;
float: right;
width: 50%;
}
<div id="header">
<div class="container">
<div id="div1">
div1
</div>
</div>
</div>
<div id="footer">
<div class="container">
<div id="div2">
div2
</div>
</div>
</div>
Preview

Three column design HTML

I'm trying to recreate a web page with a three column design like the page below, but i'm having some trouble. I've tried using nested divs, but the code does not seem to be working for some reason. Here's a snippet of the html and css code
<body>
<div id="container">
<header>
<h1>The CIS 4004 Newsletter</h1>
</header>
<div id="wrapper" role="main">
<nav>
<ul>
<li>Test link; </li>
</ul>
</nav>
<article>
<div class="inner">
<h2>Test header</h2>
<p>Just some test text.
</p>
</div>
</article>
</div>
</div>
</body>
css code is here
#wrapper {
border: 1px solid black;
position:relative;
width:960px;
margin:0 auto;
overflow:hidden;
}
nav{
width: 150px;
float: left;
border: 2px solid black;
position:relative;
}
article.inner {
margin:10px;
padding:20px:
border: 2px solid red;
}
Here's an image of the web page
http://jsfiddle.net/2yjhp/
The simple template
<div class="wrapper">
<div class="left">Left Content</div>
<div class="middle">Middle Content</div>
<div class="right">Right Content</div>
</div>
---CSS---
div.wrapper {width: 1000px; margin: 0px auto;}
div.left {width: 250px; float: left;}
div.middle{float: left;}
div.right{width: 250px; float: left;}
Whether your designing a three column layout or a two column layout the key thing to remember is to floating all the columns in the same direction (left) and adjusting there width accordingly. There is no need to use nested div.
eg:
cloumnone{float: left;
width: 33%;}
similary for other two cloumns...

floating div not on top of page

I've got three left-floating div (1, 2 & 3) and one floating right (4), which is also the last div in my HTML code. The three on the left take up 60% of the width and the last div should fill in on the right. However div 4 only floats past the div 3 and then stops.
<body>
<div style="width: 60%; float: left; background-color: red;">
div 1
</div>
<div style="width: 60%; float: left; background-color: red;">
div 2
</div>
<div style="width: 60%; float: left; background-color: red;">
div 3
</div>
<div style="width: 40%; float: right; background-color: yellow;">
div 4
</div>
</body>
Any suggestions how to make the div go to the top of the page?
This is what you want? DEMO
I edited a bit your HTML code:
<section class="container">
<div class="block one"></div>
<div class="block two"></div>
<div class="block three"></div>
<div class="block four"></div>
</section>
Just add these CSS rules:
*, *:before, *:after {
box-sizing: border-box;
}
body, div, section {
margin: 0;
padding: 0;
}
html, body {
background: #CCC;
height: 100%;
}
.block {
height: 100px;
display: inline-block;
border: 1px solid black;
}
.block:not(.four) {
float: left;
width: calc(60% / 3);
}
.four {
width: calc(100% - 60%);
}
.container > .four {
float: right;
}
I used the calc() function for set the anchors to the elements. You can see the browser support here
EDIT Sorry, I didn't understand your question. This is what you want! DEMO =)
Cheers,
Leo!
I think what you are trying to achieve here is put some content in your page (the left floated divs) and a sidebar (the right div).
Well, there are many ways to do it, here is a method without using floats (right or left).
HTML:
<body>
<section style="width: 60%;"> <!-- Your main content goes in here -->
<div style="background-color: red;">div 1</div>
<div style="background-color: red;">div 2</div>
<div style="background-color: red;">div 3</div>
</section>
<aside style="width: 40%;" class="right"> <!-- content for right sidebar -->
<div style="background-color: yellow;">div 4</div>
</aside>
</body>
CSS:
aside,section {
display : inline-block;
padding : 0;
margin : 0;
}
aside.right {
vertical-align: top; //to bring sidebar to top
}
Here is a demo FIDDLE

Remove unwanted margin due to line-break in HTML

I get an unwanted margin between block1 and block2 with display: inline-block style. See this jsFiddle.
HTML
<div id="container">
<div id="innercontainer">
<div id="block1">
block1
</div>
<div id="block2">
block2
</div>
</div>
</div>
CSS
* {
margin: 0px;
padding: 0px;
}
#container {
background-color: #f00;
width: 100%;
height: 200px;
}
#innercontainer {
background-color: #0f0;
width: 200px;
height: 200px;
margin: 0px auto;
}
#block1, #block2 {
display: inline-block;
background-color: #00f;
height: 200px;
}
The margin disappears when I change the HTML to this:
<div id="container">
<div id="innercontainer">
<div id="block1">
block1
</div><div id="block2">
block2
</div>
</div>
</div>
or this:
<div id="container">
<div id="innercontainer">
<div id="block1">
block1
</div><!--
--><div id="block2">
block2
</div>
</div>
</div>
While I prefer the latter, I still do wonder if anyone knows a solution so I can use the original HTML, but no whitespace shows up in innercontainer. Also note that I want to avoid setting float: left; on both block1 and block2 or making them floating by position: absolute|relative because that generates other problems in my layout. Any ideas?
EDIT
Ok, so I had more trouble with my layout. When I added an image to block1, the whole block moved down, very strange (see jsFiddle). I am now using float: left and will have to figure out how I can add a div that consumes the free-space on the right.
Update this part of css :
#block1, #block2 {
display: block;
float: left;
background-color: #00f;
height: 200px;
}
When you are inline, spaces take space!
EDIT :
To be safe change this part of HTML
<div id="container">
<div id="innercontainer">
<div id="block1">
block1
</div>
<div id="block2">
block2
</div>
<div style="clear: both"></div>
</div>
If you want to use display: inline-block;. You need to close gap between tags like you mention. Because The it self are treated as inline-elements also. When you have a space or line-break between two tags would create a gap between them.
You can fix this by set font-size of a surrounding container to 0 and set them back in child node.
#innercontainer {
background-color: #0f0;
width: 200px;
height: 200px;
margin: 0px auto;
font-size: 0px;
}
#block1, #block2 {
display: inline-block;
background-color: #00f;
height: 200px;
font-size: 15px;
}
http://jsfiddle.net/SbUwt/27/

CSS: Sidebar div will not stay in place!

I am attaching my HTML and CSS hoping that someone can help me. Basically I have a right sidebar div where the content will not push to the top. When I play around with position and height properties, the content just floats all over the page and doesn't even stay in the right sidebar. I hope someone can point me in the right direction, I have looked at numerous posts and nothing I try seems to work.
HTML:
<div id="container">
<div id="head">
</div>
<div id="menuTop">
</div>
<div id="content">
</div>
<div id="sidebar">
</div>
<div id="footer">
</div>
</div>
CSS:
#container {
margin: 0 auto;
width: 1000px;
background: url("bgbg.jpg");
border: 10px solid #000;
}
#content {
float: left;
width: 750px;
padding: 0;
background: url("bgbg.jpg");
border-right: 1px dashed #fff;
}
#sidebar {
float: right;
background: url("bgbg.jpg");
width: 250px;
}
CSS Box Model 101 - the actual width of a div (or any element) is width + padding + borders
So your two floated divs add up to 1001px
the content div # 750px + 1px border is actually 751px wide, make it's width 749px and all should be well
#container {
margin: 0 auto;
width: 1000px;
background: url("bgbg.jpg");
border: 10px solid #000;
}
#content {
float: left;
width: 750px;
padding: 0;
background: url("bgbg.jpg");
border-right: 1px dashed #fff;
display:block;
}
#sidebar {
float: right;
background: url("bgbg.jpg");
width: 200px;
}
<div id="container">
<div id="head">head
</div>
<div id="menuTop">
</div>
<div id="content">ssss
</div>
<div id="sidebar">ffff
</div>
<br style="clear:both;" />
<div id="footer">
</div>
</div>

Resources