/    Sign up×
Community /Pin to ProfileBookmark

understanding css positioning

Why even though there #text is 300 pixels wide, and #actions is 200 pixles wide, the #action div doesn’t stay on the right [B]top[/B] side of the header? It stays on the right, but #text doesn’t let it sit on its right. Instead, it pushes #actions down.

[code=html]
<!DOCTYPE HTML>
<html lang=’pt-br’>
<head>
<meta charset=’UTF-8′>
<title>Positioning</title>
<style>
* {
/* margin: 0; */
/* padding: 0; */
}
html {
font-family: ‘Verdana’;
}
#wrapper {
width: 960px;
margin: 0 auto;
background-color: #eee;
}
#main_header {
background-color: #ddd;
height: 70px;
}
#logo {
width: 200px;
float: left;
background-color: #1a9;
}
#text {
width: 300px;
margin-left: 200px;
/* float: left; */ /* This makes things work. */
}
#actions {
width: 200px;
background-color: #7f9f7f;
float: right;
}
</style>
</head>

<body>

<div id=’wrapper’>
<header id=’main_header’>

<div id=’logo’>
<h1>Logo</h1>
</div>

<div id=’text’>
<h2>Welcome here.</h2>
</div>

<div id=’actions’>
<div id=’logout’>
<p><a href=’#logout’>Sair</a></p>
</div>
<div id=’site’>
<p><a href=’#view_site’>Ver o site</a></p>
</div>
</div>
</header>
<div style=’clear: both;’></div>

<section id=’main_section’>

<h1>Main Section</h1>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer iaculis
tincidunt velit. Integer malesuada velit ut sapien congue mollis. In placerat
nunc non diam. Fusce scelerisque placerat lectus. Nulla fringilla porttitor
felis. Vivamus auctor pharetra elit. Aliquam quis diam. *** sociis natoque
penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent
at libero. Duis scelerisque luctus nibh. Aliquam mi. Lorem ipsum dolor sit
amet, consectetuer adipiscing elit. Fusce magna libero, lacinia a, sollicitudin
at, mattis ut, odio. Vivamus sapien lacus, tempus non, interdum vel, tempor
vel, mauris. Duis consequat vehicula neque. Class aptent taciti sociosqu ad
litora torquent per conubia nostra, per inceptos hymenaeos.</p>

</section>

</div><!– Fim div id=’wrapper’. –>

</body>
</html>

[/code]

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@COBOLdinosaurFeb 10.2013 — If #text is not floated, then the line feeds for the h2 and div reset the the starting position available to the bottom of the text line. Whe you do a layout like that all the element going across must be floated. to keep them on the same line.
Copy linkTweet thisAlerts:
@FernandoBassoauthorFeb 10.2013 — What do you mean by "line feeds"? Do you mean the same as "new line" or "n"?
Copy linkTweet thisAlerts:
@COBOLdinosaurFeb 10.2013 — Yes block elements include a new line.
×

Success!

Help @FernandoBasso 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 5.5,
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,
)...