Reputation: 816
I've got a couple of DIV's within a containing DIV . I want them to sit next each other horizontally but no matter what I do they stay on the vertical.
code :
<style>
#entrycontainer {
height:100px;
width:500px;
}
#entry {
height:100px;
width:200px;
}
</style>
<div id="entrycontainer" >
<div id="entry" >
<h1>PHP File Upload/Browser</h1>
<img src="img/projectimg/fileupimg.png" />
<p>PHP MySQL CSS</p>
</div>
<div id="entry" >
<h1>PHP File Upload/Browser</h1>
<img src="img/projectimg/fileupimg.png" />
<p>PHP MySQL CSS</p>
</div>
</div>
Upvotes: 1
Views: 176
Reputation: 9276
divs are block-level elements, meaning they will always be placed below the previous content (as opposed to inline elements, like span)
Upvotes: 0
Reputation: 4924
You also need to use a class, since an id
should be unique on a page.
.entry{ float: left; width: 200px; height: 100px; }
Upvotes: 0
Reputation: 7863
You can't (or shouldn't) have two divs with the same ID; for one thing. Secondly, divs are block elements which mean that unless you change the behavior with styling, they will always appear on a new line.
Change your CSS to be like this:
.entry {
height:100px;
width:200px;
float:left;
}
And change your HTML to be like this:
<div id="1" class="entry" >
<h1>PHP File Upload/Browser</h1>
<img src="img/projectimg/fileupimg.png" />
<p>PHP MySQL CSS</p>
</div>
<div id="2" class="entry" >
<h1>PHP File Upload/Browser</h1>
<img src="img/projectimg/fileupimg.png" />
<p>PHP MySQL CSS</p>
</div>
That should be enough to get you in the right direction.
Upvotes: 0
Reputation: 298106
You have two elements with the same id
. The id
property is unique, which means that it is used to reference a single element. If you want to group elements together, use class
, as it can be used multiple times.
As for the fix, float: left
the elements. div
elements are block
s, so they don't stay inline. Also notice my overflow: auto
statement in the parent element. That is used to account for the float
s.
Demo: http://jsfiddle.net/g9bgV/1/
Upvotes: 0
Reputation: 4659
add float:left;
to you entry class should look like this also of note you should change like I did for you in the code the #entry to .entry and change them to reference a class. the correct use of class is anytime more than one element is styled on the same page it should be set as a class.
<style type="text/css">
#entrycontainer {
height:100px;
width:500px;
}
.entry {
float: left;
height:100px;
width:200px;
}
</style>
<div id="entrycontainer" >
<div class="entry" >
<h1>PHP File Upload/Browser</h1>
<img src="img/projectimg/fileupimg.png" />
<p>PHP MySQL CSS</p>
</div>
<div class="entry" >
<h1>PHP File Upload/Browser</h1>
<img src="img/projectimg/fileupimg.png" />
<p>PHP MySQL CSS</p>
</div>
</div>
Upvotes: 2