I have a page in ASP.NET as follows.
JSFIDDLE http://jsfiddle.net/nyrUp/
HTML
<div class="mainContainer">
<div>
<div class="topLeft">
<% =DateTime.Now.Ticks.ToString()%>
</div>
<div class="topRight">
foo
</div>
</div>
<div>
<div class="bottomLeft">
foo
</div>
<div class="bottomRight">
foo
</div>
</div>
<div class="underneath">
foo
</div>
</div>
CSS
.mainContainer {
}
.topLeft {
width: 50%;
float: left;
background-color: red;
}
.topRight {
width: 50%;
float: left;
background-color: orange;
}
.bottomLeft {
width: 50%;
float: left;
background-color: yellow;
}
.bottomRight {
width: 50%;
float: left;
background-color: green;
}
.underneath {
width: 100%;
background-color: blue;
}
This works fine, until you add content to any div, at which point the layout is broken
JSFIDDLE showing broken layout: http://jsfiddle.net/4gbP8/
How do I maintain this layout when content is added please?
i.e.
So I was able to contain them by placing a container on the blank div, called top. I think if I understand correctly you want each box to fill the page.
http://jsfiddle.net/4gbP8/2/
CSS ADD
.top {
display: inline-block;
width: 100%;
height: 100%;
}
HTML
<div class="top">
<div class="topLeft">
<p>123</p>
<p>123</p>
<p>123</p>
<p>123</p>
</div>
<div class="topRight">
foo
</div>
</div>
I dont know if you are able to update the HTML but I have a solution If you can add in a new class.
I added a class called clear which help to push down the different levels and gives them a bit more structure.
JSFIDDLE
CSS
.clear{clear:both;}
HTML
<div class="mainContainer">
<div class="clear">
<div class="topLeft">
<p>123</p>
<p>123</p>
<p>123</p>
<p>123</p>
</div>
<div class="topRight">
foo
</div>
</div>
<div class="clear">
<div class="bottomLeft">
foo
</div>
<div class="bottomRight">
foo
</div>
</div>
<div class="underneath clear">
foo
</div>
</div>
Let me know if it helps or I could tweek something to make it work better for yourself
You have 2 issues
In order to keep the column distribution you must clear the floats
In order to kept the backgrounds you must use negative margins "equ" exaggerated paddings
You will get this
(
See this fiddle with demo and full coding )
You must include wrapers for each pair of floating elements and some css for the negative margin trick
Markup should be as follows
<div class="mainContainer">
<div class="wrapper">
<div class="topLeft">
<p>123</p>
<p>123</p>
<p>123</p>
<p>123</p>
</div>
<div class="topRight">
foo
</div>
</div>
<div class="wrapper">
<div class="bottomLeft">
foo
</div>
<div class="bottomRight">
<p>123</p>
<p>123</p>
<p>123</p>
<p>123</p>
</div>
</div>
<div class="underneath clear">
foo
</div>
</div>
Each floating div should include
{
...
padding-bottom:2000px;
margin-bottom:-2000px;
...
}
The ....left divs should include
{
...
clear:left;
...
}
And the wraper to be included for each pair of floating divs should be
.wrapper {
overflow:hidden;
}
The table/table-cell display properties can do what you're looking for:
http://jsfiddle.net/4gbP8/3/
.mainContainer {
}
.mainContainer > div {
display: table;
width: 100%;
}
.topLeft {
width: 50%;
display: table-cell;
background-color: red;
}
.topRight {
width: 50%;
display: table-cell;
background-color: orange;
}
.bottomLeft {
width: 50%;
display: table-cell;
background-color: yellow;
}
.bottomRight {
width: 50%;
display: table-cell;
background-color: green;
}
.underneath {
width: 100%;
background-color: blue;
}
If the content needs to reflow for narrow devices, hide the display properties behind a media query targeting wider devices.
Related
Is it possible to fill an entire page with 16 divs but still have it responsive so it can be viewed on different devices. At the moment I have only used percentages but I am open to other solutions if there are any.
-How it is suppose to look.
The webpage has to contain 16 divs in total four spread across the top first quater of the webpage four spread across the second quarter of the page four spread across the third quarter of the page and four spread across the forth quarter of the page.
So overall it is suppose to look like a big cube or look like the 2408 game http://gabrielecirulli.github.io/2048/
-My code so far
***HTML***
<!doctype html>
<head>
<link rel="stylesheet" href="master.css">
</head>
<!-- ========================================================================================================================= -->
<div id="s1" class="divq"> </div> <div id="s2" class="divq"> </div> <div id="s3" class="divq"> </div> <div id="s4" class="divq"> </div>
<!-- ========================================================================================================================= -->
<div id="s5" class="divq"> </div> <div id="s6" class="divq"> </div> <div id="s7" class="divq"> </div> <div id="s8" class="divq"> </div>
<!-- ========================================================================================================================= -->
<div id="s9" class="divq"> </div> <div id="s10" class="divq"> </div> <div id="s11" class="divq"> </div> <div id="s12" class="divq"> </div>
<!-- ========================================================================================================================= -->
<div id="s13" class="divq"> </div> <div id="s14" class="divq"> </div> <div id="s15" class="divq"> </div> <div id="s16" class="divq"> </div>
<!-- ========================================================================================================================= -->
***CSS***
html {
height: 100%;
width: 100%;
margin: 0px;
}
body {
height: 100%;
width: 100%;
margin: 0px;
}
.divq {
height: 25%;
margin: 0px;
width: 25%;
}
#s1 {
background-color: rgb(100,100,100);
float: left;
}
#s2 {
background-color: rgb(120,100,100);
}
#s3 {
background-color: rgb(100,120,100);
}
#s4 {
background-color: rgb(100,100,120);
float: right;
}
#s5 {
background-color: rgb(140,100,100);
float: left;
}
#s6 {
background-color: rgb(100,140,100);
}
#s7 {
background-color: rgb(100,100,140);
}
#s8 {
background-color: rgb(160,100,100);
float: right;
}
#s9 {
background-color: rgb(100,160,100);
float: left;
}
#s10 {
background-color: rgb(100,100,160);
}
#s11 {
background-color: rgb(180,100,100);
}
#s12 {
background-color: rgb(100,180,100);
float: right;
}
#s13 {
background-color: rgb(100,100,180);
float: left;
}
#s14 {
background-color: rgb(200,100,100);
}
#s15 {
background-color: rgb(100,200,100);
}
#s16 {
background-color: rgb(100,100,200);
float: right;
}
Make them all float: left, and don't forget to add box-sizing: border-box to all elements (via .divq)
That way you can add margings and paddings without breakting your grid.
If you are fine with flexbox, you can span four rows inside a wrapper with display: flex and flex-direction: column, each including four columns.
Sample Fiddle:
http://fiddle.jshell.net/n50tnnka/2/
Maybe you could try using a Bootstrap grid? It's fairly easy to use!
Just give your div's the class col-md-3. That way, the div's will know they can take up 3/12th of the screen = 25% = 4 divs per row.
If you then contain all these divs in one parent div with fixed width and height, you should be fine.
<div id="cube">
<div class="col-md-3" id="s1"></div>
<div class="col-md-3" id="s2"></div>
<div class="col-md-3" id="s3"></div>
<div class="col-md-3" id="s4"></div>
<div class="col-md-3" id="s5"></div>
<div class="col-md-3" id="s6"></div>
<div class="col-md-3" id="s7"></div>
<div class="col-md-3" id="s8"></div>
<div class="col-md-3" id="s9"></div>
<div class="col-md-3" id="s10"></div>
<div class="col-md-3" id="s11"></div>
<div class="col-md-3" id="s12"></div>
<div class="col-md-3" id="s13"></div>
<div class="col-md-3" id="s14"></div>
<div class="col-md-3" id="s15"></div>
<div class="col-md-3" id="s16"></div>
</div>
By still using the id's you can give any square the color you like, but by using bootstrap you won't have to use float.
You can do this easily with Flexbox like this
DEMO
.content {
display: flex;
height: 100vh;
width: 100vw;
flex-wrap: wrap;
box-sizing: border-box;
}
.box {
flex: 25%;
border: 1px solid black;
padding: 5px;
box-sizing: border-box;
}
<div class="content">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
For better browser support (than flex) you can use display table-cell for your elements
But you will have to nest each "row" (four divs) in a parent element:
HTML:
<div class="row">
<div id="s1" class="divq"> </div>
<div id="s2" class="divq"></div>
<div id="s3" class="divq"> </div>
<div id="s4" class="divq"> </div>
</div>
CSS:
html {
height: 100%;
width: 100%;
margin: 0px;
}
body {
height: 100%;
width: 100%;
margin: 0px;
}
div {
box-sizing:border-box;
}
.row{
display: table;
table-layout: fixed;
border-spacing:0px;
width:100%;
height:25%;
}
.divq {
display:table-cell;
height: 25%;
width: 25%;
}
DEMO: https://jsfiddle.net/Nillervision/06z1L5tg/
I am using bootstrap and I have two container inside a bootstrap container. Like this:
<div class="container">
<div id="container-map">
aasdasd
</div>
<div id="container-buttons">
asdasda
</div>
</div>
What I am trying to do is center the two divs, #container-map and #container-buttons side by side, inside the main container.
This is my custom CSS for the two divs:
#container-map,
#container-buttons {
display: inline-block;
margin: 0 auto 0 auto;
width: 500px;
height: 500px;
}
Is there a reason you don't want to use the bootstraps built in gridsystem? Something like this?
<div class="container">
<div class="row">
<div class="col-md-3 col-md-offset-3">
<div class="container-map">
asdf
</div>
</div>
<div class="col-md-3">
<div class="container-buttons">
asdf
</div>
</div>
</div>
</div>
Just change your CSS to this
#container-map,
#container-buttons {
float: left;
margin-left: auto;
}
Both containers will be centered and side by side
You can try the code from this example (using text-align: center; on .container display:inline-block; for divs).
<style>
.container {
position:relative;
text-align:center;
}
#dv1, #dv2 {
display:inline-block;
width:100px;
margin:0 3px;
background:#33f;
}
</style>
<div class="container">
<div id="dv1">Div 1</div>
<div id="dv2">Div 2</div>
</div>
you make both your divs to take equal height using flex. You can refer the link to find out the browsers which support it. Have a look at this:
.container {
display: flex;
width: 400px;
background: #eee;
}
.column {
flex: 1;
background: #fff;
border: 1px solid #ccc;
margin: 1px;
}
<div class="container">
<div class="column">
<p>aasdasd</p>
</div>
<div class="column">
<p>asdasda</p>
<p>asdasda</p>
</div>
</div>
The best way to describe what I want to do is using this image. As you can see I have 3 different images as background (which are three different Divs) and I want to insert 3 List Points (here named as: "LV", "RP", "IP") with a centred description/heading below (here as: Lv: 15, RP: 16975 and so on).
My biggest problem is to handle the centred width of those elements. I have no idea how to solve this the best way regarding the CSS.
My HTML:
<div class="package">
<div class="item-description">
<div class="col-md-3"><span class="title">LV</span><span class="description">15</span></div>
<div class="col-md-3"><span class="title">RP<span><span class="description">16975</span></div>
<div class="col-md-3"><span class="title">IP<span><span class="description">40000</span></div>
</div>
</div>
Are you looking for something like this?
It's using quite a few elements (which could possibly be converted into pseudo elements), but it shows a general overview of what you might be looking for.
Also, with the id's and classes this shouldn't make it too hard to alter for your needs.
.container {
width: 32%;
height: 200px;
background: red;
display: inline-block;
}
.container .title {
margin-top: 100px;
width: 32%;
height: 100%;
display: inline-block;
vertical-align: middle;
text-align: center;
color: white;
}
#one {
background: url(http://placekitten.com/g/300/300);
}
#two {
background: url(http://placekitten.com/g/200/200);
}
#three {
background: url(http://placekitten.com/g/300/200);
}
<div id="one" class="container">
<div class="title">200
<div class="desc">I'm a very long description</div>
</div>
<div class="title">300
<div class="desc">desc</div>
</div>
<div class="title">400
<div class="desc">Be More Dog</div>
</div>
</div>
<div id="two" class="container">
<div class="title">200
<div class="desc">desc</div>
</div>
<div class="title">300
<div class="desc">I'm a tree.</div>
</div>
<div class="title">400
<div class="desc">What is a description?</div>
</div>
</div>
<div id="three" class="container">
<div class="title">200
<div class="desc">desc</div>
</div>
<div class="title">300
<div class="desc">a description of what?</div>
</div>
<div class="title">400
<div class="desc">Don't you like, er, trees?</div>
</div>
</div>
this might also work:
Note: I've used a pseudo effect here, but to keep my code 'minimal', rather than applying it to individual items (as you would for individual descriptions), i've just used an existing item.
html,
body {
margin: 0;
padding: 0;
}
.sec {
width: 33%;
height: 200px;
background: red;
background: url(http://placekitten.com/g/200/200);
position: relative;
text-align: center;
color: white;
vertical-align: middle;
display: inline-block;
line-height: 200px;
margin-left: -0.5%;
}
.col {
width: 32%;
margin-left: -0.5%;
font-size: 25px;
display: inline-block;
position:relative;
}
.col:after{
padding-top:25px;
font-size: 10px;
position:absolute;
content:"description";
left:25%;
}
<div class="sec">
<div class="col">
title
</div>
<div class="col">
title2
</div>
<div class="col">
title3
</div>
</div>
<div class="sec">
<div class="col">
title
</div>
<div class="col">
title2
</div>
<div class="col">
title3
</div>
</div>
<div class="sec">
<div class="col">
title
</div>
<div class="col">
title2
</div>
<div class="col">
title3
</div>
</div>
Try this in your css
.description, .title{float:left; width:100%; text-align:center;}
So my logic of Div ID's and Classes must be WAY off.
Heres whats going on:
As you can see the blocks which say PS don't align center with the slider (Which is inside a container.
Here is my css:
/*Front Page Buttons */
#frontpage-Button-Cont {
height: 350px;
}
.button-cont {
width: 175px;
float: left;
margin-left: 10px;
margin-top: 10px;
height: 250px;
}
.thumbnail {
color: #fff;
font-size: 5em;
background: #1f4e9b;
width: 175px;
height: 135px;
text-align: center;
}
.pheader {
color: #DC143C;
min-width: 175px;
text-align: center;
}
.paragraph {
text-align: center;
}
#Align-content {
margin: 0 auto;
}
And here is the html:
<div id="frontpage-Button-Cont">
<div id="Align-content">
<div class="button-cont">
<div class="thumbnail">
PS
</div>
<div class="paragraph">
<div class="pheader">
HEADER
</div>
<p>dadaasdasdadadad
</div>
</div>
<div class="button-cont">
<div class="thumbnail">
PS
</div>
<div class="paragraph">
<div class="pheader">
HEADER
</div>
<p>dadaasdasdadadad
</div>
</div>
<div class="button-cont">
<div class="thumbnail">
PS
</div>
<div class="paragraph">
<div class="pheader">
HEADER
</div>
<p>dadaasdasdadadad
</div>
</div>
<div class="button-cont">
<div class="thumbnail">
PS
</div>
<div class="paragraph">
<div class="pheader">
HEADER
</div>
<p>dadaasdasdadadad
</div>
</div>
</div>
</div>
My theory is that I'm using classes incorrectly?
Thanks.
You can Add this to your CSS
#frontpage-Button-Cont {
width:100%;
}
#Align-content {
display:table;
}
With this your margin:o auto can work
View This Demo http://jsfiddle.net/VGPeW/
You need to make sure that the containing div (in this case frontpage-Button-Cont) is the same width as your slider above it. Then add the property text-align:center to the container. That should fix your issue.
I have a problem in HTML. I have divided the HTML page into two columns:
My code:
<div id="outer">
<div id="inner1">
<div id="data1">
</div>
<div id="response">
</div>
</div>
<div id="inner2">
<div id="data2">
</div>
</div>
</div>
My CSS:
#outer {
background-color:#FFFF99;
}
#inner1 {
float: left;
width: 62%;
}
#inner2 {
float: right;
width: 38%;
}
I need to insert another column #inner1_2 in between inner1 and inner2 which is the optional one.
There is also a third column:
<div id="#inner1_2">
</div>
The problem here is the variable division. Either I have three columns or two columns depending on the data:
inner2 is fixed
If there are three columns of data, .inner1 needs to be split into two halves, otherwise .inner1 remains as it is.
This is more complex logic than I am comfortable with in CSS.
What is the best way to handle this?
Add a class to the outer div that controls how the inner divs are displayed. Setting the class to "twoColumn" hides the middle column and setting the class to "threeColumn" shows the middle column:
<div id="outer" class="twoColumn">
<div id="inner1">
<div id="data1">
</div>
<div id="response">
</div>
</div>
<div id="inner1_2">
</div>
<div id="inner2">
<div id="data2">
</div>
</div>
</div>
css:
#outer { background-color: #FF9; }
#inner1 { float: left; }
#inner1_2 { float: left; }
#inner2 { float: left; width: 38%; }
.twoColumn #inner1 { width: 62% }
.twoColumn #inner1_2 { display: none; }
.threeColumn #inner1 { width: 31%; }
.threeColumn #inner1_2 { width: 31%; }