3 column layout will not fill width of screen - html

I'm fairly new to html/css and I'm having a problem with a project. I am trying to create a 3 column layout for the bottom portion of my page. What I have right now is close to what I want, but it does not fill the width of the screen. It's all bunched on the left side and does not stretch to match the screen. I went back and followed the example from w3schools and it still didn't work. What am I missing?
HTML
<div class="row">
<div class="column">
<h1>FOLLOW ME ON <br> INSTAGRAM</h1>
</div>
<div class="column">
<h2>contact me</h2>
</div>
<div class="column">
<h1>SUBSCRIBE</h1>
</div>
</div>
CSS
.column {
float: left;
padding: 10px;
height: 300px;
text-align: center;
position: relative;
}
.column.side {
width: 25%;
}
.column.middle {
width: 50%;
}
.row:after {
content: "";
display: table;
clear: both;
}

If you wanna have padding "inside" element, then you need to set box-sizing: border-box.
.row {
width: 100%;
}
.column {
float: left;
padding: 10px;
height: 300px;
text-align: center;
box-sizing: border-box;
}
.column.side {
width: 25%;
}
.column.middle {
width: 50%;
}
<div class="row">
<div class="column side">
<h1>FOLLOW ME ON <br> INSTAGRAM</h1>
</div>
<div class="column middle">
<h2>contact me</h2>
</div>
<div class="column side">
<h1>SUBSCRIBE</h1>
</div>
</div>

Two things:
1.) As #chojnicki wrote in a comment, you need to add the classes defined in the CSS (.side, .middle) to your HTML
2.) To include the padding in the width in order to get a sum of exactly 100% overall (and not more than that to avoid the last column to go under the second one) for the added widths (25% + 50% + 25%), you need to add box-sizing: border-box; to everything (using the *selector):
* {
box-sizing: border-box;
}
.column {
float: left;
padding: 10px;
height: 300px;
text-align: center;
position: relative;
}
.column.side {
width: 25%;
}
.column.middle {
width: 50%;
}
h1 {
font-size: 24px;
}
h2 {
font-size: 18px;
}
<div class="row">
<div class="column side">
<h1>FOLLOW ME ON <br> INSTAGRAM</h1>
</div>
<div class="column middle">
<h2>contact me</h2>
</div>
<div class="column side">
<h1>SUBSCRIBE</h1>
</div>
</div>

Why you don't use .col-xs-4?
and you shouldn't use width to your cols so why do you use col?

Related

Align 6 divs content vertical

