Reputation: 17496
This is in style.css
:
#top{
background: white;
text-align: center;
height: 180px;
border-bottom: solid 1px #efeecc;
}
#topLogo{
background: yellow;
width: 25%;
float:left;
}
#topDescription {
background: red;
width: 75%;
text-align: center;
}
#topDepartment {
background: blue;
float:right;
width: 25%;
text-align: right;
}
This is index.html
:
<div id="top">
<div id="topLogo">
<a href="index.html"><img src="img/book.jpg" width="170" height="160" border="0"/></a>
</div>
<div id="topDescription">
Page title
</div>
<div id="topDepartment">
Category
</div>
</div>
This is the expected outcome:
This is the current outcome:
Upvotes: 1
Views: 81
Reputation: 2157
Here's a demo: http://jsfiddle.net/p2T5q/7/
CSS:
#top{
background: white;
text-align: center;
display:table;
height: 180px;
border-bottom: solid 1px #efeecc;
}
#topLogo{
background: yellow;
width: 25%;
display:table-cell;
}
#topDescription {
background: red;
display:table-cell;
width: 50%;
text-align: center;
}
#topDepartment {
background: blue;
display:table-cell;
width: 25%;
text-align: right;
}
Upvotes: 2
Reputation: 381
Here you go, I fixed the fiddle and copied the answer here:
#top{
height: 180px;
border: solid 1px #555555;
position:relative;
}
#top * {
float:left;
}
#topLogo{
background: yellow;
width: 25%;
}
#topDescription {
background: red;
width: 50%;
}
#topDepartment {
background: blue;
width: 25%;
}
Basically make sure the width percentages add up to 100% and float all elements to left so they know in relation to what they should position themselves. You can use the * to select all subelements. I would appreciate you accepting this answer so I can finally get my 50 damn coins and make comments, lol.
Upvotes: 0
Reputation: 173
Well, the quick answer is that your div's total width is 125%, so you would need to change that so it equals 100%.
Second, you might want to put a clear fix on that top div so it encompasses all of the floating ones.
Also, don't use inline styles because you can put them in the CSS file. You are giving a fixed width to an image that sits inside a div with a percentage width. That is sure to break if the user reduces the size of his viewport.
Upvotes: 0