Split page vertically using CSS
Sorry guys for the really simple question but I have tried to float one div left and one right with predefined widths along these lines
<div style="width: 100%;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
Although this 'mostly' works it seems to mess up the other elements on the page below it.
So what is the correct why to split a HTML page vertically into two parts using CSS without effecting other elements on the page?
css html
add a comment |
Sorry guys for the really simple question but I have tried to float one div left and one right with predefined widths along these lines
<div style="width: 100%;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
Although this 'mostly' works it seems to mess up the other elements on the page below it.
So what is the correct why to split a HTML page vertically into two parts using CSS without effecting other elements on the page?
css html
add a comment |
Sorry guys for the really simple question but I have tried to float one div left and one right with predefined widths along these lines
<div style="width: 100%;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
Although this 'mostly' works it seems to mess up the other elements on the page below it.
So what is the correct why to split a HTML page vertically into two parts using CSS without effecting other elements on the page?
css html
Sorry guys for the really simple question but I have tried to float one div left and one right with predefined widths along these lines
<div style="width: 100%;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
Although this 'mostly' works it seems to mess up the other elements on the page below it.
So what is the correct why to split a HTML page vertically into two parts using CSS without effecting other elements on the page?
css html
css html
edited Jul 26 '12 at 5:00
Mr. Alien
119k26225232
119k26225232
asked Jul 26 '12 at 4:52
Maxim GershkovichMaxim Gershkovich
18k33115209
18k33115209
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
you can use..
<div style="width: 100%;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
<div style="clear:both"></div>
now element below this will not be affected.
4
While this would work, it's considered bad practice to add elements whose only function is to "clear content".
– Tieson T.
Jul 26 '12 at 5:00
6
What's the best practice in these cases then? (I've been wondering for a while how to avoid "clearfix" divs)
– Attila Fulop
Feb 5 '13 at 16:32
what if I need a line between them? can't use left|right border since I don't know which one will be larger all the time...
– gcb
Mar 23 '13 at 6:12
add a comment |
Just add overflow:auto; to parent div
<div style="width: 100%;overflow:auto;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
Working Demo
1
you just putheight: 400px;
on both sides.
– gcb
Mar 23 '13 at 6:11
add a comment |
I guess your elements on the page messes up because you don't clear out your floats, check this out
Demo
HTML
<div class="wrap">
<div class="floatleft"></div>
<div class="floatright"></div>
<div style="clear: both;"></div>
</div>
CSS
.wrap {
width: 100%;
}
.floatleft {
float:left;
width: 80%;
background-color: #ff0000;
height: 400px;
}
.floatright {
float: right;
background-color: #00ff00;
height: 400px;
width: 20%;
}
probably the best answer, thanks
– Anton Semenichenko
May 20 '18 at 13:01
add a comment |
There can also be a solution by having both float
to left
.
Try this out:
Working Demo
P.S. This is just an improvement of Ankit's Answer
add a comment |
Check out this fiddle:
http://jsfiddle.net/G6N5T/1574/
CSS/HTML code:
.wrap {
width: 100%;
overflow:auto;
}
.fleft {
float:left;
width: 33%;
background:lightblue;
height: 400px;
}
.fcenter{
float:left;
width: 33%;
background:lightgreen;
height:400px;
margin-left:0.25%;
}
.fright {
float: right;
background:pink;
height: 400px;
width: 33.5%;
}
<div class="wrap">
<!--Updated on 10/8/2016; fixed center alignment percentage-->
<div class="fleft">Left</div>
<div class="fcenter">Center</div>
<div class="fright">Right</div>
</div>
This uses the CSS float
property for left, right, and center alignments of div
s on a page.
This snippet is just a modification of this JSFiddle (click me!).
– Stardust
Aug 19 '15 at 17:13
add a comment |
Alternatively, you can also use a special function known as the linear-gradient() function to split browser screen into two equal halves.
Check out the following code snippet:
body
{
background-image:linear-gradient(90deg, lightblue 50%, skyblue 50%);
}
Here, linear-gradient() function accepts three arguments
90deg
for vertical division of screen.( Similarly, you can use180deg
for horizontal division of screen)
lightblue
color is used to represent the left half of the screen.
skyblue
color has been used to represent the right half of the split screen.
Here,50%
has been used for equal division of the browser screen. You can use any other value if you don't want an equal division of the screen.
Hope this helps. :)
Happy Coding!
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%2f11662536%2fsplit-page-vertically-using-css%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
you can use..
<div style="width: 100%;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
<div style="clear:both"></div>
now element below this will not be affected.
4
While this would work, it's considered bad practice to add elements whose only function is to "clear content".
– Tieson T.
Jul 26 '12 at 5:00
6
What's the best practice in these cases then? (I've been wondering for a while how to avoid "clearfix" divs)
– Attila Fulop
Feb 5 '13 at 16:32
what if I need a line between them? can't use left|right border since I don't know which one will be larger all the time...
– gcb
Mar 23 '13 at 6:12
add a comment |
you can use..
<div style="width: 100%;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
<div style="clear:both"></div>
now element below this will not be affected.
4
While this would work, it's considered bad practice to add elements whose only function is to "clear content".
– Tieson T.
Jul 26 '12 at 5:00
6
What's the best practice in these cases then? (I've been wondering for a while how to avoid "clearfix" divs)
– Attila Fulop
Feb 5 '13 at 16:32
what if I need a line between them? can't use left|right border since I don't know which one will be larger all the time...
– gcb
Mar 23 '13 at 6:12
add a comment |
you can use..
<div style="width: 100%;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
<div style="clear:both"></div>
now element below this will not be affected.
you can use..
<div style="width: 100%;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
<div style="clear:both"></div>
now element below this will not be affected.
answered Jul 26 '12 at 4:55
Ashwini AgarwalAshwini Agarwal
4,17723255
4,17723255
4
While this would work, it's considered bad practice to add elements whose only function is to "clear content".
– Tieson T.
Jul 26 '12 at 5:00
6
What's the best practice in these cases then? (I've been wondering for a while how to avoid "clearfix" divs)
– Attila Fulop
Feb 5 '13 at 16:32
what if I need a line between them? can't use left|right border since I don't know which one will be larger all the time...
– gcb
Mar 23 '13 at 6:12
add a comment |
4
While this would work, it's considered bad practice to add elements whose only function is to "clear content".
– Tieson T.
Jul 26 '12 at 5:00
6
What's the best practice in these cases then? (I've been wondering for a while how to avoid "clearfix" divs)
– Attila Fulop
Feb 5 '13 at 16:32
what if I need a line between them? can't use left|right border since I don't know which one will be larger all the time...
– gcb
Mar 23 '13 at 6:12
4
4
While this would work, it's considered bad practice to add elements whose only function is to "clear content".
– Tieson T.
Jul 26 '12 at 5:00
While this would work, it's considered bad practice to add elements whose only function is to "clear content".
– Tieson T.
Jul 26 '12 at 5:00
6
6
What's the best practice in these cases then? (I've been wondering for a while how to avoid "clearfix" divs)
– Attila Fulop
Feb 5 '13 at 16:32
What's the best practice in these cases then? (I've been wondering for a while how to avoid "clearfix" divs)
– Attila Fulop
Feb 5 '13 at 16:32
what if I need a line between them? can't use left|right border since I don't know which one will be larger all the time...
– gcb
Mar 23 '13 at 6:12
what if I need a line between them? can't use left|right border since I don't know which one will be larger all the time...
– gcb
Mar 23 '13 at 6:12
add a comment |
Just add overflow:auto; to parent div
<div style="width: 100%;overflow:auto;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
Working Demo
1
you just putheight: 400px;
on both sides.
– gcb
Mar 23 '13 at 6:11
add a comment |
Just add overflow:auto; to parent div
<div style="width: 100%;overflow:auto;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
Working Demo
1
you just putheight: 400px;
on both sides.
– gcb
Mar 23 '13 at 6:11
add a comment |
Just add overflow:auto; to parent div
<div style="width: 100%;overflow:auto;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
Working Demo
Just add overflow:auto; to parent div
<div style="width: 100%;overflow:auto;">
<div style="float:left; width: 80%">
</div>
<div style="float:right;">
</div>
</div>
Working Demo
edited Jul 26 '12 at 5:02
answered Jul 26 '12 at 4:55
bugwheels94bugwheels94
21.4k32851
21.4k32851
1
you just putheight: 400px;
on both sides.
– gcb
Mar 23 '13 at 6:11
add a comment |
1
you just putheight: 400px;
on both sides.
– gcb
Mar 23 '13 at 6:11
1
1
you just put
height: 400px;
on both sides.– gcb
Mar 23 '13 at 6:11
you just put
height: 400px;
on both sides.– gcb
Mar 23 '13 at 6:11
add a comment |
I guess your elements on the page messes up because you don't clear out your floats, check this out
Demo
HTML
<div class="wrap">
<div class="floatleft"></div>
<div class="floatright"></div>
<div style="clear: both;"></div>
</div>
CSS
.wrap {
width: 100%;
}
.floatleft {
float:left;
width: 80%;
background-color: #ff0000;
height: 400px;
}
.floatright {
float: right;
background-color: #00ff00;
height: 400px;
width: 20%;
}
probably the best answer, thanks
– Anton Semenichenko
May 20 '18 at 13:01
add a comment |
I guess your elements on the page messes up because you don't clear out your floats, check this out
Demo
HTML
<div class="wrap">
<div class="floatleft"></div>
<div class="floatright"></div>
<div style="clear: both;"></div>
</div>
CSS
.wrap {
width: 100%;
}
.floatleft {
float:left;
width: 80%;
background-color: #ff0000;
height: 400px;
}
.floatright {
float: right;
background-color: #00ff00;
height: 400px;
width: 20%;
}
probably the best answer, thanks
– Anton Semenichenko
May 20 '18 at 13:01
add a comment |
I guess your elements on the page messes up because you don't clear out your floats, check this out
Demo
HTML
<div class="wrap">
<div class="floatleft"></div>
<div class="floatright"></div>
<div style="clear: both;"></div>
</div>
CSS
.wrap {
width: 100%;
}
.floatleft {
float:left;
width: 80%;
background-color: #ff0000;
height: 400px;
}
.floatright {
float: right;
background-color: #00ff00;
height: 400px;
width: 20%;
}
I guess your elements on the page messes up because you don't clear out your floats, check this out
Demo
HTML
<div class="wrap">
<div class="floatleft"></div>
<div class="floatright"></div>
<div style="clear: both;"></div>
</div>
CSS
.wrap {
width: 100%;
}
.floatleft {
float:left;
width: 80%;
background-color: #ff0000;
height: 400px;
}
.floatright {
float: right;
background-color: #00ff00;
height: 400px;
width: 20%;
}
edited Mar 30 '18 at 6:26
Aakash Patel
342114
342114
answered Jul 26 '12 at 4:57
Mr. AlienMr. Alien
119k26225232
119k26225232
probably the best answer, thanks
– Anton Semenichenko
May 20 '18 at 13:01
add a comment |
probably the best answer, thanks
– Anton Semenichenko
May 20 '18 at 13:01
probably the best answer, thanks
– Anton Semenichenko
May 20 '18 at 13:01
probably the best answer, thanks
– Anton Semenichenko
May 20 '18 at 13:01
add a comment |
There can also be a solution by having both float
to left
.
Try this out:
Working Demo
P.S. This is just an improvement of Ankit's Answer
add a comment |
There can also be a solution by having both float
to left
.
Try this out:
Working Demo
P.S. This is just an improvement of Ankit's Answer
add a comment |
There can also be a solution by having both float
to left
.
Try this out:
Working Demo
P.S. This is just an improvement of Ankit's Answer
There can also be a solution by having both float
to left
.
Try this out:
Working Demo
P.S. This is just an improvement of Ankit's Answer
edited Jul 23 '13 at 6:08
bugwheels94
21.4k32851
21.4k32851
answered Dec 21 '12 at 17:39
AnkurAnkur
1,7511724
1,7511724
add a comment |
add a comment |
Check out this fiddle:
http://jsfiddle.net/G6N5T/1574/
CSS/HTML code:
.wrap {
width: 100%;
overflow:auto;
}
.fleft {
float:left;
width: 33%;
background:lightblue;
height: 400px;
}
.fcenter{
float:left;
width: 33%;
background:lightgreen;
height:400px;
margin-left:0.25%;
}
.fright {
float: right;
background:pink;
height: 400px;
width: 33.5%;
}
<div class="wrap">
<!--Updated on 10/8/2016; fixed center alignment percentage-->
<div class="fleft">Left</div>
<div class="fcenter">Center</div>
<div class="fright">Right</div>
</div>
This uses the CSS float
property for left, right, and center alignments of div
s on a page.
This snippet is just a modification of this JSFiddle (click me!).
– Stardust
Aug 19 '15 at 17:13
add a comment |
Check out this fiddle:
http://jsfiddle.net/G6N5T/1574/
CSS/HTML code:
.wrap {
width: 100%;
overflow:auto;
}
.fleft {
float:left;
width: 33%;
background:lightblue;
height: 400px;
}
.fcenter{
float:left;
width: 33%;
background:lightgreen;
height:400px;
margin-left:0.25%;
}
.fright {
float: right;
background:pink;
height: 400px;
width: 33.5%;
}
<div class="wrap">
<!--Updated on 10/8/2016; fixed center alignment percentage-->
<div class="fleft">Left</div>
<div class="fcenter">Center</div>
<div class="fright">Right</div>
</div>
This uses the CSS float
property for left, right, and center alignments of div
s on a page.
This snippet is just a modification of this JSFiddle (click me!).
– Stardust
Aug 19 '15 at 17:13
add a comment |
Check out this fiddle:
http://jsfiddle.net/G6N5T/1574/
CSS/HTML code:
.wrap {
width: 100%;
overflow:auto;
}
.fleft {
float:left;
width: 33%;
background:lightblue;
height: 400px;
}
.fcenter{
float:left;
width: 33%;
background:lightgreen;
height:400px;
margin-left:0.25%;
}
.fright {
float: right;
background:pink;
height: 400px;
width: 33.5%;
}
<div class="wrap">
<!--Updated on 10/8/2016; fixed center alignment percentage-->
<div class="fleft">Left</div>
<div class="fcenter">Center</div>
<div class="fright">Right</div>
</div>
This uses the CSS float
property for left, right, and center alignments of div
s on a page.
Check out this fiddle:
http://jsfiddle.net/G6N5T/1574/
CSS/HTML code:
.wrap {
width: 100%;
overflow:auto;
}
.fleft {
float:left;
width: 33%;
background:lightblue;
height: 400px;
}
.fcenter{
float:left;
width: 33%;
background:lightgreen;
height:400px;
margin-left:0.25%;
}
.fright {
float: right;
background:pink;
height: 400px;
width: 33.5%;
}
<div class="wrap">
<!--Updated on 10/8/2016; fixed center alignment percentage-->
<div class="fleft">Left</div>
<div class="fcenter">Center</div>
<div class="fright">Right</div>
</div>
This uses the CSS float
property for left, right, and center alignments of div
s on a page.
.wrap {
width: 100%;
overflow:auto;
}
.fleft {
float:left;
width: 33%;
background:lightblue;
height: 400px;
}
.fcenter{
float:left;
width: 33%;
background:lightgreen;
height:400px;
margin-left:0.25%;
}
.fright {
float: right;
background:pink;
height: 400px;
width: 33.5%;
}
<div class="wrap">
<!--Updated on 10/8/2016; fixed center alignment percentage-->
<div class="fleft">Left</div>
<div class="fcenter">Center</div>
<div class="fright">Right</div>
</div>
.wrap {
width: 100%;
overflow:auto;
}
.fleft {
float:left;
width: 33%;
background:lightblue;
height: 400px;
}
.fcenter{
float:left;
width: 33%;
background:lightgreen;
height:400px;
margin-left:0.25%;
}
.fright {
float: right;
background:pink;
height: 400px;
width: 33.5%;
}
<div class="wrap">
<!--Updated on 10/8/2016; fixed center alignment percentage-->
<div class="fleft">Left</div>
<div class="fcenter">Center</div>
<div class="fright">Right</div>
</div>
edited Oct 8 '16 at 15:20
answered Aug 19 '15 at 17:11
StardustStardust
4551517
4551517
This snippet is just a modification of this JSFiddle (click me!).
– Stardust
Aug 19 '15 at 17:13
add a comment |
This snippet is just a modification of this JSFiddle (click me!).
– Stardust
Aug 19 '15 at 17:13
This snippet is just a modification of this JSFiddle (click me!).
– Stardust
Aug 19 '15 at 17:13
This snippet is just a modification of this JSFiddle (click me!).
– Stardust
Aug 19 '15 at 17:13
add a comment |
Alternatively, you can also use a special function known as the linear-gradient() function to split browser screen into two equal halves.
Check out the following code snippet:
body
{
background-image:linear-gradient(90deg, lightblue 50%, skyblue 50%);
}
Here, linear-gradient() function accepts three arguments
90deg
for vertical division of screen.( Similarly, you can use180deg
for horizontal division of screen)
lightblue
color is used to represent the left half of the screen.
skyblue
color has been used to represent the right half of the split screen.
Here,50%
has been used for equal division of the browser screen. You can use any other value if you don't want an equal division of the screen.
Hope this helps. :)
Happy Coding!
add a comment |
Alternatively, you can also use a special function known as the linear-gradient() function to split browser screen into two equal halves.
Check out the following code snippet:
body
{
background-image:linear-gradient(90deg, lightblue 50%, skyblue 50%);
}
Here, linear-gradient() function accepts three arguments
90deg
for vertical division of screen.( Similarly, you can use180deg
for horizontal division of screen)
lightblue
color is used to represent the left half of the screen.
skyblue
color has been used to represent the right half of the split screen.
Here,50%
has been used for equal division of the browser screen. You can use any other value if you don't want an equal division of the screen.
Hope this helps. :)
Happy Coding!
add a comment |
Alternatively, you can also use a special function known as the linear-gradient() function to split browser screen into two equal halves.
Check out the following code snippet:
body
{
background-image:linear-gradient(90deg, lightblue 50%, skyblue 50%);
}
Here, linear-gradient() function accepts three arguments
90deg
for vertical division of screen.( Similarly, you can use180deg
for horizontal division of screen)
lightblue
color is used to represent the left half of the screen.
skyblue
color has been used to represent the right half of the split screen.
Here,50%
has been used for equal division of the browser screen. You can use any other value if you don't want an equal division of the screen.
Hope this helps. :)
Happy Coding!
Alternatively, you can also use a special function known as the linear-gradient() function to split browser screen into two equal halves.
Check out the following code snippet:
body
{
background-image:linear-gradient(90deg, lightblue 50%, skyblue 50%);
}
Here, linear-gradient() function accepts three arguments
90deg
for vertical division of screen.( Similarly, you can use180deg
for horizontal division of screen)
lightblue
color is used to represent the left half of the screen.
skyblue
color has been used to represent the right half of the split screen.
Here,50%
has been used for equal division of the browser screen. You can use any other value if you don't want an equal division of the screen.
Hope this helps. :)
Happy Coding!
answered Jan 1 at 7:48
Raunak MitraRaunak Mitra
11
11
add a comment |
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%2f11662536%2fsplit-page-vertically-using-css%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