HTML / CSS: Issues Creating Three Columns - html

I created three columns spread across 90% of the width page width and also centred on the page using "margin: auto". I wanted to have the three columns of equal width with equal spacing in between but was unable to achieve my desired result. How would I ago about doing this?
html, body {
width: 100%;
height: 100%;
margin: 0px;
background-color: #fbe3cf;
}
.ColumnContainer {
height: 100%;
width: 90%;
margin: auto;
}
.c1 {
float: left;
width: 30%;
height: 70%;
background-color: green;
}
.c2 {
float: right;
width: 30%;
height: 70%;
background-color: #DDDDDD;
}
.c3{
float: right;
width: 30%;
height: 70%;
background-color: yellow;
}
<div class="ColumnContainer">
<div class="c1">c1</div>
<div class="c3">c3</div>
<div class="c2">c2</div>
</div>

You can use flex box to easily achieve this, here is the css for the desired result which also keeps it fully responsive.
here is a more detailed explanation on flex box and what you can achieve
html, body {
width: 100%;
height: 100%;
margin: 0px;
background-color: #fbe3cf;
}
.ColumnContainer {
height: 100%;
width: 90%;
margin: auto;
display:flex;
justify-content:space-between;
}
.c1 {
width: 30%;
height: 70%;
background-color: green;
}
.c2 {
width: 30%;
height: 70%;
background-color: #DDDDDD;
}
.c3{
width: 30%;
height: 70%;
background-color: yellow;
}
<div class="ColumnContainer">
<div class="c1">c1</div>
<div class="c3">c3</div>
<div class="c2">c2</div>
</div>

You can remove float and make them as inline-block, and then center the elements present in the ColumnContainer.
html, body {
width: 100%;
height: 100%;
margin: 0px;
background-color: #fbe3cf;
}
.ColumnContainer {
height: 100%;
width: 90%;
margin: auto;
text-align: center;
}
.ColumnContainer > div{
display:inline-block;
width:30%;
}
.c1 {
height: 70%;
background-color: green;
}
.c2 {
height: 70%;
background-color: #DDDDDD;
}
.c3{
height: 70%;
background-color: yellow;
}
<div class="ColumnContainer">
<div class="c1">c1</div>
<div class="c3">c3</div>
<div class="c2">c2</div>
</div>

Related

How to center an image between the containers?

How do I make the image responsive and keep it in between the containers left and right.
I have tried putting it all into another container and it doesn’t work.
I know it sounds basic but it really is not.
body {
background-color: black;
}
.left {
background-color: red;
width: 150px;
height: 800px;
float: left;
}
.right {
background-color: green;
width: 150px;
height: 800px;
float: right;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
<div class="left"></div>
<div class="right"></div>
<img src="paintingOg.gif" style="width:50%">
How about this way? Is it (close to) what you need? Please check responsiveness too.
body {
background-color: black;
}
.left {
background-color: red;
width: 150px;
height: 800px;
float: left;
}
.right {
background-color: green;
width: 150px;
height: 800px;
float: right;
}
.center {
height: 800px;
background-color: blue;
overflow: auto;
text-align: center;
}
img {
max-width: 100%;
height: auto;
}
<div class="left"></div>
<div class="right"></div>
<div class="center">
<img src="https://picsum.photos/500/500?gravity=west">
</div>
You don't need containers to center something.
It's better to use 1 container that contains everything.
If you want to center your image into a div just use this code:
<div align="center">
<image src="whatever.png"/>
</div>
body {
background-color: black;
}
.left {
background-color: red;
width: 150px;
height: 800px;
float: left;
}
.right {
background-color: green;
width: 150px;
height: 800px;
float: right;
}
img {
width: 100%;
height: auto;
}
<div class="left"></div>
<div class="right"></div>
<div align="center">
<img src="paintingOg.gif" />
</div>

how to stop this div's from overlapping?

So I have 3 divs side by side inside the div element and another div after them. However, this div is overlapping the others. How can I make "footer" come after "main"?
.main {
height: 500px;
width: 100%;
position: absolute;
}
.filter {
background: red;
height: 100%;
float: left;
width: 20%;
}
.post-bar {
background: blue;
height: 100%;
float: left;
width: 60%;
}
.advertisment {
background: green;
height: 100%;
float: left;
width: 20%;
}
.footer {
height: 250px;
width: 100%;
background: black;
position: relative;
}
<div class="main">
<div class="filter">
</div>
<div class="post-bar">
</div>
<div class="advertisment">
</div>
</div>
<div class="footer"></div>
Just get rid off position:absolute in your main class:
.main {
height: 500px;
width: 100%;
}
.filter {
background: red;
height: 100%;
float: left;
width: 20%;
}
.post-bar {
background: blue;
height: 100%;
float: left;
width: 60%;
}
.advertisment {
background: green;
height: 100%;
float: left;
width: 20%;
}
.footer {
height: 250px;
width: 100%;
background: black;
position: relative;
}
<div class="main">
<div class="filter">
</div>
<div class="post-bar">
</div>
<div class="advertisment">
</div>
</div>
<div class="footer"></div>
Just remove the
position: absolute;
display: block;
from
.main
I think you will find your desired result. Please , inform if there are any other issues. Thank you.
Remove positions from main and footer.
.main {
height: 500px;
width: 100%;
float:left;
}
.footer {
height: 250px;
width: 100%;
background: black;
float:left;
}

How do i stop elements from moving when resizing the browser?

When i resize my browser my div tags resize themselves. I've added min-width: which i thought would stop it but it does not.
html:
<div id="wrapper">
<div id="adleft"></div>
<div id="adright"></div>
css:
#wrapper{
max-width: 50%;
margin: 0 auto;
}
#adleft {
height: 500px;
min-width: 48%;
background-color: red;
float: left;
}
#adright {
height: 500px;
min-width: 48%;
background-color: red;
float: right;
}
The reason is that you are applying a min-width as a % not in px.
Using a % means that when the browser window shrinks 48% becomes less and less pixels. If you define the min-width in pixels it will stop shrinking when it hits the minimum number of pixels you declare.
Html:
<div id="wrapper">
<div id="ad">
<div id="adleft"></div>
<div id="adright"></div>
</div>
Include this in your Css:
#ad
{
Display: table;
Margin-left: auto;
Margin-right: auto;
}
#adleft
{
height: 500px;
min-width: 48%;
background-color: red;
Margin-right:20px;
}
#adright
{
height: 500px;
min-width: 48%;
background-color: red;
}
This worked for me :
Html:
<div id="wrapper">
<div id="adleft"></div>
<div id="adright"></div>
css:
#wrapper{
max-width: 960px;
min-width: 960px;
margin: 0 auto;
margin-top: 30px;
}
#adleft {
height: 500px;
width: 48%;
background-color: red;
float: left;
}
#adright {
height: 500px;
width: 48%;
background-color: red;
float: right;
}