How would i align all these 6 divs vertically in a 3x3 pattern so that the top and bottom divs content are aligned with each other so it looks good. i've tried some vertical-align: middle; with no sucess.
It's a must to be 100% responsive and that the number also is centered and aligned so whatever number gets there is aligned.
.top-right-container {
position: absolute;
border: 1px solid white;
height: 20%;
width: 50%;
right: 0;
top: 0;
}
.stats-container {
position: relative;
float: left;
border: 1px solid white;
width: 75%;
height: 80%;
}
.Agility,
.Stamina,
.Respect,
.Intelligence,
.Strength,
.Cash {
display: inline-block;
color: black;
}
.Agility,
.Intelligence {
float: left;
margin-left: 10%;
}
.Stamina,
.Strength {
margin: 0 auto;
}
.Respect,
.Cash {
margin-right: 10%;
float: right;
}
.stats-container h2 {
font-family: Marker-Felt;
margin: 0;
font-size: calc(0.7vh + 1.2vw);
}
.stats-container p {
margin: 5%;
text-align: center;
font-size: calc(0.5vh + 0.8vw);
}
.top-stats,
.bottom-stats {
width: 100%;
text-align: center;
}
<div class="top-right-container">
<div class="stats-container">
<div class="top-stats">
<div class="Agility">
<h2>Agility</h2>
<p>10</p>
</div>
<div class="Stamina">
<h2>Stamina</h2>
<p>10</p>
</div>
<div class="Respect">
<h2>Respect</h2>
<p>10</p>
</div>
</div>
<div class="bottom-stats">
<div class="Intelligence">
<h2>Intelligence</h2>
<p>10</p>
</div>
<div class="Strength">
<h2>Strength</h2>
<p>10</p>
</div>
<div class="Cash">
<h2>Cash</h2>
<p>10</p>
</div>
</div>
</div>
</div>
You can do it with the Flexbox:
* {margin:0;padding:0;box-sizing:border-box}
html, body {width:100%}
.stats-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
.top-stats,
.bottom-stats {
display: flex;
width: 100%;
text-align: center;
}
.Agility,
.Stamina,
.Respect,
.Intelligence,
.Strength,
.Cash {
flex: 1;
}
.stats-container h2 {
font-size: calc(0.7vh + 1.2vw);
}
.stats-container p {
font-size: calc(0.5vh + 0.8vw);
}
<div class="top-right-container">
<div class="stats-container">
<div class="top-stats">
<div class="Agility">
<h2>Agility</h2>
<p>10</p>
</div>
<div class="Stamina">
<h2>Stamina</h2>
<p>10</p>
</div>
<div class="Respect">
<h2>Respect</h2>
<p>10</p>
</div>
</div>
<div class="bottom-stats">
<div class="Intelligence">
<h2>Intelligence</h2>
<p>10</p>
</div>
<div class="Strength">
<h2>Strength</h2>
<p>10</p>
</div>
<div class="Cash">
<h2>Cash</h2>
<p>10</p>
</div>
</div>
</div>
</div>
responsive 2 rows and 6 boxes
Here is some code you can work with.
The container of all the divs .container will take 100% of the page eg. its <body> .
The rows .statRow will take 100% of its parent the container.
Now the boxes .box will take 33% of its parent width.
Then adding 3 of these boxes 33%+33%+33% will take up 99% of the container.
Additionally borders usually take up more space so width + border is its actual width.
This is fixed with chancing the elements box-sizing to border-box.
.container {
border: 10px solid black;
width: 100%;
box-sizing: border-box;
border-radius: 5px;
}
.statRow {
width: 100%;
display: block;
}
.box {
color: white;
display: inline-block;
text-align: center;
width: 33%;
border: 10px solid white;
box-sizing: border-box;
border-radius: 15px;
background-color: #222;
}
<div class="container">
<div class="statBubble">
<div class="box">
<h5>Agility</h5>
<p>10</p>
</div><!--
--><div class="box">
<h5>Strength</h5>
<p>10</p>
</div><!--
--><div class="box">
<h5>Stat</h5>
<p>number</p>
</div>
</div>
<div class="statRow">
<div class="box">
<h5>Wisdom</h5>
<p>100</p>
</div><!--
--><div class="box">
<h5>Stat</h5>
<p>number</p>
</div><!--
--><div class="box">
<h5>Stat</h5>
<p>number</p>
</div>
</div>
</div>

Remove padding on the left and right of a grid system

I have a grid system with 10px padding between columns. But i don't want that padding on the left and right side of the whole grid. I have tried putting the columns in a big wrapper and adding margin-left: -10px and margin-right:-10px but it just moves the grid left.
<div class="column column-1"><div class="inner"></div></div>
<div class="column column-2"><div class="inner"></div></div>
<div class="column column-3"><div class="inner"></div></div>
<div class="column column-1"><div class="inner"></div></div>
<div class="column column-1"><div class="inner"></div></div>
<div class="column column-1"><div class="inner"></div></div>
CSS:
.row,
.column {
box-sizing: border-box;
}
.column {
position: relative;
float: left;
display: inline-block;
}
.column-1 {
width: 33.3333333%;
}
.column-2 {
width: 66.6666666%;
}
.column-3 {
width: 100%;
}
.column {
min-height: 60px;
padding: 10px;
}
.inner {
height: 100px;
width: 100%;
background: black;
display:block;
position: relative;
}
JS Fiddle
I notice you have a .row class defined in your css, but aren't using it.
If you start using it, and embed your columns within a row, you can use :first-child and :last-child selectors to change the margins on the end columns.
Like so
.row .column:first-child {
padding-left: 0;
}
.row .column:last-child {
padding-right: 0;
}
<div class="row">
<div class="column column-1"><div class="inner"></div></div>
<div class="column column-2"><div class="inner"></div></div>
</div>
Fiddle

creating a wrapper of similar to ID card

