CSS positioning 2 shifted columns
first of all is there a good tutorial about positioning elements which really explains what's going on? I've read multiple but can't get a grip on it.
the specific problem I have is as follows:
I have a header div-element (in red) with underneath 2 columns(white and green). Normally with float:left; i can position the elements next to each-other. But now I want one (the white one) to move a bit over the header als shown.
with relative positioning with a negative top value I can get the white one at the right position but how to position the second column. When adjusting the browser size it al gets messed up.
#Column1
float: left;
position: relative;
top: -140px;
background-color: #FFFFFF;
left: 70px;
width: 280px;
min-height: 500px;
padding: 10px;
#Column2
float: left;
width: 800px;
background-color: #00FF00;
html css
add a comment |
first of all is there a good tutorial about positioning elements which really explains what's going on? I've read multiple but can't get a grip on it.
the specific problem I have is as follows:
I have a header div-element (in red) with underneath 2 columns(white and green). Normally with float:left; i can position the elements next to each-other. But now I want one (the white one) to move a bit over the header als shown.
with relative positioning with a negative top value I can get the white one at the right position but how to position the second column. When adjusting the browser size it al gets messed up.
#Column1
float: left;
position: relative;
top: -140px;
background-color: #FFFFFF;
left: 70px;
width: 280px;
min-height: 500px;
padding: 10px;
#Column2
float: left;
width: 800px;
background-color: #00FF00;
html css
alistapart.com/topics/topic/css
– Wex
Jul 27 '12 at 21:46
add a comment |
first of all is there a good tutorial about positioning elements which really explains what's going on? I've read multiple but can't get a grip on it.
the specific problem I have is as follows:
I have a header div-element (in red) with underneath 2 columns(white and green). Normally with float:left; i can position the elements next to each-other. But now I want one (the white one) to move a bit over the header als shown.
with relative positioning with a negative top value I can get the white one at the right position but how to position the second column. When adjusting the browser size it al gets messed up.
#Column1
float: left;
position: relative;
top: -140px;
background-color: #FFFFFF;
left: 70px;
width: 280px;
min-height: 500px;
padding: 10px;
#Column2
float: left;
width: 800px;
background-color: #00FF00;
html css
first of all is there a good tutorial about positioning elements which really explains what's going on? I've read multiple but can't get a grip on it.
the specific problem I have is as follows:
I have a header div-element (in red) with underneath 2 columns(white and green). Normally with float:left; i can position the elements next to each-other. But now I want one (the white one) to move a bit over the header als shown.
with relative positioning with a negative top value I can get the white one at the right position but how to position the second column. When adjusting the browser size it al gets messed up.
#Column1
float: left;
position: relative;
top: -140px;
background-color: #FFFFFF;
left: 70px;
width: 280px;
min-height: 500px;
padding: 10px;
#Column2
float: left;
width: 800px;
background-color: #00FF00;
html css
html css
edited Nov 13 '18 at 5:02
Cœur
17.5k9104145
17.5k9104145
asked Jul 27 '12 at 21:43
Luuk KrijnenLuuk Krijnen
7073828
7073828
alistapart.com/topics/topic/css
– Wex
Jul 27 '12 at 21:46
add a comment |
alistapart.com/topics/topic/css
– Wex
Jul 27 '12 at 21:46
alistapart.com/topics/topic/css
– Wex
Jul 27 '12 at 21:46
alistapart.com/topics/topic/css
– Wex
Jul 27 '12 at 21:46
add a comment |
4 Answers
4
active
oldest
votes
Here is JSFiddle that demonstrates your layout without floats using position absolute.
In my experience position absolute is more flexible and made for this kind of layouts, especially when you want to dock elements using top, right, bottom and left.
There are circumstance where you need to fallback on using floats, but in this case it is not needed.
Use floats to float things around it and position absolute to dock things.
The HTML
<div id="Header">header</div>
<div id="Column1">Left</div>
<div id="Column2">Right</div>
The CSS
#Header
background-color: red;
height: 200px;
#Column1
position: relative;
background-color: #FFFFFF;
top: -140px; left: 70px;
width: 280px;
min-height: 500px;
#Column2
position: absolute;
background-color: #00FF00;
left: 350px; top: 200px; right: 0;
min-height: 360px;
Update Remove display:none from the .more class in the JSFiddle and see that the containers are flexible as well.
Yeah I would agree thatposition: absolute
is good for "docking" elements, but there are definitely better ways of going about it.
– Wex
Jul 27 '12 at 22:10
@Wex Sure! A CSS grid system is better. Why do you think floats are better than position absolute? Sure you can make it work with floats, but doesn't it feel a like a hack? Overflow: hidden :-)
– Split Your Infinity
Jul 27 '12 at 22:16
float
is generally better because it allows for content to dynamically resize (As opposed to usingposition: absolute
, which always requires you to set specific positions for each element).overflow: hidden
is certainly not a hack.
– Wex
Jul 27 '12 at 22:19
I know what overflow hidden does, but it isn't very semantic in my eyes? What does it tell you about my layout? That it is using floats? Or that it wants to 'hide' content.
– Split Your Infinity
Jul 27 '12 at 22:26
Semantic CSS? I'm not quite sure what you're getting at.
– Wex
Jul 27 '12 at 22:27
|
show 1 more comment
I'm just gonna spitball here:
HTML
<div id="red"></div>
<div id="white"></div>
<div id="green"></div>
CSS
#red
width: 100%;
float: left;
height: 100px;
position: relative;
background-color: #f00;
#white
width: 20%;
float: left;
margin-left: 4%;
margin-top: -40px;
position: relative;
background-color: #fff;
height: 400px;
#green
width: 76%;
float: left;
position: relative;
background-color: #0f0;
height: 400px;
Does it work?
Ahah, confirmed, works: jsfiddle.net/nYyxA
– wanovak
Jul 27 '12 at 21:53
A couple unnecessaryfloat
andposition
declarations in there but not a bad way of doing it.
– Wex
Jul 27 '12 at 22:12
I tried to do it correctly the first time without testing it :-) I did, but you're right, it's not perfect.
– wanovak
Jul 27 '12 at 22:14
add a comment |
You could just use a minus margin
http://jsfiddle.net/gAKAK/
add a comment |
This is kind of a complex request, so don't feel bad that you weren't able to figure it out. You shouldn't have to set the width
of anything other than your sidebar for this solution; my solution relies on an uncommon use of overflow: hidden
to achieve this.
http://jsfiddle.net/Wexcode/uBQEu/
HTML:
<div id="header"></div>
<div id="white"></div>
<div id="green"></div>
CSS:
#header
background: red;
height: 70px;
border: 1px solid #000;
#white
background: #fff;
float: left;
margin: -30px 0 0 70px;
width: 100px;
height: 230px;
border: 1px solid #000;
#green
background: green;
overflow: hidden;
height: 201px;
border: 1px solid #000;
border-top: 0;
border-left: 0;
A good article on whyoverflow: hidden;
helps in this situation can be found here: colinaarts.com/articles/the-magic-of-overflow-hidden
– Wex
Jul 27 '12 at 22:06
Still doesn't tell me why floats are not a hack and the wrong tool in most cases. I have used floats to many times myself, before I realised that using position relative and absolute is so much easier in many cases. Even in flexible layouts.
– Split Your Infinity
Jul 27 '12 at 22:22
I don't know why you keep referring tofloat
as a hack. I guess it's just a matter of personal preference. Usingfloat
seems to have saved the trouble of adding an arbitrary container.
– Wex
Jul 27 '12 at 22:27
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11696038%2fcss-positioning-2-shifted-columns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is JSFiddle that demonstrates your layout without floats using position absolute.
In my experience position absolute is more flexible and made for this kind of layouts, especially when you want to dock elements using top, right, bottom and left.
There are circumstance where you need to fallback on using floats, but in this case it is not needed.
Use floats to float things around it and position absolute to dock things.
The HTML
<div id="Header">header</div>
<div id="Column1">Left</div>
<div id="Column2">Right</div>
The CSS
#Header
background-color: red;
height: 200px;
#Column1
position: relative;
background-color: #FFFFFF;
top: -140px; left: 70px;
width: 280px;
min-height: 500px;
#Column2
position: absolute;
background-color: #00FF00;
left: 350px; top: 200px; right: 0;
min-height: 360px;
Update Remove display:none from the .more class in the JSFiddle and see that the containers are flexible as well.
Yeah I would agree thatposition: absolute
is good for "docking" elements, but there are definitely better ways of going about it.
– Wex
Jul 27 '12 at 22:10
@Wex Sure! A CSS grid system is better. Why do you think floats are better than position absolute? Sure you can make it work with floats, but doesn't it feel a like a hack? Overflow: hidden :-)
– Split Your Infinity
Jul 27 '12 at 22:16
float
is generally better because it allows for content to dynamically resize (As opposed to usingposition: absolute
, which always requires you to set specific positions for each element).overflow: hidden
is certainly not a hack.
– Wex
Jul 27 '12 at 22:19
I know what overflow hidden does, but it isn't very semantic in my eyes? What does it tell you about my layout? That it is using floats? Or that it wants to 'hide' content.
– Split Your Infinity
Jul 27 '12 at 22:26
Semantic CSS? I'm not quite sure what you're getting at.
– Wex
Jul 27 '12 at 22:27
|
show 1 more comment
Here is JSFiddle that demonstrates your layout without floats using position absolute.
In my experience position absolute is more flexible and made for this kind of layouts, especially when you want to dock elements using top, right, bottom and left.
There are circumstance where you need to fallback on using floats, but in this case it is not needed.
Use floats to float things around it and position absolute to dock things.
The HTML
<div id="Header">header</div>
<div id="Column1">Left</div>
<div id="Column2">Right</div>
The CSS
#Header
background-color: red;
height: 200px;
#Column1
position: relative;
background-color: #FFFFFF;
top: -140px; left: 70px;
width: 280px;
min-height: 500px;
#Column2
position: absolute;
background-color: #00FF00;
left: 350px; top: 200px; right: 0;
min-height: 360px;
Update Remove display:none from the .more class in the JSFiddle and see that the containers are flexible as well.
Yeah I would agree thatposition: absolute
is good for "docking" elements, but there are definitely better ways of going about it.
– Wex
Jul 27 '12 at 22:10
@Wex Sure! A CSS grid system is better. Why do you think floats are better than position absolute? Sure you can make it work with floats, but doesn't it feel a like a hack? Overflow: hidden :-)
– Split Your Infinity
Jul 27 '12 at 22:16
float
is generally better because it allows for content to dynamically resize (As opposed to usingposition: absolute
, which always requires you to set specific positions for each element).overflow: hidden
is certainly not a hack.
– Wex
Jul 27 '12 at 22:19
I know what overflow hidden does, but it isn't very semantic in my eyes? What does it tell you about my layout? That it is using floats? Or that it wants to 'hide' content.
– Split Your Infinity
Jul 27 '12 at 22:26
Semantic CSS? I'm not quite sure what you're getting at.
– Wex
Jul 27 '12 at 22:27
|
show 1 more comment
Here is JSFiddle that demonstrates your layout without floats using position absolute.
In my experience position absolute is more flexible and made for this kind of layouts, especially when you want to dock elements using top, right, bottom and left.
There are circumstance where you need to fallback on using floats, but in this case it is not needed.
Use floats to float things around it and position absolute to dock things.
The HTML
<div id="Header">header</div>
<div id="Column1">Left</div>
<div id="Column2">Right</div>
The CSS
#Header
background-color: red;
height: 200px;
#Column1
position: relative;
background-color: #FFFFFF;
top: -140px; left: 70px;
width: 280px;
min-height: 500px;
#Column2
position: absolute;
background-color: #00FF00;
left: 350px; top: 200px; right: 0;
min-height: 360px;
Update Remove display:none from the .more class in the JSFiddle and see that the containers are flexible as well.
Here is JSFiddle that demonstrates your layout without floats using position absolute.
In my experience position absolute is more flexible and made for this kind of layouts, especially when you want to dock elements using top, right, bottom and left.
There are circumstance where you need to fallback on using floats, but in this case it is not needed.
Use floats to float things around it and position absolute to dock things.
The HTML
<div id="Header">header</div>
<div id="Column1">Left</div>
<div id="Column2">Right</div>
The CSS
#Header
background-color: red;
height: 200px;
#Column1
position: relative;
background-color: #FFFFFF;
top: -140px; left: 70px;
width: 280px;
min-height: 500px;
#Column2
position: absolute;
background-color: #00FF00;
left: 350px; top: 200px; right: 0;
min-height: 360px;
Update Remove display:none from the .more class in the JSFiddle and see that the containers are flexible as well.
edited Jul 27 '12 at 22:44
answered Jul 27 '12 at 22:00
Split Your InfinitySplit Your Infinity
3,74211419
3,74211419
Yeah I would agree thatposition: absolute
is good for "docking" elements, but there are definitely better ways of going about it.
– Wex
Jul 27 '12 at 22:10
@Wex Sure! A CSS grid system is better. Why do you think floats are better than position absolute? Sure you can make it work with floats, but doesn't it feel a like a hack? Overflow: hidden :-)
– Split Your Infinity
Jul 27 '12 at 22:16
float
is generally better because it allows for content to dynamically resize (As opposed to usingposition: absolute
, which always requires you to set specific positions for each element).overflow: hidden
is certainly not a hack.
– Wex
Jul 27 '12 at 22:19
I know what overflow hidden does, but it isn't very semantic in my eyes? What does it tell you about my layout? That it is using floats? Or that it wants to 'hide' content.
– Split Your Infinity
Jul 27 '12 at 22:26
Semantic CSS? I'm not quite sure what you're getting at.
– Wex
Jul 27 '12 at 22:27
|
show 1 more comment
Yeah I would agree thatposition: absolute
is good for "docking" elements, but there are definitely better ways of going about it.
– Wex
Jul 27 '12 at 22:10
@Wex Sure! A CSS grid system is better. Why do you think floats are better than position absolute? Sure you can make it work with floats, but doesn't it feel a like a hack? Overflow: hidden :-)
– Split Your Infinity
Jul 27 '12 at 22:16
float
is generally better because it allows for content to dynamically resize (As opposed to usingposition: absolute
, which always requires you to set specific positions for each element).overflow: hidden
is certainly not a hack.
– Wex
Jul 27 '12 at 22:19
I know what overflow hidden does, but it isn't very semantic in my eyes? What does it tell you about my layout? That it is using floats? Or that it wants to 'hide' content.
– Split Your Infinity
Jul 27 '12 at 22:26
Semantic CSS? I'm not quite sure what you're getting at.
– Wex
Jul 27 '12 at 22:27
Yeah I would agree that
position: absolute
is good for "docking" elements, but there are definitely better ways of going about it.– Wex
Jul 27 '12 at 22:10
Yeah I would agree that
position: absolute
is good for "docking" elements, but there are definitely better ways of going about it.– Wex
Jul 27 '12 at 22:10
@Wex Sure! A CSS grid system is better. Why do you think floats are better than position absolute? Sure you can make it work with floats, but doesn't it feel a like a hack? Overflow: hidden :-)
– Split Your Infinity
Jul 27 '12 at 22:16
@Wex Sure! A CSS grid system is better. Why do you think floats are better than position absolute? Sure you can make it work with floats, but doesn't it feel a like a hack? Overflow: hidden :-)
– Split Your Infinity
Jul 27 '12 at 22:16
float
is generally better because it allows for content to dynamically resize (As opposed to using position: absolute
, which always requires you to set specific positions for each element). overflow: hidden
is certainly not a hack.– Wex
Jul 27 '12 at 22:19
float
is generally better because it allows for content to dynamically resize (As opposed to using position: absolute
, which always requires you to set specific positions for each element). overflow: hidden
is certainly not a hack.– Wex
Jul 27 '12 at 22:19
I know what overflow hidden does, but it isn't very semantic in my eyes? What does it tell you about my layout? That it is using floats? Or that it wants to 'hide' content.
– Split Your Infinity
Jul 27 '12 at 22:26
I know what overflow hidden does, but it isn't very semantic in my eyes? What does it tell you about my layout? That it is using floats? Or that it wants to 'hide' content.
– Split Your Infinity
Jul 27 '12 at 22:26
Semantic CSS? I'm not quite sure what you're getting at.
– Wex
Jul 27 '12 at 22:27
Semantic CSS? I'm not quite sure what you're getting at.
– Wex
Jul 27 '12 at 22:27
|
show 1 more comment
I'm just gonna spitball here:
HTML
<div id="red"></div>
<div id="white"></div>
<div id="green"></div>
CSS
#red
width: 100%;
float: left;
height: 100px;
position: relative;
background-color: #f00;
#white
width: 20%;
float: left;
margin-left: 4%;
margin-top: -40px;
position: relative;
background-color: #fff;
height: 400px;
#green
width: 76%;
float: left;
position: relative;
background-color: #0f0;
height: 400px;
Does it work?
Ahah, confirmed, works: jsfiddle.net/nYyxA
– wanovak
Jul 27 '12 at 21:53
A couple unnecessaryfloat
andposition
declarations in there but not a bad way of doing it.
– Wex
Jul 27 '12 at 22:12
I tried to do it correctly the first time without testing it :-) I did, but you're right, it's not perfect.
– wanovak
Jul 27 '12 at 22:14
add a comment |
I'm just gonna spitball here:
HTML
<div id="red"></div>
<div id="white"></div>
<div id="green"></div>
CSS
#red
width: 100%;
float: left;
height: 100px;
position: relative;
background-color: #f00;
#white
width: 20%;
float: left;
margin-left: 4%;
margin-top: -40px;
position: relative;
background-color: #fff;
height: 400px;
#green
width: 76%;
float: left;
position: relative;
background-color: #0f0;
height: 400px;
Does it work?
Ahah, confirmed, works: jsfiddle.net/nYyxA
– wanovak
Jul 27 '12 at 21:53
A couple unnecessaryfloat
andposition
declarations in there but not a bad way of doing it.
– Wex
Jul 27 '12 at 22:12
I tried to do it correctly the first time without testing it :-) I did, but you're right, it's not perfect.
– wanovak
Jul 27 '12 at 22:14
add a comment |
I'm just gonna spitball here:
HTML
<div id="red"></div>
<div id="white"></div>
<div id="green"></div>
CSS
#red
width: 100%;
float: left;
height: 100px;
position: relative;
background-color: #f00;
#white
width: 20%;
float: left;
margin-left: 4%;
margin-top: -40px;
position: relative;
background-color: #fff;
height: 400px;
#green
width: 76%;
float: left;
position: relative;
background-color: #0f0;
height: 400px;
Does it work?
I'm just gonna spitball here:
HTML
<div id="red"></div>
<div id="white"></div>
<div id="green"></div>
CSS
#red
width: 100%;
float: left;
height: 100px;
position: relative;
background-color: #f00;
#white
width: 20%;
float: left;
margin-left: 4%;
margin-top: -40px;
position: relative;
background-color: #fff;
height: 400px;
#green
width: 76%;
float: left;
position: relative;
background-color: #0f0;
height: 400px;
Does it work?
answered Jul 27 '12 at 21:51
wanovakwanovak
5,3961829
5,3961829
Ahah, confirmed, works: jsfiddle.net/nYyxA
– wanovak
Jul 27 '12 at 21:53
A couple unnecessaryfloat
andposition
declarations in there but not a bad way of doing it.
– Wex
Jul 27 '12 at 22:12
I tried to do it correctly the first time without testing it :-) I did, but you're right, it's not perfect.
– wanovak
Jul 27 '12 at 22:14
add a comment |
Ahah, confirmed, works: jsfiddle.net/nYyxA
– wanovak
Jul 27 '12 at 21:53
A couple unnecessaryfloat
andposition
declarations in there but not a bad way of doing it.
– Wex
Jul 27 '12 at 22:12
I tried to do it correctly the first time without testing it :-) I did, but you're right, it's not perfect.
– wanovak
Jul 27 '12 at 22:14
Ahah, confirmed, works: jsfiddle.net/nYyxA
– wanovak
Jul 27 '12 at 21:53
Ahah, confirmed, works: jsfiddle.net/nYyxA
– wanovak
Jul 27 '12 at 21:53
A couple unnecessary
float
and position
declarations in there but not a bad way of doing it.– Wex
Jul 27 '12 at 22:12
A couple unnecessary
float
and position
declarations in there but not a bad way of doing it.– Wex
Jul 27 '12 at 22:12
I tried to do it correctly the first time without testing it :-) I did, but you're right, it's not perfect.
– wanovak
Jul 27 '12 at 22:14
I tried to do it correctly the first time without testing it :-) I did, but you're right, it's not perfect.
– wanovak
Jul 27 '12 at 22:14
add a comment |
You could just use a minus margin
http://jsfiddle.net/gAKAK/
add a comment |
You could just use a minus margin
http://jsfiddle.net/gAKAK/
add a comment |
You could just use a minus margin
http://jsfiddle.net/gAKAK/
You could just use a minus margin
http://jsfiddle.net/gAKAK/
answered Jul 27 '12 at 21:54
AndyAndy
12.6k24071
12.6k24071
add a comment |
add a comment |
This is kind of a complex request, so don't feel bad that you weren't able to figure it out. You shouldn't have to set the width
of anything other than your sidebar for this solution; my solution relies on an uncommon use of overflow: hidden
to achieve this.
http://jsfiddle.net/Wexcode/uBQEu/
HTML:
<div id="header"></div>
<div id="white"></div>
<div id="green"></div>
CSS:
#header
background: red;
height: 70px;
border: 1px solid #000;
#white
background: #fff;
float: left;
margin: -30px 0 0 70px;
width: 100px;
height: 230px;
border: 1px solid #000;
#green
background: green;
overflow: hidden;
height: 201px;
border: 1px solid #000;
border-top: 0;
border-left: 0;
A good article on whyoverflow: hidden;
helps in this situation can be found here: colinaarts.com/articles/the-magic-of-overflow-hidden
– Wex
Jul 27 '12 at 22:06
Still doesn't tell me why floats are not a hack and the wrong tool in most cases. I have used floats to many times myself, before I realised that using position relative and absolute is so much easier in many cases. Even in flexible layouts.
– Split Your Infinity
Jul 27 '12 at 22:22
I don't know why you keep referring tofloat
as a hack. I guess it's just a matter of personal preference. Usingfloat
seems to have saved the trouble of adding an arbitrary container.
– Wex
Jul 27 '12 at 22:27
add a comment |
This is kind of a complex request, so don't feel bad that you weren't able to figure it out. You shouldn't have to set the width
of anything other than your sidebar for this solution; my solution relies on an uncommon use of overflow: hidden
to achieve this.
http://jsfiddle.net/Wexcode/uBQEu/
HTML:
<div id="header"></div>
<div id="white"></div>
<div id="green"></div>
CSS:
#header
background: red;
height: 70px;
border: 1px solid #000;
#white
background: #fff;
float: left;
margin: -30px 0 0 70px;
width: 100px;
height: 230px;
border: 1px solid #000;
#green
background: green;
overflow: hidden;
height: 201px;
border: 1px solid #000;
border-top: 0;
border-left: 0;
A good article on whyoverflow: hidden;
helps in this situation can be found here: colinaarts.com/articles/the-magic-of-overflow-hidden
– Wex
Jul 27 '12 at 22:06
Still doesn't tell me why floats are not a hack and the wrong tool in most cases. I have used floats to many times myself, before I realised that using position relative and absolute is so much easier in many cases. Even in flexible layouts.
– Split Your Infinity
Jul 27 '12 at 22:22
I don't know why you keep referring tofloat
as a hack. I guess it's just a matter of personal preference. Usingfloat
seems to have saved the trouble of adding an arbitrary container.
– Wex
Jul 27 '12 at 22:27
add a comment |
This is kind of a complex request, so don't feel bad that you weren't able to figure it out. You shouldn't have to set the width
of anything other than your sidebar for this solution; my solution relies on an uncommon use of overflow: hidden
to achieve this.
http://jsfiddle.net/Wexcode/uBQEu/
HTML:
<div id="header"></div>
<div id="white"></div>
<div id="green"></div>
CSS:
#header
background: red;
height: 70px;
border: 1px solid #000;
#white
background: #fff;
float: left;
margin: -30px 0 0 70px;
width: 100px;
height: 230px;
border: 1px solid #000;
#green
background: green;
overflow: hidden;
height: 201px;
border: 1px solid #000;
border-top: 0;
border-left: 0;
This is kind of a complex request, so don't feel bad that you weren't able to figure it out. You shouldn't have to set the width
of anything other than your sidebar for this solution; my solution relies on an uncommon use of overflow: hidden
to achieve this.
http://jsfiddle.net/Wexcode/uBQEu/
HTML:
<div id="header"></div>
<div id="white"></div>
<div id="green"></div>
CSS:
#header
background: red;
height: 70px;
border: 1px solid #000;
#white
background: #fff;
float: left;
margin: -30px 0 0 70px;
width: 100px;
height: 230px;
border: 1px solid #000;
#green
background: green;
overflow: hidden;
height: 201px;
border: 1px solid #000;
border-top: 0;
border-left: 0;
answered Jul 27 '12 at 22:03
WexWex
11.3k84789
11.3k84789
A good article on whyoverflow: hidden;
helps in this situation can be found here: colinaarts.com/articles/the-magic-of-overflow-hidden
– Wex
Jul 27 '12 at 22:06
Still doesn't tell me why floats are not a hack and the wrong tool in most cases. I have used floats to many times myself, before I realised that using position relative and absolute is so much easier in many cases. Even in flexible layouts.
– Split Your Infinity
Jul 27 '12 at 22:22
I don't know why you keep referring tofloat
as a hack. I guess it's just a matter of personal preference. Usingfloat
seems to have saved the trouble of adding an arbitrary container.
– Wex
Jul 27 '12 at 22:27
add a comment |
A good article on whyoverflow: hidden;
helps in this situation can be found here: colinaarts.com/articles/the-magic-of-overflow-hidden
– Wex
Jul 27 '12 at 22:06
Still doesn't tell me why floats are not a hack and the wrong tool in most cases. I have used floats to many times myself, before I realised that using position relative and absolute is so much easier in many cases. Even in flexible layouts.
– Split Your Infinity
Jul 27 '12 at 22:22
I don't know why you keep referring tofloat
as a hack. I guess it's just a matter of personal preference. Usingfloat
seems to have saved the trouble of adding an arbitrary container.
– Wex
Jul 27 '12 at 22:27
A good article on why
overflow: hidden;
helps in this situation can be found here: colinaarts.com/articles/the-magic-of-overflow-hidden– Wex
Jul 27 '12 at 22:06
A good article on why
overflow: hidden;
helps in this situation can be found here: colinaarts.com/articles/the-magic-of-overflow-hidden– Wex
Jul 27 '12 at 22:06
Still doesn't tell me why floats are not a hack and the wrong tool in most cases. I have used floats to many times myself, before I realised that using position relative and absolute is so much easier in many cases. Even in flexible layouts.
– Split Your Infinity
Jul 27 '12 at 22:22
Still doesn't tell me why floats are not a hack and the wrong tool in most cases. I have used floats to many times myself, before I realised that using position relative and absolute is so much easier in many cases. Even in flexible layouts.
– Split Your Infinity
Jul 27 '12 at 22:22
I don't know why you keep referring to
float
as a hack. I guess it's just a matter of personal preference. Using float
seems to have saved the trouble of adding an arbitrary container.– Wex
Jul 27 '12 at 22:27
I don't know why you keep referring to
float
as a hack. I guess it's just a matter of personal preference. Using float
seems to have saved the trouble of adding an arbitrary container.– Wex
Jul 27 '12 at 22:27
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11696038%2fcss-positioning-2-shifted-columns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
alistapart.com/topics/topic/css
– Wex
Jul 27 '12 at 21:46