I’m newbie with css and I’m dealing with an issue that I can’t understand. I have a parent div “footer” which contains a child div “vote”. This div contains a form which currently consists of an image button.
When viewing this with “Inspect Element” the footer div has height 0px and just shows the margin defined. Why is this? Shouldn’t the parent div hold the inner divs adjusting its size in case it’s not defined?
This happens to be the case when adding a text element (line commented out in code example), but in this particular case I don’t need to add any text so this isn’t an option.
Any tip?
<html>
<head>
<style type="text/css">
#footer {
margin: 0.2em;
}
#vote {
float: right;
}
#voteForm {
float: right;
margin: 0.2em;
}
</style>
</head>
<body>
<div id="footer">
<div id="vote">
<form id="voteForm" name="voteForm" action="/vote.php" method="post">
<input type="image" src="image/vote.png">
</form>
</div>
<!-- <h3>Hello</h3> -->
</div>
</body>
</html>
You haven’t cleared your floats.
When you float an element you take it out of the normal flow of the page until it is cleared. So without the clear the
#footercontains nothing because#voteand#voteFormare both outside of the flow of the page.