I am struggling with creation of a collection of elements wrapped inside a single one. I made a sketch of what i was trying to create.
The HTML would look like this:
<div class="wrapper-1">
<div class="image"></div>
<h3 class="title">HEY NOW</h3>
<p class="text">you a rock star, hey now! You are a rock star</p>
</div>
What would be the best way to create such a wrapper?
I would prefer to create two columns as .left-side and .right-side inside the main wrapper and add the contents to the these columns as following:
<div class="wrapper-1">
<div class="left-side">
<div class="image"></div>
</div>
<div class="right-side">
<h3 class="title">HEY NOW</h3>
<p class="text">you a rock star, hey now! You are a rock star</p>
</div>
</div>
Here is the fully implemented version:
.wrapper-1 {
width: 400px;
height: 100px;
}
.left-side {
float: left;
width: 100px;
height: 100px;
margin-right: 15px;
}
.left-side > .image {
background: url(http://placehold.it/100x100) no-repeat center center;
width: 100px;
height: 100px;
margin-right: 10px;
}
.right-side {
float: left;
width: 285px;
height: 100px;
}
.right-side > .title {
margin: 0;
}
<div class="wrapper-1">
<div class="left-side">
<div class="image"></div>
<img src="" alt="">
</div>
<div class="right-side">
<h3 class="title">HEY NOW</h3>
<p class="text">you a rock star, hey now! You are a rock star</p>
</div>
</div>
How about this, using flexbox
.wrapper-1 {
display: flex;
}
.wrapper-2 {
display: flex;
flex-direction: column
}
.wrapper-1 .image {
width: 100px;
height: 100px;
background: url(http://placehold.it/100/00f);
margin-right: 10px;
}
<div class="wrapper-1">
<div class="image"></div>
<div class="wrapper-2">
<h3 class="title">HEY NOW</h3>
<p class="text">you a rock star, hey now! You are a rock star</p>
</div>
</div>
And if you can't change markup, use position: absolute
.wrapper-1 {
padding-left: 110px;
box-sizing: border-box;
}
.wrapper-1 .image {
position: absolute;
left: 0;
top: 0;
width: 100px;
height: 100px;
background: url(http://placehold.it/100/00f);
}
<div class="wrapper-1">
<div class="image"></div>
<h3 class="title">HEY NOW</h3>
<p class="text">you a rock star, hey now! You are a rock star</p>
</div>
Here is a complete solution:
HTML:
<div class="wrapper clearfix">
<div class="left">
<img src="img.png">
</div>
<div class="right">
<h3>text</h3>
<p>text text</p>
</div>
</div>
CSS:
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
* html .clearfix { zoom: 1; } /* IE6 */
*:first-child+html .clearfix { zoom: 1; } /* IE7 */
.wrapper {
box-sizing: border-box; /* makes padding go on the inside */
padding: 10px; /* gives interior padding */
width: 1170px; /* whatever width you want the container to be */
margin: 0 auto; /* center it */
background-color: #fff;
}
.left {
width: 20%; /* whatever width you want the left side to be, stick to percentages */
float: left;
}
.left img {
width: 100%;
height: auto;
}
.right {
width: 77%; /* whatever width you want the right side to be, stick to percentages, notice that 77% and 20% dont add up to 100%, this is to account for the small gap inbetween the divs */
float: right;
}
Note: "clearfix" is used when floating things left and right. It prevents the common error where the div collapses in itself when child divs are being floated.
working jsfiddle: here

How to make divs same height?

I have one parent-div which contains three divs and I would like to make them same height but it is not working. The first and third div contains each an image. The second div contains three divs with content.
Here is the HTML:
<div class="container">
<div class="column1">
<img src="http://placehold.it/300x318">
</div>
<div class="column2">
<div class="row1">
<div class="text">UNIKE GUSTAVIANSKE STILMØBLER.</div>
<div class="text">VI SELGER HÅNDVERK ETTER 1700-</div>
<div class="text">OG 1800-TALLS TRADISJONER.</div>
</div>
<div class="row2"></div>
<div class="row3">
<div class="text">
Åpningstider:<br>
Man - Fre 11 -17 Lør 11- 15
</div>
</div>
</div>
<div class="column3">
<img src="http://placehold.it/300x318">
</div>
</div>
The .container has the css-rule display:flex;. When I apply this also to .column1, .column2 and .column3, the layout breaks.
I am trying to achieve that the images height increase and decrease depended to .column2. Unfortunately, I have not the possibility to change the HTML or use JS.
Here you can see a JS-Fiddle. I have commented out the CSS-rules.
Many thanks for your help!
In the question you mention that you apply display:flex to .column1, .column2 and .column3.
Instead just apply this to .column1 and .column3 and leave .column2 as display:block.
This should resolve your problem (works in your JS-Fiddle).
You just need to apply a height and max-width to the images. They will distort to fit into the space and make your images look weird. If you choose images that are this dimensions, they will look better.
.container {
width: 100%;
display: flex;
}
.container img{
height: 100%;
max-width: 100%;
}
.row1 {
background-color: #fff;
padding-top: 40px;
}
.row1 .text {
font-size: 30px;
text-align: center;
line-height: 50px;
font-weight: 300;
}
.row2 {
height: 150px;
background-color: #e4e8eb;
}
.row3 {
background-color: #c7cacf;
padding: 10px 0px;
}
.row3 .text {
font-size: 25px;
text-align: center;
line-height: 25px;
}
<div class="container">
<div class="column1">
<img src="http://placehold.it/300x318">
</div>
<div class="column2">
<div class="row1">
<div class="text">
UNIKE GUSTAVIANSKE STILMØBLER.</div>
<div class="text">VI SELGER HÅNDVERK ETTER 1700-</div>
<div class="text">OG 1800-TALLS TRADISJONER.
</div>
</div>
<div class="row2"></div>
<div class="row3">
<div class="text">Åpningstider:
<br>Man - Fre 11 -17 Lør 11- 15</div>
</div>
</div>
<div class="column3">
<img src="http://placehold.it/300x318">
</div>
</div>
you can add this lines for row css
.row {
display: flex;
justify-content: center; /* align horizontal */
align-items: center;
}
You just need to specify the height and width of image tag.Just add width:100% and height 100% for image tag.
.container {
width: 100%;
display: flex;
}
.container img{
height: 100%;
max-width: 100%;
}
.row1 {
background-color: #fff;
padding-top: 40px;
}
.row1 .text {
font-size: 30px;
text-align: center;
line-height: 50px;
font-weight: 300;
}
.row2 {
height: 150px;
background-color: #e4e8eb;
}
.row3 {
background-color: #c7cacf;
padding: 10px 0px;
}
.row3 .text {
font-size: 25px;
text-align: center;
line-height: 25px;
}
.imgsize{
width: 100%;
height: 100%;
}
<div class="container">
<div class="column1">
<img src="http://placehold.it/300x318" class="imgsize">
</div>
<div class="column2">
<div class="row1">
<div class="text">
UNIKE GUSTAVIANSKE STILMØBLER.</div>
<div class="text">VI SELGER HÅNDVERK ETTER 1700-</div>
<div class="text">OG 1800-TALLS TRADISJONER.
</div>
</div>
<div class="row2"></div>
<div class="row3">
<div class="text">Åpningstider:
<br>Man - Fre 11 -17 Lør 11- 15</div>
</div>
</div>
<div class="column3">
<img src="http://placehold.it/300x318" class="imgsize">
</div>
</div>
If I'm understanding properly you can add this to your styles:
img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
Your columns are already filling to the parent height. Using the above css styles the images in this will fill the parent div height and basically overflow the width. If you do something else like set height of the images to 100% it will distort the image.
Here is a similar question with same (but more detailed) answer. https://stackoverflow.com/a/26967278/3366016

Centering text in footer without text-align center

From this JSFiddle, you can see that I have a footer.
I would like to align the content within each column so that the container is centered, but the text still aligned left.
HTML:
<div class="left">
<div class="align">
<h6>Facebook</h6>
<h6>Twitter</h6>
<h6>Blog</h6>
</div>
</div>
<div class="right">
<div class="align">
<h6>Privacy Policy</h6>
<h6>Terms of Service</h6>
<h6>Help</h6>
<h6>Contact Us</h6>
</div>
</div>
CSS:
div {
width: 50%;
}
.left {
float: left;
}
.right {
float: right;
}
.align {
display: table;
margin: 0 auto;
}
Any suggestions? Thanks.
Please check this
.left {
width: 50%;
float: left;
background-color: white;
}
.right {
width: 50%;
float: right;
background-color: black;
color: white;
}
.hor-center {
display: table;
margin: 0 auto;
}
<div class="left">
<div class="hor-center">
<h6>Facebook</h6>
<h6>Reddit</h6>
<h6>Instagram</h6>
</div>
</div>
<div class="right">
<div class="hor-center">
<h6>Terms</h6>
<h6>F&Q</h6>
<h6>Email</h6>
</div>
</div>
You need to set a width on a block level container and give it margin: 0 auto;. You can change the 0, which controls top and bottom margins, but the key is having a definite width with auto left and right margins.