/    Sign up×
Community /Pin to ProfileBookmark

Sitting Divs Beside Each Other

How do you set divs side by side? My current CSS:

[CODE]#header1 {
position: absolute;
left: 0px;
width: 51%;
height: 150px;
margin-right: 5px;
background-image: url(/images/misc/possible_rebirth_banner_copy.jpg);
}

#header2 {
width: 49%;
height: 150px;
background-image: none;[/CODE]

And my current web page code:

[code=php]<div id=”header1″></div>

<div id=”header2″>

<div align=”center”><img src=”/images/misc/houses.gif” border=”0″ width=”95″ height=”32″ alt=”Houses” onMouseOver=”houses1();” onMouseOut=”houses2();”>

<br> <br>

<?php include(“../includes/house_table.html”); ?>

</div>

</div>[/code]

The problem is header2 is sitting directly under header1. I need header2 to be on header1’s right side.

to post a comment
CSS

8 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Jun 28.2008 — Maybe:#header1 {
float:left;
width: 51%;
height: 150px;
margin-right: 5px;
background-image: url(/images/misc/possible_rebirth_banner_copy.jpg);
}

#header2 {
width: 49%;
height: 150px;
background-image: none;
}
Copy linkTweet thisAlerts:
@Joseph_WitchardauthorJun 29.2008 — Isn't float only used for images?
Copy linkTweet thisAlerts:
@CentauriJun 29.2008 — Any element can be floated.
Copy linkTweet thisAlerts:
@Joseph_WitchardauthorJun 29.2008 — Well, it's a little bit better, but not much. http://www.uhrebirth.com/test/test.php You can now see the image that reads "Houses," but it's now sitting under the header1 div instead of beside it liked I had hoped. If you have Aardvark for Firefox, you can see that the div is still not where it's supposed to be.

More help would be greatly appreciated:o
Copy linkTweet thisAlerts:
@CentauriJun 29.2008 — You float both the divs, and reduce the width of one of them to allow for the margin between them :[CODE]#header1 {
float: left;
width: [COLOR="Red"]50%[/COLOR];
height: 150px;
margin-right: 5px;
background-image: url(/images/misc/possible_rebirth_banner_copy.jpg);
}

#header2 {
width: 49%;
height: 150px;
background-image: none;
[COLOR="Red"]float: left;[/COLOR]
}[/CODE]
Copy linkTweet thisAlerts:
@Joseph_WitchardauthorJun 29.2008 — Just changed it, and it still doesn't work?
Copy linkTweet thisAlerts:
@CentauriJun 29.2008 — Working fine for me..
Copy linkTweet thisAlerts:
@Joseph_WitchardauthorJun 29.2008 — It's working fine for me too, now... Weird...

Okay, thanks for all of your help!
×

Success!

Help @Joseph_Witchard spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...