PureCSS vertical center/middle div elements - html

I'm trying to center my div elements (PureCSS) to build a grid like this (100% width and height, no scrollbar):
Now I need to align all the elements vertically and horizontally centered.
Here is my HTML Code:
<div class="pure-g" style="height:100%;">
<div class="pure-u-1-5" style="height:90%;">
<div class="pure-g" style="height:50%;">
<div class="pure-u-1-1 visible"><img src="img/logo.png" alt="Logo" style="width:100%;"></div>
<div class="pure-u-1-1 visible"><img src="img/ad.png" alt="AD" style="width:100%;"></div>
</div>
</div>
<div class="pure-u-4-5" style="height:90%;">
<div class="pure-g" style="height:100%;">
<div class="pure-u-1-1" style="height:20%;">
<div class="pure-g" style="height:100%;">
<div class="pure-u-1-6 news"><p>PIC</p></div>
<div class="pure-u-1-3 news"><p>TITLE</p></div>
<div class="pure-u-5-12 news"><p>DESCRIPTION</p></div>
<div class="pure-u-1-12 news"><p>ID</p></div>
</div>
</div>
<div class="pure-u-1-1" style="height:20%;">
<div class="pure-g" style="height:100%;">
<div class="pure-u-1-6 news"><p>PIC</p></div>
<div class="pure-u-1-3 news"><p>TITLE</p></div>
<div class="pure-u-5-12 news"><p>DESCRIPTION</p></div>
<div class="pure-u-1-12 news"><p>ID</p></div>
</div>
</div>
<div class="pure-u-1-1" style="height:20%;">
<div class="pure-g" style="height:100%;">
<div class="pure-u-1-6 news"><p>PIC</p></div>
<div class="pure-u-1-3 news"><p>TITLE</p></div>
<div class="pure-u-5-12 news"><p>DESCRIPTION</p></div>
<div class="pure-u-1-12 news"><p>ID</p></div>
</div>
</div>
<div class="pure-u-1-1" style="height:20%;">
<div class="pure-g" style="height:100%;">
<div class="pure-u-1-6 news"><p>PIC</p></div>
<div class="pure-u-1-3 news"><p>TITLE</p></div>
<div class="pure-u-5-12 news"><p>DESCRIPTION</p></div>
<div class="pure-u-1-12 news"><p>ID</p></div>
</div>
</div>
<div class="pure-u-1-1" style="height:20%;">
<div class="pure-g" style="height:100%;">
<div class="pure-u-1-6 news"><p>PIC</p></div>
<div class="pure-u-1-3 news"><p>TITLE</p></div>
<div class="pure-u-5-12 news"><p>DESCRIPTION</p></div>
<div class="pure-u-1-12 news"><p>ID</p></div>
</div>
</div>
</div>
</div>
<div class="pure-u-1-1 marquee">NEWSTICKER (jQuery marquee)</div>
</div>
And here is my CSS:
*{font-family:'Raleway', sans-serif;}
h1, h2, h3, p {color:#fff;}
body, html {
overflow:hidden;
height: 100%;
padding:0px;
}
div {
/*
border:1px solid;
margin:-1px;
*/
}
.news {
height:100%;
position:relative;
background:#444; background:rgba(0,0,0,.5);
margin:0px 0px 0px 0px;
border-radius:0px;
margin-bottom:0px;
}
.visible {
height:100%;
position:relative;
background:#444; background:rgba(0,0,0,.5);
margin:0px 0px 0px 0px;
border-radius:0px;
margin-bottom:0px;
}
.news p {
text-align: center;
vertical-align: middle;
margin:15px;
height:100%;
}
.marquee {
height:100%;
position:relative;
background:#444; background:rgba(0,0,0,.5);
margin:0px 0px 0px 0px;
padding:0px;
border-radius:0px;
margin-bottom:0px;
font-family:'Raleway', sans-serif;
color:#fff;
}
The result is this:
I read some threads for this problem but none of them seemed to work for me getting the div elements vertically centered.
I would also be glad if any of you finds some code improvement since this is my first time building a grid like this.
Thanks in advance

I'd keep it simple, no 3rd party.
This the basic frame work I'd use.
I would not make the images scalable. Too much work for those wimpy ARM processors in smartphones. I'd fix the width of the left column and pic div
I put temporary colored borders on the divs.
CSS
#col1{width:14%;position:absolute;top:0;left:0;}
#col2{width:84%;position:absolute;top:0;right:0;}
#logo{width:200px;height:200px;}
.row{width:100%;border:4px solid #000;display:inline-block;}
.pic{width:15%;border:1px solid #00f;display:inline-block;}
.title{width:30%;border:1px solid #f00;display:inline-block;}
.desc{width:40%;border:1px solid #0ff;display:inline-block;}
.id{width:10%;border:1px solid #f0f;display:inline-block;}
#marquee{height:6em;}<br>
HTML
<div id="col1">
<div id="logo"><img src="img/logo.png" alt="Logo"></div>
<div id="ad"><img src="img/ad.png" alt="AD" ></div>
</div>
<div id="col2">
<div class="row"><div class="pic"><p>PIC</p></div><div class="title"><p>TITLE</p></div><div class="desc"><p>DESCRIPTION</p></div><div class="id"><p>ID</p></div></div>
<div class="row"><div class="pic"><p>PIC</p></div><div class="title"><p>TITLE</p></div><div class="desc"><p>DESCRIPTION</p></div><div class="id"><p>ID</p></div></div>
<div class="row"><div class="pic"><p>PIC</p></div><div class="title"><p>TITLE</p></div><div class="desc"><p>DESCRIPTION</p></div><div class="id"><p>ID</p></div></div>
<div class="row"><div class="pic"><p>PIC</p></div><div class="title"><p>TITLE</p></div><div class="desc"><p>DESCRIPTION</p></div><div class="id"><p>ID</p></div></div>
<div class="row"><div class="pic"><p>PIC</p></div><div class="title"><p>TITLE</p></div><div class="desc"><p>DESCRIPTION</p></div><div class="id"><p>ID</p></div></div>
<div class="row"><div class="pic"><p>PIC</p></div><div class="title"><p>TITLE</p></div><div class="desc"><p>DESCRIPTION</p></div><div class="id"><p>ID</p></div></div>
<div class="row"><div class="pic"><p>PIC</p></div><div class="title"><p>TITLE</p></div><div class="desc"><p>DESCRIPTION</p></div><div class="id"><p>ID</p></div></div>
<div class="row"><div id="marquee">Breaking News</div></div></div>
</div>

This is the CSS / HTML I use to center stuff vertically and horizontally:
<html>
<head>
<style type="text/css" media="screen">
.center-outter {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.center-middle {
display: table-cell;
vertical-align: middle;
}
.center-inner {
margin-left: auto;
margin-right: auto;
/*width:200px;*/
}
.whatever {
width:200px;
background:#efefef;
}
</style>
</head>
<body>
<div class="center-outter">
<div class="center-middle">
<div class="center-inner whatever">
<div>This should be centered vertically and horizontally</div>
</div>
</div>
</div>
</body>
</html>

Related

How is the padding of display:table-cell determined

I'm trying to come out with a table-like layout, with medicine names appearing on the left and the data occupy the rest of the table. Simply put:
+-------------+------------+
medicine 1 | some data | some data |
+-------------+------------+
medicine 2 | some data | some data |
+-------------+------------+
Since I want to keep the data grid dynamic, I use two <div>'s with the style display:table-cell as two containers, the left one for all the medicine names, and the right one for the data grid. There are several inner <div>'s inside these two table-cell <div>'s, but I'm not sure why the left one has a big padding area on the top when I use Chrome inspect interface to investigate it (please see the image below):
I'm not quite sure which part went wrong, and the inspect interface didn't give me information that seems relevant. I want to learn how to approach this situation. Here is the html code for your reference:
<div style="display:table">
<div style="display:table-row">
<div style="display:table-cell">
<div style="height:85px; width:170px; text-align:right; font-size:13px; margin-right:5px">
Dexedrine Spansules (Dextroamphetamine, ER) <br/><span style="font-style:italic">(20mg)</span>
</div>
<div style="height:85px; width:170px; text-align:right; font-size:13px; margin-right:5px">
Methamphetamine (Desoxyn, IR) <br/><span style="font-style:italic">(15mg)</span>
</div>
</div>
<div style="display:table-cell; overflow:hidden; max-width:800px">
<div id="medicine_table_container_2" class="medicine-table-container" style="position:relative; left:0">
<div style="white-space:nowrap; font-size:0px">
<div style="display:inline-block; background-color:yellow; width:130px; height:85px; border:1px solid #999; font-size: 12px; white-space:normal">
<div>
<div style="display:inline-block; width:70px; height:45px">
Morning<br/>-
</div>
<div style="display:inline-block; width:50px; height:45px">
Noon<br/>5mg
</div>
</div>
<div>
<div style="display:inline-block; width:70px; height:35px">
Afternoon<br/>12mg
</div>
<div style="display:inline-block; width:50px; height:35px">
Evening<br/>-
</div>
</div>
</div>
</div>
<div style="white-space:nowrap; font-size:0px">
<div style="display:inline-block; background-color:yellow; width:130px; height:85px; border:1px solid #999; font-size: 12px; white-space:normal">
<div>
<div style="display:inline-block; width:70px; height:45px">
Morning<br/>-
</div>
<div style="display:inline-block; width:50px; height:45px">
Noon<br/>5mg
</div>
</div>
<div>
<div style="display:inline-block; width:70px; height:35px">
Afternoon<br/>12mg
</div>
<div style="display:inline-block; width:50px; height:35px">
Evening<br/>-
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
This is about vertical alignment. The default one is set to baseline and produce this output. Simply change the alignment to top on the table-cell and you won't have this issue:
<div style="display:table">
<div style="display:table-row">
<div style="display:table-cell;
vertical-align: top;">
<div style="height:85px; width:170px; text-align:right; font-size:13px; margin-right:5px">
Dexedrine Spansules (Dextroamphetamine, ER) <br/><span style="font-style:italic">(20mg)</span>
</div>
<div style="height:85px; width:170px; text-align:right; font-size:13px; margin-right:5px">
Methamphetamine (Desoxyn, IR) <br/><span style="font-style:italic">(15mg)</span>
</div>
</div>
<div style="display:table-cell;
vertical-align: top; overflow:hidden; max-width:800px">
<div id="medicine_table_container_2" class="medicine-table-container" style="position:relative; left:0">
<div style="white-space:nowrap; font-size:0px">
<div style="display:inline-block; background-color:yellow; width:130px; height:85px; border:1px solid #999; font-size: 12px; white-space:normal">
<div>
<div style="display:inline-block; width:70px; height:45px">
Morning<br/>-
</div>
<div style="display:inline-block; width:50px; height:45px">
Noon<br/>5mg
</div>
</div>
<div>
<div style="display:inline-block; width:70px; height:35px">
Afternoon<br/>12mg
</div>
<div style="display:inline-block; width:50px; height:35px">
Evening<br/>-
</div>
</div>
</div>
</div>
<div style="white-space:nowrap; font-size:0px">
<div style="display:inline-block; background-color:yellow; width:130px; height:85px; border:1px solid #999; font-size: 12px; white-space:normal">
<div>
<div style="display:inline-block; width:70px; height:45px">
Morning<br/>-
</div>
<div style="display:inline-block; width:50px; height:45px">
Noon<br/>5mg
</div>
</div>
<div>
<div style="display:inline-block; width:70px; height:35px">
Afternoon<br/>12mg
</div>
<div style="display:inline-block; width:50px; height:35px">
Evening<br/>-
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Since your code is a bit complex, here is a basic one to reproduce the issue and better understand what's happening:
.table {
display: table;
border: 1px solid;
margin: 5px;
}
.table>div {
display: table-row;
}
.table>div>span {
display: table-cell;
padding: 0 5px;
}
.table>div>span span {
display: inline-block;
}
baseline
<div class="table">
<div>
<span>one line</span>
<span><span>two <br> line (inline-block)</span></span>
</div>
</div>
baseline
<div class="table">
<div>
<span>two<br> line</span>
<span><span>two <br> line (inline-block)</span></span>
</div>
</div>
baseline (with overflow:hidden)
<div class="table">
<div>
<span>one line</span>
<span><span style="overflow:hidden;">two <br> line</span></span>
</div>
</div>
baseline (with overflow:hidden)
<div class="table">
<div>
<span>one line</span>
<span><span style="overflow:hidden;">another line</span></span>
</div>
</div>
top will fix all the cases
<div class="table">
<div>
<span style="vertical-align:top;">one line</span>
<span><span>two <br> line</span></span>
</div>
</div>
<div class="table">
<div>
<span style="vertical-align:top;">one line</span>
<span><span style="overflow:hidden;">two <br> line</span></span>
</div>
</div>
<div class="table">
<div>
<span style="vertical-align:top;">one line</span>
<span><span style="overflow:hidden;">another line</span></span>
</div>
</div>
<div class="table">
<div>
<span style="vertical-align:top;">two<br> line</span>
<span><span>two <br> line (inline-block)</span></span>
</div>
</div>
You can clearly see how the use of inline-block (and overflow:hidden) is the culprit here as it make the calculation of the baseline counter intuitive and unexpected.
I see that Temani Afif has already provided solution to your original problem. But in case if it helps you in anyway or anyone else, here is the basic structure of a table with sub-tables
Styles
<style>
.table {
display:table; border:1px solid #ccc; border-collapse:collapse
}
.table .row {
display:table-row; border:1px solid #ccc; border-collapse:collapse
}
.table .row .headercell {
display:table-cell; border:1px solid #ccc; height: 80px; width: 150px; border-collapse:collapse
}
.table .row .cell {
display:table-cell; border:1px solid #ccc; height: 80px; Width: 300px; border-collapse:collapse
}
</style>
Table structure
<div class="table">
<div class="row">
<div class="headercell">
Row1
</div>
<div class="cell">
<div class="table">
<div class="row">
<div class="cell">
Cell1
</div>
<div class="cell">
Cell2
</div>
</div>
<div class="row">
<div class="cell">
Cell3
</div>
<div class="cell">
Cell4
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="headercell">
Row2
</div>
<div class="cell">
<div class="table">
<div class="row">
<div class="cell">
Cell1
</div>
<div class="cell">
Cell2
</div>
</div>
<div class="row">
<div class="cell">
Cell3
</div>
<div class="cell">
Cell4
</div>
</div>
</div>
</div>
</div>
</div>

Bootstrap 4 image half page width

How can I make responsive layout like this?
I need only few tips how to do it. I dont need full source code. Sorry for my english.
My code:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-6">
<img src='https://via.placeholder.com/350x150' />
</div>
<div class="col-md-6">
CONTENT
</div>
</div>
<div class="row">
<div class="col-md-6">
CONTENT
</div>
<div class="col-md-6">
<img src='https://via.placeholder.com/350x150' />
</div>
</div>
</div>
I want img to be half page size.
Check fiddle and snippet below. It is fully responsive and it is working in any device.
body {
padding:15px 0;
}
.content-box {
position:relative;
width:100%;
min-height:350px;
background:#ccc;
margin:15px 0;
}
.img-box.left {
position:absolute;
top:-15px;
right:-15px;
bottom:-15px;
width:calc( 50vw - 15px );
background:red;
}
.img-box.right {
position:absolute;
top:-15px;
left:-15px;
bottom:-15px;
width:calc( 50vw - 15px );
background:red;
}
#media only screen and (max-width: 768px) {
.img-box.left, .img-box.right {
position:absolute;
top:0px;
left:0px;
right:0px;
bottom:0px;
width:100%;
background:red;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class=container>
<div class="row">
<div class="col-md-6">
<div class="content-box">
<div class="img-box left">
image
</div>
</div>
</div>
<div class="col-md-6">
<div class="content-box">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="content-box">
</div>
</div>
<div class="col-md-6">
<div class="content-box">
<div class="img-box right">
image
</div>
</div>
</div>
</div>
</div>
</body>
https://jsfiddle.net/Sampath_Madhuranga/tfz87bqe/18/
This works for you...Check and let me know if need any help.
Thanks.
here's your layout with bootstrap 4. put image into box--wide but keep in mind pink divs are absolutely positioned so they will not resize the parent - they will take full parent's height which depends on content in gray box
to make this responsive - my suggestion is to wrap images into .col-12and for desktop set it's to position static while images are absolute so they will align inside .container, not .col-12 and on mobile images should be just static
.container {
background: #5f408c;
padding: 20px;
}
.container h1 {
text-align: center;
color: white;
}
.box {
min-height: 200px;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
text-transform: uppercase;
font-size: 40px;
}
.box--wide {
position: absolute;
left: 15px;
right: calc(50% + 15px);
}
.box--wide:last-child {
right: 15px;
left: calc(50% + 15px);
}
.box--pink {
background: #ec008c;
}
.box--gray {
background: #272827;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-12">
<h1>TITLE</h1>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="box box--pink box--wide">image</div>
<div class="col-12 col-md-6 offset-md-6 ">
<div class="box box--gray">content</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-12 col-md-6">
<div class="box box--gray">content</div>
</div>
<div class="box box--pink box--wide">image</div>
</div>
</div>

Flex grid not aligning

I have a grid I have built out of flex boxes. Some of the grid is made of squares, with two rectangles. I can't seem to get the boxes to align correctly, using flexbox with flex-grow, or manually setting the box heights. The goal is to have them all line up with equal margins between the entire grid. Here is the grid code:
.project-grid { height: 1400px; padding: 80px 20px; }
.project-grid .column { width:33.33%; margin-left:10px; flex-direction:column; margin-top:-10px; }
.project-grid .column:first-child { margin-left:0; }
.project-grid .column .box {
margin-top:10px;
background-color:blue;
height: 400px;
background-size:cover;
background-repeat: no-repeat;}
.project-grid .column .box.tall { height:800px; }
.project-grid .column a .box > p {
font-family: $lato;
color: $white;
font-size: 24px;}
.flex { display:flex;}
<div class="project-grid flex">
<div class="flex column">
<a href="/hospitality">
<div class="box" style="background-image: url('');" <a href="/projects">
<p>Hospitality</p>
</div>
</a>
<a href="/rennovation-repurpose">
<div class="box tall" style="background-image: url('');">
<p>Rennovation/ Repurpose</p>
</div>
</a>
</div>
<div class="flex column">
<a href="/automotive">
<div class="box" style="background-image: url('');">
<p>Automotive</p>
</div>
</a>
<a href="/serenbe">
<div class="box" style="background-image: url('');">
<p>Serenbe</p>
</div>
</a>
<a href="/retail-office">
<div class="box" style="background-image: url('') ;">
<p>Retail/ Office</p>
</div>
</a>
</div>
<div class="flex column">
<a href="/multi-family-mixed-use">
<div class="box tall" style="background-image: url('');">
<p>Multi-Family/ Mixed Use</p>
</div>
</a>
<a href="/education-places-of-worship">
<div class="box" style="background-image: url('');">
<p>Education/ Places of Worship</p>
</div>
</a>
</div>
</div>
CSS
For easy viewing, here is a codepen I've made: https://codepen.io/bsquared/pen/zdPqPJ
As commented, if you involved <a> in your flex layout and also to draw the background, you can achieve the visual you look for.
a {
/*with no fix height so it can be spread evenly if needed*/
background: blue;
/* draw bg here it will include children area and further if needed to even the visual */
margin: 10px;
/* set margins here */
color: white;
}
/* flex layout and sizing */
.flex,
a {
display: flex;
}
.column,
a {
flex-direction: column;
flex: 1;/* make fill entire space left if any */
}
.box {
height: 400px;
}
.tall {
height: 800px;
}
<div class="project-grid flex">
<div class="flex column">
<a href="/hospitality">
<div class="box" style="background-image: url('');"><!-- background-image is to be send & set to the parent A -->
<p>Hospitality</p>
</div>
</a>
<a href="/rennovation-repurpose">
<div class="box tall" style="background-image: url('');">
<p>Rennovation/ Repurpose</p>
</div>
</a>
</div>
<div class="flex column">
<a href="/automotive">
<div class="box" style="background-image: url('');">
<p>Automotive</p>
</div>
</a>
<a href="/serenbe">
<div class="box" style="background-image: url('');">
<p>Serenbe</p>
</div>
</a>
<a href="/retail-office">
<div class="box" style="background-image: url('') ;">
<p>Retail/ Office</p>
</div>
</a>
</div>
<div class="flex column">
<a href="/multi-family-mixed-use">
<div class="box tall" style="background-image: url('');">
<p>Multi-Family/ Mixed Use</p>
</div>
</a>
<a href="/education-places-of-worship">
<div class="box" style="background-image: url('');">
<p>Education/ Places of Worship</p>
</div>
</a>
</div>
</div>
If you want to keep heights, then you need to mind the amounts of margins all together with eights of elements in each column :
example
.project-grid { height: 1400px; padding: 80px 20px; }
.project-grid .column { width:33.33%; margin-left:10px; flex-direction:column; margin-top:-10px; }
.project-grid .column:first-child { margin-left:0; }
.project-grid .column .box {
margin-top:10px;
background-color:blue;
height: 400px;
background-size:cover;
background-repeat: no-repeat;}
.project-grid .column .box.tall { height:824px; }
.project-grid .column a .box > p {
font-family: $lato;
color: $white;
font-size: 24px;}
.flex { display:flex;}
<div class="project-grid flex">
<div class="flex column">
<a href="/hospitality">
<div class="box" style="background-image: url('');" >
<p>Hospitality</p>
</div>
</a>
<a href="/rennovation-repurpose">
<div class="box tall" style="background-image: url('');">
<p>Rennovation/ Repurpose</p>
</div>
</a>
</div>
<div class="flex column">
<a href="/automotive">
<div class="box" style="background-image: url('');">
<p>Automotive</p>
</div>
</a>
<a href="/serenbe">
<div class="box" style="background-image: url('');">
<p>Serenbe</p>
</div>
</a>
<a href="/retail-office">
<div class="box" style="background-image: url('') ;">
<p>Retail/ Office</p>
</div>
</a>
</div>
<div class="flex column">
<a href="/multi-family-mixed-use">
<div class="box tall" style="background-image: url('');">
<p>Multi-Family/ Mixed Use</p>
</div>
</a>
<a href="/education-places-of-worship">
<div class="box" style="background-image: url('');">
<p>Education/ Places of Worship</p>
</div>
</a>
</div>
</div>
CSS
The p tags, which has margins top and bottom by defaults, are pushing the boxes up. You have to use overflow: auto; on the parent div to prevent it from happening.
.project-grid .column .box {
// ...
overflow: auto;
}
Full working code:
.project-grid {
height: 1400px;
padding: 80px 20px;
}
.project-grid .column {
width: 33.33%;
margin-left: 10px;
flex-direction: column;
margin-top: -10px;
}
.project-grid .column:first-child {
margin-left: 0;
}
.project-grid .column .box {
margin-top: 10px;
background-color: blue;
height: 400px;
background-size: cover;
background-repeat: no-repeat;
overflow: auto;
}
.project-grid .column .box.tall {
height: 800px;
}
.project-grid .column a .box>p {
font-family: $lato;
color: $white;
font-size: 24px;
}
.flex {
display: flex;
}
<div class="project-grid flex">
<div class="flex column">
<a href="/hospitality">
<div class="box" style="background-image: url('');" <a href="/projects">
<p>Hospitality</p>
</div>
</a>
<a href="/rennovation-repurpose">
<div class="box tall" style="background-image: url('');">
<p>Rennovation/ Repurpose</p>
</div>
</a>
</div>
<div class="flex column">
<a href="/automotive">
<div class="box" style="background-image: url('');">
<p>Automotive</p>
</div>
</a>
<a href="/serenbe">
<div class="box" style="background-image: url('');">
<p>Serenbe</p>
</div>
</a>
<a href="/retail-office">
<div class="box" style="background-image: url('') ;">
<p>Retail/ Office</p>
</div>
</a>
</div>
<div class="flex column">
<a href="/multi-family-mixed-use">
<div class="box tall" style="background-image: url('');">
<p>Multi-Family/ Mixed Use</p>
</div>
</a>
<a href="/education-places-of-worship">
<div class="box" style="background-image: url('');">
<p>Education/ Places of Worship</p>
</div>
</a>
</div>
</div>
CSS

Why isn't my footer displayed in the bottom ? what is wrong with this CSS?

So I'd like my footer to adjust and stay on the bottom of the page no matter the height of the content which is dynamic
Below is the CSS for the body, wrapper and footer .. the footer doesn't not stay in the bottom when the content is too long and gets display in the middle of the page when you have to scroll
body, html{
margin:0px;
padding:0px;
width:100%;
height:100%;
background:#FFFFFF;
}
#wrapper{
position:relative;
top:0px;
left:0px;
width:100%;
padding:0px;
min-height:100%;
overflow-x:hidden;
}
#footer{
position:absolute;
bottom:0px;
left:150px;
width:1600px;
height:500px;
background:blue;
}
...
<div id="wrapper">
<div id="header"></div>
<div id="logo"><img src="images/u176.png" class="logo_pic" style="outline: none;"></div>
<div id="search_bar"><input type="text" name="search_bar" class="search" /></div>
<div id="search_icon"><img src="images/u205.png" width="28px" height="28px" /></div>
<div id="become_a_chef"><span id="become_title">Become </span></div>
<div id="login">Log in</div>
<div id="sign_up">Sign up</div>
<div id="tap-container"><img id="tap-pic" class="food_container_pic" src="images/today_menu/u35.png" /></div>
<div id="tap-content"></div>
<div class="column1">
<div class="tap-links">Become a member</div>
<div class="tap-links">Sign up</div>
<div class="tap-links">Log in</div>
<div class="tap-links">Home</div>
</div>
<div class="column2">
<div class="tap-links">Search</div>
<div class="tap-links">Download the App</div>
<div class="tap-links">How it works</div>
<div class="tap-links">Help</div>
</div>
<div id="chef-rating-responsive">
<div class="subinfo_container3"><img class="food_container_pic" src="images/fusion/u1837.jpg" /></div>
<div class="subinfo_container4">A</div>
<div class="subinfo_container5">Open Now</div>
<div class="subinfo_container6">More...</div>
</div>
<div id="cover_picture_container"><img class="food_container_pic" src="images/u4.jpg" /></div>
<div id="profile_picture_container"><img id="profile_picture" class="img" src="<?php echo $picture;?>"></div>
<div id="chef_description_container">
<div id="kitchen_name"><span id="kitchen_title"><?php echo $name;?></span></div>
<div id="chef_description_summary"><?php echo description;?></div>
<div id="schedule_info_container">
<div class="subinfo_container">
<img id="chef_rating" src="images/fusion/u1837.jpg" width="186px" height="35px">
<span id="number_reviews">64 reviews</span>
</div>
<div class="subinfo_container"><span id="open_now">Open Now</span></div>
<div class="subinfo_container"><span id="chef_location">Chef Location</span></div>
<div class="subinfo_container2"><span id="letter_grade">A</span><span id="chef_grade">since Nov.2016</span></div>
<div class="subinfo_container2">
<div id="clock"><img id="u1341_img" src="images/u1341.png" class="full" ></div>
<span id="schedule_hours"></span>
</div>
<div class="subinfo_container2"><span id="chef_contact">Chef contact</span></div>
</div>
</div>
<div class="today_menu">
<div class="space"></div>
</div>
<div id="footer">
<div class="company_footer">
<div class="title">Company</div>
<div class="column_content_footer">About</div>
<div class="column_content_footer">Careers</div>
<div class="column_content_footer">Press</div>
<div class="column_content_footer">Blog</div>
<div class="column_content_footer">About</div>
<div class="column_content_footer">Help</div>
<div class="column_content_footer">Policies</div>
<div class="column_content_footer">Disaster</div>
<div class="column_content_footer">Terms & Privacy</div>
</div>
<div class="discover_footer">
<div class="title">Discover</div>
<div class="column_content_footer">Trust & Safety</div>
<div class="column_content_footer">Invite friends</div>
<div class="column_content_footer">Gift card</div>
<div class="column_content_footer">pricks</div>
<div class="column_content_footer">Mobile</div>
<div class="column_content_footer">Events support</div>
<div class="column_content_footer">Travel</div>
<div class="column_content_footer">Nearby</div>
</div>
<div class="kitchening_footer">
<div class="title"></div>
<div class="column_content_footer"></div>
<div class="column_content_footer">Serving</div>
<div class="column_content_footer">Responsible</
</div>
<div class="social_media_buttons">Hey</div>
</div>
</div>
</div>
html, body {
padding: 0;
margin: 0;
background: #fff;
}
#wrapper {
position: relative;
width: 100%;
height: 100%;
padding-bottom: 400px;
box-sizing: border-box;
}
#footer {
z-index: 50;
position: fixed;
bottom: 0;
width: 100%;
height: 400px;
background: blue;
}
<div id="wrapper">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<div id="footer">
</div>
</div>
This works perfectly fine for me (tweaked it a little bit). I'd advice you not to use fixed widths like 1600px, but to work with percentages and max-widths. Hope this helps
If your footer has a fixed height you could do something like this:
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
.force-min-height {
min-height: 100%;
position: relative;
}
.header {
background: grey;
}
.content {
/* padding being the same as footer height */
padding-bottom: 4em;
}
.footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 4em;
background: grey;
}
<div class="force-min-height">
<div class="header">Header</div>
<div class="content">
line<br>line<br>line<br>line<br>line<br>line<br>line<br>line<br>line
</div>
<div class="footer">Footer</div>
</div>

Horizontally Center elements inside the div

So i need to create layout with 3 or 4 squares centered in it. As now many different screens are (i at the moment have 21 philips, macbook 13 and ipad) and on all of them the squares are different.
So i need it centered in any screens. Here some of my code:
Some CSS:
#main{
border: 1px solid red;
margin: auto;
}
#block{
display: inline-block;
padding: 110px;
border: 1px solid red;
margin: 10px 10px;
overflow:hidden;
}
Some HTML:
<div id="wrapper">
<div id="header">
header
</div>
<div id="main">
<div id="block">main</div>
<div id="block">main</div>
<div id="block">main</div>
<div id="block">main</div>
<div id="block">main</div>
<div id="block">main</div>
<div style="clear:both"></div>
</div>
</div>
I tried different ways with some extra div...
So i need that this squares would automatically centered in any screens
Since you're just using inline-block, you can center the text of the container.
Also, use classes for non-unique elements.
Fiddle: http://jsfiddle.net/LWTNB/3/
Updated HTML:
<div id="wrapper">
<div id="header">
header
</div>
<div id="main">
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
</div>
</div>
Updated CSS:
#main{
border:1px solid red;
text-align:center; /* solution */
}
.block{
display:inline-block;
padding:110px;
border:1px solid red;
margin:10px 10px;
overflow:hidden;
}