Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialVamsi Pavan Mahesh Gunturu
4,541 PointsI'm trying to construct a box. But it was made with all the hacks
I'm trying to construct a box with title, description, button and an image. Regarding the positions, I am unable to do them right. Had to use chrome developer tools, to position them properly. can you guys review my code, and tell me. How do it right?
<html>
<head>
<title>Trying box positions</title>
<style>
.outerbox{
position: relative;
height: 200px;
width: 80%;
margin: auto;
background: lightblue;
}
.title{
text-align: center;
}
h2{
padding: 0;
margin: 0;
}
.image{
height: 50px;
}
img{
max-height: 500%;
padding-left: 5px;
}
.desc{
padding-left: 150px;
}
.buy{
position: relative;
width: 100px;
height: 50px;
background: steelblue;
left: 979px;
top: -94px;
}
</style>
</head>
<body>
<div class="outerbox">
<div class="title">
<h2>
Operating Systems by Willam stallings
</h2>
</div>
<div class="image">
<img src="vamsi.png" >
</div>
<div class="desc">
This book is very useful for the third year students of all branches. This book condition is very new, as I mostly
dont read :p.
</div>
<div class="buy">
BUY rs.xxx
</div>
</div>
</body>
</html>
The wire frame is like this ... https://drive.google.com/file/d/0BxY-ounFx9_hbG93WXYyb21sSFk/view?usp=sharing
1 Answer
Jorge Felico
15,543 PointsHi Vamsi, See if the code below helps
<!DOCTYPE html>
<html>
<head>
<title>Trying box positions</title>
<style>
.outerbox{
position: relative;
height: 200px;
width: 80%;
margin: auto;
background: lightblue;
}
.title{
text-align: center;
}
h2{
padding: 0;
margin: 0;
}
.image{
height: 50px;
float: left;
}
.clear{
clear: both;
}
img{
max-height: 500%;
padding-left: 5px;
}
.desc{
padding-left: 150px;
}
.buy{
width: 100px;
height: 50px;
background: steelblue;
float:right;
}
</style>
</head>
<body>
<div class="outerbox">
<div class="title">
<h2>
Operating Systems by Willam stallings
</h2>
</div>
<div class="image">
<img src="vamsi.png" >
</div>
<div class="desc">
This book is very useful for the third year students of all branches. This book condition is very new, as I mostly
dont read :p.
</div>
<div class="clear"></div>
<div class="buy">
BUY rs.xxx
</div>
</div>
</body>
</html>
The problem I saw is that you were not floating the image to the left so that the h2 tag and the description div would align to the right of the picture, then I cleared the float by adding a div with a class .clear which I added to your css. Then I floated the buy div to the right.
Vamsi Pavan Mahesh Gunturu
4,541 PointsHey Jorge, Thanks for taking time to write code for me. Ok, the code seems cool. But the problem is that I am not quite able to Understand the positioning. When Should I use float and relative? And according to your code, are you not supposed to clear the float after the buy button? In your post it was mentioned before the buy button. And instead of keeping an empty div and clearing floats, can we add an another class in the image section and buy section, to clear them? can you write these doubts in your answer(by editing it), I think it's not possible for you to comment on this any further. Thanks in advance.
Chris Shaw
26,676 PointsChris Shaw
26,676 PointsHi Vamsi,
How exactly do you need your box to look as it's not possible to assist you without a clear wireframe to base your code on.