I am attempting to place an iframe and img inline in a div. The code that I have posted puts the img below the iframe. I have tried to position and float the elements but nothing seems to work. I have also checked out other posts on SO, but nothing seems to work. I am willing to start from scratch if required.
I would be grateful if someone could point out my error and show me the corrections to make to get this to work. I have looked at other posts but nothing seems to be working.
Thank you.
#media (min-width: 1200px) {
.container {
max-width: 1080px;
}
}
.hero-unit {
background-color: #000000;
border: 1px solid #252525;
margin-bottom: 30px;
}
.hero-unit img {
display: inline-block;
}
.fp-block {
padding: 5px !important;
padding: 0;
}
/*** CUSTOM CODE FOR YOUTUBE VIDEO DISPLAY ***/
.inner {
float: left;
width: 49%;
margin: 0;
}
.holder {
height: 0px;
width: 100%;
}
<div class="container">
<div class="hero-unit fp-block">
<div id="ut-wrap">
<div class="inner">
<div class="holder">
<iframe src="https://www.youtube.com/embed/_VRXrp_AfMM" frameborder="0" allowfullscreen></iframe>
<img src="http://placehold.it/150x150">
</div>
</div>
</div>
</div>
</div>
The problem
The issue is that .inner has a width of 49% which is pushing the image onto a new line. This can be seen if you add a background color and height to .inner.
#media (min-width: 1200px) {
.container {
max-width: 1080px;
}
}
.hero-unit {
background-color: #000000;
border: 1px solid #252525;
margin-bottom: 30px;
}
.hero-unit img {
display: inline-block;
}
.fp-block {
padding: 5px !important;
padding: 0;
}
/*** CUSTOM CODE FOR YOUTUBE VIDEO DISPLAY ***/
.inner {
float: left;
width: 49%;
margin: 0;
background-color: red;
height: 100px;
}
.holder {
height: 0px;
width: 100%;
}
iframe {
opacity: 0.5;
}
<div class="container">
<div class="hero-unit fp-block">
<div id="ut-wrap">
<div class="inner">
<div class="holder">
<iframe src="https://www.youtube.com/embed/_VRXrp_AfMM" frameborder="0" allowfullscreen></iframe>
<img src="http://placehold.it/150x150">
</div>
</div>
</div>
</div>
</div>
How to fix
Option 1
Add whitespace: nowrap; to .holder to stop the image from being able to wrap onto the next line
#media (min-width: 1200px) {
.container {
max-width: 1080px;
}
}
.hero-unit {
background-color: #000000;
border: 1px solid #252525;
margin-bottom: 30px;
}
.hero-unit img {
display: inline-block;
}
.fp-block {
padding: 5px !important;
padding: 0;
}
/*** CUSTOM CODE FOR YOUTUBE VIDEO DISPLAY ***/
.inner {
float: left;
width: 49%;
margin: 0;
}
.holder {
height: 0px;
width: 100%;
white-space: nowrap;
}
<div class="container">
<div class="hero-unit fp-block">
<div id="ut-wrap">
<div class="inner">
<div class="holder">
<iframe src="https://www.youtube.com/embed/_VRXrp_AfMM" frameborder="0" allowfullscreen></iframe>
<img src="http://placehold.it/150x150">
</div>
</div>
</div>
</div>
</div>
Option 2
Set a larger width on .inner.
#media (min-width: 1200px) {
.container {
max-width: 1080px;
}
}
.hero-unit {
background-color: #000000;
border: 1px solid #252525;
margin-bottom: 30px;
}
.hero-unit img {
display: inline-block;
}
.fp-block {
padding: 5px !important;
padding: 0;
}
/*** CUSTOM CODE FOR YOUTUBE VIDEO DISPLAY ***/
.inner {
float: left;
width: 100%;
margin: 0;
}
.holder {
height: 0px;
width: 100%;
}
<div class="container">
<div class="hero-unit fp-block">
<div id="ut-wrap">
<div class="inner">
<div class="holder">
<iframe src="https://www.youtube.com/embed/_VRXrp_AfMM" frameborder="0" allowfullscreen></iframe>
<img src="http://placehold.it/150x150">
</div>
</div>
</div>
</div>
</div>
Related
I have an html page which displays three images in a row and I need to place a button over each of them in a responsive way. I want the images to change in size and then be one above the other when the page width is reduced, but I want the button size to also reduce as image reduces in size and I want the button position to remain the same wrt the image.
I found that I needed to use relative positioning for the button but when I do that a large amount of extra space appears below an image. If I use absolute positioning this space doesn't appear but then the button no longer stays positioned on the image when the image size and/or position changes. Also I can't find a way to reduce the button size.
How can I prevent the extra white space appearing and ensure the button stays over the image and how can i make the button size change dynamically when page width is changed?
* {
box-sizing: border-box;
}
.main {
color: limegreen;
background-color: lightsteelblue;
}
.row {
width: 100%;
display: block;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
}
#media screen and (max-width: 800px) {
.column {
float: none;
width: 360px;
margin-left: auto;
margin-right: auto;
}
}
#media screen and (max-width: 360px) {
.column {
width: 95%;
}
}
/* Clearfix (clear floats) */
.row::after {
content: "";
clear: both;
display: table;
}
.container {
position: relative;
}
/* Style the button and place it at the bottom of the container/image */
.container .btn {
position: relative;
bottom: 50%;
left: 50%;
transform: translate(-50%, -120%);
-ms-transform: translate(-50%, -50%);
background-color: transparent;
color: white;
font-size: 20px;
font-weight: 700;
padding: 12px 24px;
border: solid white;
cursor: pointer;
border-radius: 5px;
}
.container .btn:hover {
background-color: black;
}
<!DOCTYPE html>
<html>
<head>
<link href="images.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="main row container">
<div class="column">
<img src="https://www.w3schools.com/howto/img_snow.jpg" alt="Snow" style="width: 100%" />
<button class="btn">START TODAY</button>
</div>
<div class="column">
<img src="https://www.w3schools.com/howto/img_forest.jpg" alt="Forest" style="width: 100%" />
</div>
<div class="column">
<img src="https://www.w3schools.com/howto/img_mountains.jpg" alt="Mountains" style="width: 100%" />
</div>
</div>
</body>
</html>
i change some css structure in your code.maybe this can help
.main.row.container .column {
overflow: hidden;
display: flex;
align-items: center;
vertical-align: middle;
justify-content: center;
flex-wrap: wrap;
}
* {
box-sizing: border-box;
}
.main {
color: limegreen;
background-color: lightsteelblue;
}
.row {
width: 100%;
display: block;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
}
#media screen and (max-width: 800px) {
.column {
float: none;
width: 360px;
margin-left: auto;
margin-right: auto;
}
}
#media screen and (max-width: 360px) {
.column {
width: 95%;
}
}
/* Clearfix (clear floats) */
.row::after {
content: "";
clear: both;
display: table;
}
.container {
position: relative;
}
/* Style the button and place it at the bottom of the container/image */
.container .btn {
position: absolute;
color: white;
font-size: 20px;
font-weight: 700;
padding: 12px 24px;
border: solid white;
cursor: pointer;
border-radius: 5px;
background-color: transparent;
}
.container .btn:hover {
background-color: black;
}
<!DOCTYPE html>
<html>
<head>
<link href="images.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="main row container">
<div class="column">
<img src="https://www.w3schools.com/howto/img_snow.jpg" alt="Snow" style="width: 100%" />
<button class="btn">START TODAY</button>
</div>
<div class="column">
<img src="https://www.w3schools.com/howto/img_forest.jpg" alt="Forest" style="width: 100%" />
</div>
<div class="column">
<img src="https://www.w3schools.com/howto/img_mountains.jpg" alt="Mountains" style="width: 100%" />
</div>
</div>
</body>
</html>
I need help, im currently stuck on how to set different min-height's for two different iframe videos from Youtube that are on the same page.
Currently what seem's to work (but only for one or the other) is changing the min-height on ".cms-page iframe" and setting it to !important.
Here is how the css currently looks right now:
.cms-page iframe {
min-height: 564px !important;
}
Above is for the larger iframe, I am looking to also have a min-height of 250px for the smaller iframe.
Kind regards,
Harry
In your css, change .cms-page iframe to .vcontainer iframe.
Give a different id to each iframe and use it to define each one the min-height.
I gave the first one the id of iframe1 and the second iframe2. take a look
#iframe1{
min-height:250px !important;
}
#iframe2{
min-height:564px !important;
}
Working perfectly :)
.container-full {
width:100%;
margin:0;
}
.cms-page {
margin: 0;
}
.breadcrumb {
display: none;
}
.row .row {
width: 100%;
margin: 0 0px;
}
.col {
padding: 0px;
}
.image_full{
display:block;
}
.image_mobile{
display:none;
}
#media (max-width: 640px) and (min-width: 320px){
.image_full{
display:none;
}
.image_mobile{
display:block;
}
.container--pad {
padding-left: 0rem;
padding-right: 0rem;
}
}
.button2 {
width: 180px;
height: 50px;
border: 3px solid #FFFFFF;
text-decoration: none;
color: #ec1c24;
text-align: center;
display: block;
font-weight: 600;
background-color: #FFFFFF;
text-transform: uppercase;
margin-left: auto;
margin-right: auto;
}
.button2:hover {
color: #fff;
background-color: #111111;
border: 3px solid #111111;
}
.FullWidthImg {
width: 100vw;
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
}
.img-wrapper {
position: relative;
}
.img-wrapper img {
width: 100%;
}
.hcontainer {
max-width: 1000px;
margin-left: auto;
margin-right: auto;
}
.pcontainer {
padding-bottom: 20px;
max-width: 1000px;
margin-left: auto;
margin-right: auto;
}
.vcontainer {
max-width: 1000px;
margin-left: auto;
margin-right: auto;
}
.ccontainer {
padding-top: 80px;
padding-bottom: 80px;
width: 100%;
background-color: #efefef;
}
.img-wrapper .overlay {
position: absolute;
top: 64%; left: 0; right: 0; bottom: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
.img-wrapper h2 {
margin: 0 0 .5em;
}
.column {
float: left;
width: 50%;
padding: 10px;
}
.row:after {
content: "";
display: table;
clear: both;
}
#iframe1{
min-height:250px !important;
}
#iframe2{
min-height:564px !important;
}
<div class="vcontainer">
<p><iframe src="https://www.youtube.com/embed/l01s5oDySjM" frameborder="0" width="100%" id="iframe1" allowfullscreen=""></iframe></p>
<p> </p>
<p> </p>
</div>
<div class="ccontainer">
<div class="hcontainer"><img src="https://gallery.mailchimp.com/c4e779335ad94d19c242bf724/images/75b2051f-dc4d-4ca1-96f1-273d67b214fa.png" alt="" /></div>
<div class="pcontainer">
<div class="row" style="padding-top: 50px; padding-bottom: 50px;">
<div class="column">
<p style="text-align: center;"><span style="font-size: 18px; color: #777777;">We all know that after a long day, it’s tough to have energy for a good workout. With the help of 1UP Pre-Workout, you won’t feel hesitant to go train and put in the hard work.</span></p>
</div>
<div class="column">
<p id="small"><iframe id="iframe2" src="https://www.youtube.com/embed/pKJgRkV2vI8" frameborder="0" width="560" height="315" allowfullscreen=""></iframe></p>
</div>
</div>
</div>
</div>
You really shouldn't have to work around the iframe width/height with this code. Just set the width to the outer div.
.embed-responsive {
position: relative;
display: block;
height: 0;
padding: 0;
overflow: hidden;
}
.embed-responsive .embed-responsive-item,
.embed-responsive embed,
.embed-responsive iframe,
.embed-responsive object,
.embed-responsive video {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
}
.embed-responsive-16by9 {
padding-bottom: 56.25%;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div class="container">
<div class="row">
<div style="width:33%">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="https://www.youtube.com/embed/iOHkyZ62jjQ" frameborder="0" allowfullscreen="" id="widget2"></iframe>
</div>
</div>
</div>
<div class="row">
<div style="width:100%">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="https://www.youtube.com/embed/iOHkyZ62jjQ" frameborder="0" allowfullscreen="" id="widget2"></iframe>
</div>
</div>
</div>
</div>
</body>
</html>
I'm trying to figure out why there is extra space added to the right of the thumbnail images. I put a red border around the area to make it easier to see the extra white space. how would I remove it?
Any advice would be greatly appreciated.
jQuery(document).ready(function() {
$('.thumb').click(function() {
$('.main-image img').attr('src', $(this).children('img').attr('src'));
});
});
.pics {
overflow: hidden;
width: 60%;
box-sizing: border-box;
padding-left: 6em;
display:flex;
justify-content:center;
}
.main-image {
width: 100%;
}
.main-image img {
width: 100%
}
.thumb {
position:relative;
width:30%;
height:auto;
margin:1em;
border: 1px solid blue;
}
.selection-image {
display:flex;
flex-direction:column;
border:1px solid red;
}
.selection-image img {
width:100%;
height: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pics">
<div class="main-image">
<img src="https://images.unsplash.com/photo-1502901047037-d0184a3efead?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=e5e38bba3f79d4f86a648d7e9961ca09">
</div>
<div class="selection-image">
<div class="thumb">
<img src="https://images.unsplash.com/photo-1502901047037-d0184a3efead?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=e5e38bba3f79d4f86a648d7e9961ca09">
</div>
<div class="thumb">
<img src="https://images.unsplash.com/photo-1511644547841-f467df8071a4?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=151cc232aa6e73bab1aa03d23b276046">
</div>
<div class="thumb">
<img src="https://images.unsplash.com/photo-1477868433719-7c5f2731b310?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=5d54dfa7ff8cdf7d4214d468d7c7443b">
</div>
</div>
</div>
You are setting width of the pictures in thumb class to 30% and not centering the images. Set width of thumb class to auto and you can remove margin/padding if you want no white space.
.thumb {
position:relative;
width:auto;
height:auto;
margin:1em;
border: 1px solid blue;
}
Maybe simply move the width:30% to the container instead. Also make the image block to avoid the whitespace under them:
jQuery(document).ready(function() {
$('.thumb').click(function() {
$('.main-image img').attr('src', $(this).children('img').attr('src'));
});
});
.pics {
overflow: hidden;
width: 60%;
box-sizing: border-box;
padding-left: 6em;
display: flex;
justify-content: center;
}
.main-image {
width: 100%;
}
.main-image img {
width: 100%;
}
.thumb {
position: relative;
height: auto;
margin: 1em;
border: 1px solid blue;
}
.thumb img {
display: block;
}
.selection-image {
display: flex;
width: 30%;
flex-direction: column;
border: 1px solid red;
}
.selection-image img {
width: 100%;
height: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pics">
<div class="main-image">
<img src="https://images.unsplash.com/photo-1502901047037-d0184a3efead?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=e5e38bba3f79d4f86a648d7e9961ca09">
</div>
<div class="selection-image">
<div class="thumb">
<img src="https://images.unsplash.com/photo-1502901047037-d0184a3efead?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=e5e38bba3f79d4f86a648d7e9961ca09">
</div>
<div class="thumb">
<img src="https://images.unsplash.com/photo-1511644547841-f467df8071a4?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=151cc232aa6e73bab1aa03d23b276046">
</div>
<div class="thumb">
<img src="https://images.unsplash.com/photo-1477868433719-7c5f2731b310?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=5d54dfa7ff8cdf7d4214d468d7c7443b">
</div>
</div>
</div>
When I resize the browser, the images overlap with the video, and I don't want the to overlap. I want them to stay in position when I resize the browser.
iframe {
display: block;
margin: 0 auto;
margin-top: 60px;
}
.png1 img {
display: inline-block;
max-width: 100%;
height: auto;
margin: -430px 210px 850px;
}
.png2 img{
display: inline-block;
max-width: 100%;
height: auto;
float: right;
position: relative;
top: -85.100em;
right: 150px;
}
<div class="video">
<iframe width="600" height="415" src="https://www.youtube.com/embed/c9Qg7vm0lSk" frameborder="0" fullscreen></iframe>
</div>
<div class="png1">
<img src="https://s3.amazonaws.com/gameartpartnersimagehost/wp-content/uploads/2016/03/Adventure-Boy-Featured-Game-Art.png">
</div>
<div class="png2">
<img src="http://gameartpartnersimagehost.s3.amazonaws.com/wp-content/uploads/2016/07/royalty-free-game-art-commando-thumbnail0003.png">
</div>
You should learn Media queries as well, it will be helpful. Resize window to see the image move down.
Desktop
Mobile
.col {
color: #fff;
float: left;
margin: 2%;
width: 46%;
}
.one {
background-color: none;
}
.two {
background-color: none;
}
#media screen and (max-width: 600px) {
.col {
float: none;
margin: 0;
width: 100%;
}
}
iframe {
display: block;
margin: 0 auto;
margin-top: 60px;
}
<div id="container">
<div class="row">
<div class="video">
<iframe width="600" height="415" src="https://www.youtube.com/embed/c9Qg7vm0lSk" frameborder="0" fullscreen></iframe>
</div>
<div class="col one">
<img src="https://s3.amazonaws.com/gameartpartnersimagehost/wp-content/uploads/2016/03/Adventure-Boy-Featured-Game-Art.png">
</div>
<div class="col two">
<img src="http://gameartpartnersimagehost.s3.amazonaws.com/wp-content/uploads/2016/07/royalty-free-game-art-commando-thumbnail0003.png">
</div>
</div>
</div>
Because for .png1 img you are using margin as negetive values and for .png2 img you are using top value relativly to that image.Try removing those properties , you will get line by line
iframe {
display: block;
margin: 0 auto;
margin-top: 60px;
max-width: 100%;
}
.video,.png2,.png1 {
float: left;
width: 33%;
}
.png1 img {
max-width: 100%;
height: auto;
}
.png2 img{
display: inline-block;
max-width: 100%;
height: auto;
}
I've tried to add a display:table to a parent element (rowcontainer) and display:table-cell; to the child element (div1, div2) for over 500px width on screen. This worked, but the padding on the child elements now have to left or right padding, and the bottom row has something off with it, any ideas on how to fix this? :
Here is also a codepen of the problem:
http://codepen.io/anon/pen/MYxegN
#media screen and (max-width: 499px) {
.div1,
.div2 {
color: blue;
}
}
#pagewrap {
padding: 10px;
background-color: rgba(21, 21, 21, 0.75);
border: 1px red solid;
max-width: 1024px;
min-height: 87.5% height: inherit;
margin: 0 auto;
}
h1,
h2 {
color: white;
}
p {
color: silver;
}
#tablecontainer {
padding: 5px 5px 5px 0px;
width: 100%;
min-height: 100%;
color: white;
font-size: 20px;
}
.div1,
.div2 {
padding: 5px;
margin: 5px;
}
.div1 {
background-color: darkgreen;
padding: 5px;
}
.div2 {
background-color: green;
}
#media screen and (min-width: 500px) {
.rowcontainer {
padding: 2.5px;
display: table;
width: 100%;
}
.rowcontainer div {
display: table-cell;
}
.div1 {
padding: 1.25px;
}
}
<div id="pagewrap">
<div id="tablecontainer">
<div class="rowcontainer">
<div class="div1">1</div>
<div class="div2">2</div>
</div>
<div class="rowcontainer">
<div class="div1">3</div>
<div class="div2">4</div>
</div>
<div class="rowcontainer">
<div class="div1">5</div>
<div class="div2">6</div>
</div>
<div class="rowcontainer">
<div class="div1">7</div>
<div class="div2">9</div>
</div>
<div class="rowcontainer">
<div class="div1">9</div>
<div class="div2">10</div>
</div>
</div>
I think the correct structure is like this for CSS table.
#tablecontainer {
display:table; /*behaves like <table>*/
}
.rowcontainer {
display:table-row; /*behaves like <tr>*/
}
.rowcontainer div {
display:table-cell; /*behaves like <td>*/
}
As far as I can tell, all that is needed is to add
table-layout:fixed
in the media query
#media screen and (min-width: 500px){
.rowcontainer {
padding:2.5px;
display:table;
table-layout: fixed;
border-spacing: 5px 0;
border-collapse: separate;
width:100%;
}
}
Codepen Updated.
#media screen and (max-width: 499px) {
.div1,
.div2 {
color: blue;
}
}
html {
background: url(img/nature.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#pagewrap {
padding: 10px;
background-color: rgba(21, 21, 21, 0.75);
border: 1px red solid;
max-width: 1024px;
min-height: 87.5% height: inherit;
margin: 0 auto;
}
h1,
h2 {
color: white;
}
p {
color: silver;
}
#tablecontainer {
padding: 5px 5px 5px 0px;
width: 100%;
min-height: 100%;
color: white;
font-size: 20px;
}
.div1,
.div2 {
padding: 5px;
margin: 5px;
}
.div1 {
background-color: darkgreen;
padding: 5px;
}
.div2 {
background-color: green;
}
#media screen and (min-width: 500px) {
.rowcontainer {
padding: 2.5px;
display: table;
table-layout: fixed;
width: 100%;
}
.rowcontainer div {
display: table-cell;
}
.div1 {
padding: 1.25px;
}
}
<div id="pagewrap">
<div id="tablecontainer">
<div class="rowcontainer">
<div class="div1">1</div>
<div class="div2">2</div>
</div>
<div class="rowcontainer">
<div class="div1">3</div>
<div class="div2">4</div>
</div>
<div class="rowcontainer">
<div class="div1">5</div>
<div class="div2">6</div>
</div>
<div class="rowcontainer">
<div class="div1">7</div>
<div class="div2">9</div>
</div>
<div class="rowcontainer">
<div class="div1">9</div>
<div class="div2">10</div>
</div>
</div>
Are you looking for something like this?
#media screen and (max-width: 499px) {
.div1,
.div2 {
color: blue;
}
}
#pagewrap {
padding: 10px;
background-color: rgba(21, 21, 21, 0.75);
border: 1px red solid;
max-width: 1024px;
min-height: 87.5% height: inherit;
margin: 0 auto;
}
h1,
h2 {
color: white;
}
p {
color: silver;
}
#tablecontainer {
padding: 5px 5px 5px 0px;
width: 100%;
min-height: 100%;
color: white;
font-size: 20px;
display: table;
border-spacing: 5px;
}
.div1,
.div2 {
padding: 5px;
margin: 5px;
}
.div1 {
background-color: darkgreen;
padding: 5px;
}
.div2 {
background-color: green;
}
#media screen and (min-width: 500px) {
.rowcontainer {
padding: 2.5px;
display: table-row;
}
.rowcontainer div {
display: table-cell;
}
.div1 {
padding: 1.25px;
}
}
<div id="pagewrap">
<div id="tablecontainer">
<div class="rowcontainer">
<div class="div1">1</div>
<div class="div2">2</div>
</div>
<div class="rowcontainer">
<div class="div1">3</div>
<div class="div2">4</div>
</div>
<div class="rowcontainer">
<div class="div1">5</div>
<div class="div2">6</div>
</div>
<div class="rowcontainer">
<div class="div1">7</div>
<div class="div2">9</div>
</div>
<div class="rowcontainer">
<div class="div1">9</div>
<div class="div2">10</div>
</div>
</div>
You are almost correct in making a table with div. The above problem is because of the text. (Last cell has 2 digit text, if you make it one digit it works fine ). To fix this issue use below code. In the rowcontainer just add width.
.rowcontainer div{
display:table-cell;
width:50%
}
Your complete code can be seen on http://codepen.io/gauravshankar/pen/OPqXga