How can I make FireFox understand the correct height of my divs?

here is my fiddle http://jsfiddle.net/9m1Lba6u/
This works on Google Chrome and Safari and shows all the numbers from 1 to last. But in FireFox it only shows until 99. Am I missing some thing in my style sheet?
here is a shorter version off my code:
html, body {
margin: 0;
padding: 0;
border: 0;
height: 100%;
overflow: hidden;
}
.head {
width: 100%;
height: 60px;
background-color: #CDF1F4;
}
.main-content {
width: 70%;
height: 100%;
padding-bottom: 70px;
float: right;
background-color: #BEE4F4;
overflow: auto;
box-sizing: border-box;
}
.side-bar {
width: 30%;
height: 100%;
padding-bottom: 70px;
float: left;
background-color: #E1BEF4;
overflow: auto;
box-sizing: border-box;
}
<div class="head"></div>
<div class="main-content"></div>
<div class="side-bar"></div>
Here is a simple CSS2 approch (it require couple of more wrappers though)
HTML:
<div class="head"></div>
<div class="page">
<div class="page-inner">
<div class="main-content">first
<br>1
<br>2
<br>3
<br>4
.....
<br>99
<br>100
<br>
<br>last
</div>
<div class="side-bar">first
<br>1
<br>2
<br>3
<br>4
.....
<br>99
<br>100
<br>
<br>last
</div>
</div>
</div>
CSS:
html, body {
margin: 0;
padding: 0;
border: 0;
height: 100%;
}
body:before{
content:'';
float:left;
height: 100%;
}
.head {
width: 100%;
height: 60px;
background-color: #CDF1F4;
}
.page{position:relative;}
.page:after{content:''; display:block; clear:both;}
.page-inner{position:absolute; left:0; right:0; top:0; bottom:0;}
.main-content {
width: 70%;
height: 100%;
float: right;
background-color: #BEE4F4;
overflow: auto;
}
.side-bar {
width: 30%;
height: 100%;
float: left;
background-color: #E1BEF4;
overflow: auto;
}
.footer {
width: 100%;
height: 160px;
background-color: #F4BED6;
}
change
overflow: scroll;
in .main-content and .side-bar , It works for me

Centering Div while being able to expand div

I found this solution to centering my div vertically and horizontally. However if I fill in the content section past the length defined for the div it will run outside of it. I was hoping to make it expand depending on the content inside the div. How do I make it so this can happen?
JSFIDDLE
HTML:
<body>
<div id="wrapper">
<div id="headerwrapper">
<div id="header" class="center">header</div>
</div>
<div id="titlewrapper">
<div id="title" class="center">title</div>
</div>
<div id="contentwrapper">
<div id="content" class="center">content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br></div>
</div>
<div id="footerwrapper">
<div id="locationwrapper">
<div id="location" class="center">location</div>
</div>
<div id="copyrightwrapper">
<div id="copyright" class="center">copyright</div>
</div>
</div>
</div>
</body>
CSS:
html body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
.center {
position: relative;
top: 50%;
transform: translateY(-50%);
margin-right: auto;
margin-left: auto;
width: 100%;
height: 100%
max-width: 5em;
}
#wrapper {
background-color: pink;
height: 100%;
width: 100%;
}
#headerwrapper {
background-color: green;
width: 100%;
height: 8em;
}
#header {
color: white;
background-color: black;
}
#titlewrapper {
background-color: red;
width: 100%;
height: 8em;
}
#title {
color: white;
background-color: black;
}
#contentwrapper {
background-color: blue;
width: 100%;
height: 8em;
}
#content {
color: white;
background-color: black;
}
#locationwrapper {
background-color: yellow;
width: 100%;
height: 8em;
}
#location {
color: white;
background-color: black;
}
#footerwrapper {
background-color: brown;
width: 100%;
height: 100%;
}
#copyrightwrapper {
background-color: green;
width: 100%;
height: 8em;
}
#copyright {
color: white;
background-color: black;
}
If you want the "content" sections to dynamically adjust height, take off the fixed height.
Change:
#contentwrapper {
background-color: blue;
width: 100%;
height: 8em;
}
To:
#contentwrapper {
background-color: blue;
width: 100%;
}
Working fiddle to your requirement: http://jsfiddle.net/k5YUu/6/