/    Sign up×
Community /Pin to ProfileBookmark

mixing widths with pixels and %

hey i have a two column layout and i want one column to be a fixed width and i want the other to expand the rest of the width.

just wondering if it will work if i float both elements.

eg:

[CODE]
.leftcol {
width:100px;
float:left;
}

.rightcol {
width:100%
float:left;
}[/CODE]

to post a comment
CSS

1 Comments(s)

Copy linkTweet thisAlerts:
@CentauriJul 11.2008 — That won't work as the 100% width will be the width of the container and not the available width. The usual way is to float the fixed column and just specify a left margin on the unfloated variable width div :
[CODE].leftcol {
width:100px;
float:left;
}

.rightcol {
margin-left: 100px;
}[/CODE]

The .leftcol should come before the .rightcol in the html, and .rightcol should have no width or height dimensions (otherwise IE6 complains), and will fill the available width.
×

Success!

Help @tehashman 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.26,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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