Reputation: 17
I created two divs on my websit. The first div which is having the color aqua was given a height of 200px. the next div was given afterwards with some padding. but the height for the original div has now been reduced. it's not 200px anymore. please suggest a way to place the second div soon after the first one without reducing/overlapping the first one.
HTML
<!doctype html>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" type="text/css" href="style.css" >
<script src="JavaScript.js"></script>
</head>
<body>
<div>
<ul id="nav">
<li id="click"><a href="#">Contact</a></li>
<li> <a href="#">Blog</a></li>
<li> <a href="#">Work</a></li>
<li> <a href="#">About</a></li>
<li> <a href="#">Home</a></li>
</ul>
</div>
<div>
<img src="image.jpg" style="width: 100%">
</div>
<div id="tagline">
<p>Miss Baker's flight was another milestone in the history of space flight…</p>
<div>
<div style="padding: 200px; background-color: red">
<p>Haha, it worked!!!</p>
</div>
</body>
</html>
CSS
body {
margin: 0;
}
#nav {
list-style-type: none;
margin: 0;
padding: 0;
}
#nav li {
width: 20%;
float: left;
text-align: center;
display: inline;
}
#nav li a {
line-height: 40px;
display: block;
padding: 0.5em 5px;
text-decoration: none;
font-weight: bold;
color: #F2F2F2;
-webkit-box-shadow: 3px 3px 3px rgba(51,51,51,0.3);
box-shadow: 3px 3px 3px rgba(51,51,51,0.3);
}
#nav a:link, #nav a:visited {
background-color: #071726;
}
#nav a:hover, #nav a:active, #nav a:focus {
background-color: #326773;
}
#tagline {
height: 200px;
background-color: aqua;
}
img {display:block;}
p {margin:0;}
Here's the fiddle
Upvotes: 0
Views: 65
Reputation: 974
Overlapping occurred since you accidentally missed to close tagline div:
<div id="tagline">
<p>Miss Baker's flight was another milestone in the history of space flight…</p>
</div>
<div style="padding: 200px; background-color: red">
<p>Haha, it worked!!!</p>
</div>
Upvotes: 0
Reputation: 81384
The most likely culprit is line 23:
<div>
You probably meant:
</div>
This change would both make the HTML valid, and also make the red div element a sibling of the tagline, not a child, which is probably what you want.
Upvotes: 2