Balidani
02-15-2011, 10:11 PM
Hi there!
This is my first post here. I registered because I'm in need of help, and I'm totally clueless. I hope some people could help.
I'm building a website and I decided to add a gradient background to the top of each column. This is the code I used:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
@charset "utf-8";
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #ECDBA6;
margin: 0;
padding: 0;
text-align: center;
color: #000000;
}
h1 {
margin: 0;
padding-top: 20px;
}
.teststyle #gradient {
width: 100%;
height: 100px;
background-image: url(gradient.png);
}
</style>
</head>
<body class="teststyle">
<div id="gradient"/>
<h1>Hello World!</h1>
<p>
Lorem ipsum dolor sit amet
</p>
</body>
</html>
The first interesting thing is that if I use "<div></div>" instead of "<div/>" the whole thing goes wrong. The gradient.png image doesn't go behind the text - it's just simply standing above the text. Why is this?
The real problem is when I have two collumns, one of which floats on the left and the other on the right side of the page. Adding the "<div/>" part makes everything collapse. This is a sample code:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
@charset "utf-8";
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #FFFFFF;
margin: 0;
padding: 0;
text-align: center;
color: #000000;
}
.teststyle2 #gradient_left {
float: left;
width: 100%;
height: 100px;
background-image: url(images/gradient.png);
}
.teststyle2 #container {
width: 900px;
margin: 0 auto;
text-align: left;
}
.teststyle2 #sidebar1 {
float: left;
width: 11em;
padding: 0;
background: #ECDBA6;
}
.teststyle2 #sidebar2 {
float: right;
width: 11em;
padding: 0;
background: #ECDBA6;
}
.teststyle2 #sidebar1 h3, .thrColHybHdr #sidebar1 p {
margin-left: 10px;
margin-right: 10px;
}
</style>
</head>
<body class="teststyle2">
<div id="container">
<div id="sidebar1">
<!-- ***** -->
<!-- * * -->
<div id="gradient_left"/>
<!-- * * -->
<!-- ***** -->
<h3>sidebar 1</h3>
<p>Lorem ipsum dolor sit amet</p>
</div>
<div id="sidebar2">
<h3>sidebar 2</h3>
<p>Donec eu mi sed turpis feugiat feugiat.</p>
</div>
</div>
</body>
</html>
I have no idea why this is happening. Could somebody give me a hint?
Thanks, in advance!
This is my first post here. I registered because I'm in need of help, and I'm totally clueless. I hope some people could help.
I'm building a website and I decided to add a gradient background to the top of each column. This is the code I used:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
@charset "utf-8";
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #ECDBA6;
margin: 0;
padding: 0;
text-align: center;
color: #000000;
}
h1 {
margin: 0;
padding-top: 20px;
}
.teststyle #gradient {
width: 100%;
height: 100px;
background-image: url(gradient.png);
}
</style>
</head>
<body class="teststyle">
<div id="gradient"/>
<h1>Hello World!</h1>
<p>
Lorem ipsum dolor sit amet
</p>
</body>
</html>
The first interesting thing is that if I use "<div></div>" instead of "<div/>" the whole thing goes wrong. The gradient.png image doesn't go behind the text - it's just simply standing above the text. Why is this?
The real problem is when I have two collumns, one of which floats on the left and the other on the right side of the page. Adding the "<div/>" part makes everything collapse. This is a sample code:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
@charset "utf-8";
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #FFFFFF;
margin: 0;
padding: 0;
text-align: center;
color: #000000;
}
.teststyle2 #gradient_left {
float: left;
width: 100%;
height: 100px;
background-image: url(images/gradient.png);
}
.teststyle2 #container {
width: 900px;
margin: 0 auto;
text-align: left;
}
.teststyle2 #sidebar1 {
float: left;
width: 11em;
padding: 0;
background: #ECDBA6;
}
.teststyle2 #sidebar2 {
float: right;
width: 11em;
padding: 0;
background: #ECDBA6;
}
.teststyle2 #sidebar1 h3, .thrColHybHdr #sidebar1 p {
margin-left: 10px;
margin-right: 10px;
}
</style>
</head>
<body class="teststyle2">
<div id="container">
<div id="sidebar1">
<!-- ***** -->
<!-- * * -->
<div id="gradient_left"/>
<!-- * * -->
<!-- ***** -->
<h3>sidebar 1</h3>
<p>Lorem ipsum dolor sit amet</p>
</div>
<div id="sidebar2">
<h3>sidebar 2</h3>
<p>Donec eu mi sed turpis feugiat feugiat.</p>
</div>
</div>
</body>
</html>
I have no idea why this is happening. Could somebody give me a hint?
Thanks, in advance!