I tried to create a layout like instagram in css but faced an issue. i want it to be 3 grid like instagram with a gap of 10px on desktop mode and on below 768px i want it be single grid. i.e #media(max-width:768px) it should be 100% width.work link is attached of codepen[Codepen link of work][1]
[1]: https://codepen.io/TA0011/pen/eYjGvyV
const targets = document.querySelectorAll('[data-target]');
const contents = document.querySelectorAll('[data-content]');
targets.forEach(target => {
target.addEventListener('click',()=>{
const t = document.querySelector(target.dataset.target)
targets.forEach(t => {
t.classList.remove('active')
})
contents.forEach(c => {
c.classList.remove('active')
})
t.classList.add('active');
target.classList.add('active');
})
})
*{
margin:0;
padding:0;
box-sizing:border-box;
font-family: Sans-serif;
}
body{
padding: 5%;
}
.menu{
display:flex;
}
.menu p{
margin-right: 2rem;
cursor: pointer;
text-transform:uppercase;
}
.content{
margin-top:2rem;
}
[data-content]{
display:none;
}
.active[data-content]{
display:block;
}
.menu .active{
text-transform:uppercase;
color:#FFF;
background: #000;
padding: 5px 10px;
margin-top: -5px;
border-radius: 50px;
}
.cards{
display:flex;
flex:1;
flex-basis: 33.33%;
max-width: 33.33%;
min-width: 33.33%;
height: 100%;
position: relative;
}
.card{
border: 1px solid #ccc;
background: #fff;
}
<div class="menu">
<p data-target="#initial" class="active">Initial</p>
<p data-target="#product">Product</p>
<p data-target="#contact">Contact</p>
</div>
<div class="content">
<div data-content id="initial" class="active">
<div class="cards">
<div class="card">
abc
</div>
<div class="card">
abc
</div>
<div class="card">
abc
</div>
</div>
</div>
<div data-content id="product">
<div class="cards">
<div class="card">
lmn
</div>
<div class="card">
lmn
</div>
<div class="card">
lmn
</div>
</div>
</div>
<div data-content id="contact">
<div class="cards">
<div class="card">
xyz
</div>
<div class="card">
xyz
</div>
<div class="card">
xyz
</div>
</div>
</div>
</div>
I gave class names left, mid, right to 3 separate fields. After max-width:768px, I hidden the left and right areas, I created the spaces by giving margin. My English is not very good, you can contact me if you don't understand :)
const targets = document.querySelectorAll('[data-target]');
const contents = document.querySelectorAll('[data-content]');
targets.forEach(target => {
target.addEventListener('click',()=>{
const t = document.querySelector(target.dataset.target)
targets.forEach(t => {
t.classList.remove('active')
})
contents.forEach(c => {
c.classList.remove('active')
})
t.classList.add('active');
target.classList.add('active');
})
})
*{
margin:0;
padding:0;
box-sizing:border-box;
font-family: Sans-serif;
}
body{
padding: 5%;
}
.menu{
display:flex;
}
.menu p{
margin-right: 2rem;
cursor: pointer;
text-transform:uppercase;
}
.content{
margin-top:2rem;
}
[data-content]{
display:none;
}
.active[data-content]{
display:block;
}
.menu .active{
text-transform:uppercase;
color:#FFF;
background: #000;
padding: 5px 10px;
margin-top: -5px;
border-radius: 50px;
}
.cards{
display:flex;
height: 100%;
position: relative;
}
.card{
border: 1px solid #ccc;
background: #fff;
flex-grow:1;
margin-left:10px;
padding: 15px;
max-width:33%;
width:33%;
}
.card.left, .card.right{
display:none;
}
#media only screen and (max-width:768px) {
.card{
max-width:100%;
width:100%;
margin-bottom:10px;
}
.card.left, .card.right{
display:none;
}
.contact .cards, .product .cards {
flex-direction: column;
}
}
#media only screen and (max-width:320px) {
.menu p{
margin-right: 1rem;
font-size:12px;
}
}
<div class="menu">
<p data-target="#initial" class="active">Initial</p>
<p data-target="#product">Product</p>
<p data-target="#contact">Contact</p>
</div>
<div class="content">
<div data-content id="initial" class="active">
<div class="cards">
<div class="card left">
abc
</div>
<div class="card mid">
abc
</div>
<div class="card right">
abc
</div>
</div>
</div>
<div data-content id="product" class="product">
<div class="cards">
<div class="card">
lmn
</div>
<div class="card">
lmn
</div>
<div class="card">
lmn
</div>
</div>
</div>
<div data-content id="contact" class="contact">
<div class="cards">
<div class="card">
xyz
</div>
<div class="card">
xyz
</div>
<div class="card">
xyz
</div>
</div>
</div>
</div>
Related
I need to create equal height cards using flexbox or any other methods in css. But one of those cards will have a ribbon on top of the card. That will be set dynamically in react.
So I need to create equal height cards except one. Something like below,
An example is here,
https://codepen.io/andichamy-ga/pen/MGJPXv
HTML:
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar<br>
foo
</div>
</div>
<div class="some">
<div class="recommended">Recommended Card</div>
<div class="box">
foo<br>
</div>
</div>
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar
</div>
</div>
</div>
CSS:
.container {
display: flex;
}
.some {
padding: 20px;
margin-right: 20px;
}
.recommended {
background-color: yellow;
width: 200px;
height: 20px;
padding: 5px 10px;
}
.one {
background-color: transparent;
}
.box {
width: 200px;
height: 150px;
background-color: green;
padding: 10px;
}
I tried in many different ways. But none of those seems like a proper way. How can I do this elegantly?
You can make the top ribbon to be absolute position and rely on flexbox for the remaining to have equal height:
* {
box-sizing:border-box;
}
body {
background-color: #a3d5d3;
}
.container {
display: flex;
}
.some {
margin-top:50px;
margin-right: 30px;
position:relative;
}
.recommended {
position:absolute;
background-color: yellow;
left:0px;
right:0px;
height: 40px;
top:-40px;
padding: 5px 10px;
}
.one {
background-color: transparent;
}
.box {
width: 200px;
height:100%;
background-color: green;
padding: 10px;
}
<div class="container">
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br> bar
<br> foo bar
<br> foo bar
<br>
</div>
</div>
<div class="some">
<div class="recommended">Recommended Card</div>
<div class="box">
foo<br>
</div>
</div>
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br> bar
</div>
</div>
</div>
You want something like a price table, more in number like below.
https://jsfiddle.net/rdggv429/
<h2 style="text-align:center">Responsive Pricing Tables</h2>
<p style="text-align:center">Resize the browser window to see the effect.</p>
<div class="columns">
<ul class="price">
<li class="header">Basic</li>
<li class="grey">$ 9.99 / year</li>
<li>10GB Storage</li>
<li>10 Emails</li>
<li>10 Domains</li>
<li>1GB Bandwidth</li>
<li class="grey">Sign Up</li>
</ul>
</div>
<div class="columns special">
<ul class="price">
<li class="special-li">Special</li>
<li class="header" style="background-color:#4CAF50">Pro</li>
<li class="grey">$ 24.99 / year</li>
<li>25GB Storage</li>
<li>25 Emails</li>
<li>25 Domains</li>
<li>2GB Bandwidth</li>
<li class="grey">Sign Up</li>
</ul>
</div>
<div class="columns">
<ul class="price">
<li class="header">Premium</li>
<li class="grey">$ 49.99 / year</li>
<li>50GB Storage</li>
<li>50 Emails</li>
<li>50 Domains</li>
<li>5GB Bandwidth</li>
<li class="grey">Sign Up</li>
</ul>
</div>
* {
box-sizing: border-box;
}
.columns {
float: left;
width: 33.3%;
padding: 8px;
}
.price {
list-style-type: none;
border: 1px solid #eee;
margin: 0;
padding: 0;
-webkit-transition: 0.3s;
transition: 0.3s;
margin-top: 50px;
position: relative;
}
.price:hover {
box-shadow: 0 8px 12px 0 rgba(0, 0, 0, 0.2)
}
.price .header {
background-color: #111;
color: white;
font-size: 25px;
}
.price li {
border-bottom: 1px solid #eee;
padding: 20px;
text-align: center;
}
.price .grey {
background-color: #eee;
font-size: 20px;
}
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px 25px;
text-align: center;
text-decoration: none;
font-size: 18px;
}
.special-li {
position: absolute;
top: -60px;
border: 1px solid #ccc;
width: 100%;
}
#media only screen and (max-width: 600px) {
.columns {
width: 100%;
}
}
If you want the header dynamically, give it on the page load, append the LI to the first element on the UL
HTML
<div class="some-all">
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar<br>
foo
</div>
</div>
<div class="some">
<div class="recommended">Recommended Card</div>
<div class="box">
foo<br>
</div>
</div>
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar
</div>
</div>
use css
<style>
.some-all{display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.some-all .some{
background-color: green;
}
</style>
I don't think that can be possible with flexbox, but this could be a possible solution for your question, hope it might help you.
You can also view it on Codepen: https://codepen.io/techyogi/pen/ervNWW
CSS
$blue: #a3d5d3;
body {
background-color: $blue;
}
.container {
display: flex;
padding-top: 20px;
}
.some {
padding: 20px;
margin-right: 20px;
position:relative;
}
.recommended {
position: absolute;
background-color: yellow;
width: 200px;
height: 20px;
padding: 5px 10px;
margin-top: -30px;
}
.one {
background-color: transparent;
}
.box {
width: 200px;
height: 100%;
background-color: green;
padding: 10px;
}
HTML
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar<br>
foo
</div>
</div>
<div class="some">
<div class="recommended">Recommended Card</div>
<div class="box">
foo<br>
</div>
</div>
<div class="some">
<div class="recommended one"></div>
<div class="box">
foo<br>
bar
</div>
</div>
</div>
I have made 4 rectangle boxes in CSS. Here is the fiddle for it.
At this moment, they are looking exactly similar to the below design. I am wondering, how I can make exactly same (below) design (which I have made in fiddle) in Bootstrap 4
The CSS which I am using for the boxes are:
/***** Company heads CTO, CFO, and CEO START ************/
.company-heads {
margin-left: 300px;
padding-top: 80px;
font-style: italic;
margin-right: 289px
}
.company-heads .rectangle {
border-radius: 10px;
display: inline-block;
margin-bottom: 30px;
margin-right: 22px;
width: 355px;
height: 100px;
border: 1px solid #000;
background-color: white;
padding: 10px 10px 10px 100px;
position: relative;
}
.company-heads .rectangle .circle {
background: #aaa;
border-radius: 100%;
height: 60px;
width: 60px;
position: absolute;
top: 20px;
left: 20px;
}
/***** Company heads CTO, CFO, and CEO FINISH ************/
The width of the rectangle box is currently 355px but can be adjust according to the screen size.
I tried using the following code in Bootstrap 4 but it didn't work out.
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-3 left-side">ABC</div>
<div class="col-lg-3 right-side">DEF</div>
</div
</div>
.row {
text-align:center;
}
.col-md-4 {
border-radius:20px;
margin:10px;
border:1px solid #000;
display:inline-block;
float:none !important;
}
.col-md-2 {
border-radius:100%;
height:60px;
width:60px;
background:#ccc;
width:25%;
margin:20px;
}
.row h1, .row p {
font-style:italic;
text-align:left;
}
.row h1 {
font-size:1.4em;
}
.row p {
font-size:1em;
}
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="col-md-2"></div>
<h1>Will's profile, CEO</h1>
<p>Say something inspiring will</p>
</div>
<div class="col-md-4">
<div class="col-md-2"></div>
<h1>Will's profile, CEO</h1>
<p>Say something inspiring will</p>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="col-md-2"></div>
<h1>Zeeshan, CTO</h1>
<p>Say something inspiring</p>
</div>
<div class="col-md-4">
<div class="col-md-2"></div>
<h1>Whoever yall hire next</h1>
<p>Say something inspiring</p>
</div>
</div>
</div>
Here is the codepen of the demo working. New Demo
h1 {
font-style: italic;
}
p {
font-style: italic;
}
.col-md-5 {
border-radius:15px;
margin:10px;
border:1px solid #000;
}
.col-md-2 {
border-radius:100%;
height:60px;
width:60px;
background:#ccc;
width:25%;
margin:20px;
}
.row h1 {
font-size:1.4em;
}
.row p {
font-size:1em;
}
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-md-5">
<div class="col-md-2"></div>
<h1>Will's profile, CEO</h1>
<p>Say something inspiring will</p>
</div>
<div class="col-md-5">
<div class="col-md-2"></div>
<h1>Will's profile, CEO</h1>
<p>Say something inspiring will</p>
</div>
</div>
<div class="row">
<div class="col-md-5">
<div class="col-md-2"></div>
<h1>Zeeshan, CTO</h1>
<p>Say something inspiring</p>
</div>
<div class="col-md-5">
<div class="col-md-2"></div>
<h1>Whoever yall hire next</h1>
<p>Say something inspiring</p>
</div>
</div>
</div>
How to put banners side by side using HTML/CSS? Ideally with different sizes as shown below?
One simple way would be to display the banners inline-block, and assign them the required width.
.banner {
display: inline-block;
}
.banner-sm {
width: 32%;
}
.banner-lg {
width: 65%;
}
.banner {
height: 100px;
background: #DDD;
padding: 0; margin: 0;
}
<div class="row">
<div class="banner banner-lg"> </div>
<div class="banner banner-sm"> </div>
</div>
<div class="row">
<div class="banner banner-sm"> </div>
<div class="banner banner-sm"> </div>
<div class="banner banner-sm"> </div>
</div>
<div class="row">
<div class="banner banner-sm"> </div>
<div class="banner banner-lg"> </div>
</div>
Either use some grid system, or the bare CSS float property, pseudo example shown below:
.banner1 {
float: left;
width: 100px;
height: 20px;
margin: 4px;
border: 1px solid #777;
}
.banner2 {
float: left;
width: 200px;
height: 20px;
margin: 4px;
border: 1px solid #777;
}
.banner3 {
float: left;
width: 50px;
height: 20px;
margin: 4px;
border: 1px solid #777;
}
.clearfix {
clear: both;
}
<div class="banner1">banner</div>
<div class="banner1">banner</div>
<div class="clearfix"></div>
<div class="banner2">banner</div>
<div class="clearfix"></div>
<div class="banner3">banner</div>
<div class="banner3">banner</div>
<div class="banner3">banner</div>
<div class="banner3">banner</div>
<div class="clearfix"></div>
Good luck
You can use Twitter Bootstrap to get grid system and other useful layout functionality:
.row div {
height: 30px;
background: #aaa;
border: 1px solid #ddd;
}
* {
box-sizing: border-box;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='row'>
<div class='col-xs-8'></div>
<div class='col-xs-4'></div>
</div>
<div class='row'>
<div class='col-xs-4'></div>
<div class='col-xs-4'></div>
<div class='col-xs-4'></div>
</div>
<div class='row'>
<div class='col-xs-4'></div>
<div class='col-xs-8'></div>
</div>
<div class='row'>
<div class='col-xs-4'></div>
<div class='col-xs-8'></div>
<div class='col-xs-8'></div>
<div class='col-xs-4'></div>
</div>
If you are familiar with twitter-bootstrap then use its Grid system otherwise using inline-block will help you.
div {
border: 1px solid #ddd;
height: 200px;
margin: 5px;
display: inline-block;
box-sizing:border-box;
}
<section style="width:650px">
<div style="width:415px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:415px;"></div>
</section>
you can use CSS3 flex-box concept
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
flex-direction:column;
}
.flex-item {
background-color: cornflowerblue;
width: calc(100% - 20px);
height: 100px;
margin: 10px;
display:flex;
justify-content:space-between;
}
.sub{
height:100%;
background:white;
box-sizing:border-box;
}
.one{
width:75%;
border:1px solid green;
}
.two{
width:25%;
border:1px solid red;
}
.subb{
width:33%;
background:white;
height:100%;
}
<div class="flex-container">
<div class="flex-item">
<div class="sub one">sub 1 </div>
<div class="sub two">sub 2 </div>
</div>
<div class="flex-item">
<div class="subb s3">sub 3 </div>
<div class="subb s4">sub 4 </div>
<div class="subb s5">sub 5 </div>
</div>
</div>
You can use Bootstrap to do this.
Bootstarp is a Powerful css framework which enables web developer's
to do stuff like these(dividing screens etc).
Bootstrap is very easy to learn and implement.
You can start Learning Bootstrap here
I am trying to create a list that will show messages. The image below is what I wish to achive. Check the codepen for how it looks as of now!:
As you can see apart of the ui jumps up as it it utilizing float. I can't set a fixed height on the avatar red area as the message area can vary in height (basically the whole message can vary in size). I've gotten it to work by removing the float on the text-container however I'm not able to lineup the green arrow then. Any ideas?
Hree is codepen code for yous to fiddle with!
html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<div class="center">
<ol id="holder" class="scroll" style="background:pink;">
<li class="message">
<div class="thumb-fav-container">
<div class="thumb-fav-row">
<div class="thumb">
</div>
<div class="thumb-fav-num">
1000
</div>
</div>
<div class="thumb-fav-row">
<div class="fav">
</div>
<div class="thumb-fav-num">
0
</div>
</div>
</div>
<div class="message-avatar-container">
<div class="message-avatar">
</div>
</div>
<div class="text-container">
message
<br>1
<br>2
<br>3
<br>4
<br>5
<br>6
<br>6
<br>6
<br>6
<br>6
<br>6
<br>6
<br>6
</div>
<div class="text-arrow">
</div>
</li>
<li class="message">
<div class="thumb-fav-container">
<div class="thumb-fav-row">
<div class="thumb">
</div>
<div class="thumb-fav-num">
1000
</div>
</div>
<div class="thumb-fav-row">
<div class="fav">
</div>
<div class="thumb-fav-num">
0
</div>
</div>
</div>
<div class="message-avatar-container">
<div class="message-avatar">
</div>
</div>
<div class="text-container">
message
<br>1
<br>2
<br>3
<br>4
</div>
<div class="text-arrow">
</div>
</li>
</ol>
</div>
</body>
</html>
css:
/* Styles go here */
div.center
{
max-width: 1200px;
width: 1000px;
min-width:800px;
display: block;
margin-left: auto;
margin-right: auto;
}
ol {
list-style-type: none;
padding: 0em;
margin: 0em;
}
li {
display: inline;
margin: 0em;
padding: 0em;
left: 0em;
}
message {
background: red;
width: 100%;
height: auto;
}
div.thumb-fav-container {
margin-top: 20px;
float:left;
padding:10px;
width:70px;
background: lime;
}
div.thumb-fav-row {
height:20px;
margin-left:5px;
margin-bottom:5px;
background: silver;
}
div.thumb {
float:left;
width:20px;
height:20px;
background-image:url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Thumbs_up_font_awesome.svg/512px-Thumbs_up_font_awesome.svg.png');
background-size: contain;
}
div.fav {
float: left;
width:20px;
height:20px;
background-image:url('https://upload.wikimedia.org/wikipedia/commons/7/73/Farm-Fresh_star.png');
background-size: contain;
}
div.thumb-fav-num {
float: left;
margin-left:10px;
text-align: center;
background: pink;
}
div.text-container {
float:left;
margin-left:10px;
margin-top: 10px;
width:700px;
padding:20px;
background: silver;
}
div.text-arrow {
margin-top:20px;
float:left;
width: 0;
height: 0;
border-bottom: 30px solid transparent;
border-left: 30px solid lime;
border-top: 30px solid transparent;
}
div.message-avatar-container {
float:right;
padding:10px;
margin-top: 20px;
width:100px;
height:70px;
background: red;
}
div.message-avatar {
float:left;
width:50px;
height:50px;
background-image:url('http://findicons.com/files/icons/1072/face_avatars/300/a04.png');
background-size: contain;
}
Little mistake in your CSS:
Instead of:
message {
background: red;
width: 100%;
height: auto;
}
You should have:
.message {
clear:both;
float:left;
height: auto;
}
This yields the expected output (demo):
I want to display two boxes inline. I tried a lot to solve it.
.checks {
width:100%;
}
.moinfo {
background:#F29400;
width:50%;
padding-left:10px;
padding-right:10px;
margin-top:30px;
color: white !important;
padding-bottom:20px;
height:300px;
display:inline-block;
}
.role {
background:green;
width:50%;
padding-left:10px;
padding-right:10px;
margin-top:30px;
color: white !important;
padding-bottom:20px;
height:300px;
}
.hmovie {
border-bottom:3px dotted #93117E;
color:white;
width:200px;
}
.cat {
float:left;
width:100%;
padding-bottom:3px;
border-bottom:2px dotted white;
}
.cat {
float:left;
width:100%;
padding-bottom:3px;
}
.subcat {
float:left;
width:40%;
}
.dcont {
float:left;
width:60%;
}
<div class='checks'>
<div class='moinfo'>
<h2 class='hmovie'>Movie Information</h2>
<div class='cat'>
<div class='subcat'>Genre:</div>
<div class='dcont'>".$dummy[0]."</div>
</div>
<div class='cat'>
<div class='subcat'>Year:</div>
<div class='dcont'>".$dummy[1]."</div>
</div>
<div class='cat'>
<div class='subcat'>Running Time:</div>
<div class='dcont'>".$dummy[2]."</div>
</div>
<div class='cat'>
<div class='subcat'>Language:</div>
<div class='dcont'>".$dummy[3]."</div>
</div>
<div class='cat'>
<div class='subcat'>Subtitles:</div>
<div class='dcont'>".$dummy[4]."</div>
</div>
<div class='cat'>
<div class='subcat'>Country:</div>
<div class='dcont'>".$dummy[5]."</div>
</div>
<div class='lcat'>
<div class='subcat'>Awards:</div>
<div class='dcont'>".$dummy[6]."</div>
</div>
</div>
<div class='role'>
<h2 class='hmovie'>Cast Information</h2>
<div class='cat'>
<div class='subcat'>Cast:</div>
<div class='dcont'>".$dummy[7]."</div>
</div>
<div class='cat'>
<div class='subcat'>Director:</div>
<div class='dcont'>".$dummy[8]."</div>
</div>
<div class='cat'>
<div class='subcat'>Writer:</div>
<div class='dcont'>".$dummy[9]."</div>
</div>
<div class='cat'>
<div class='subcat'>Producers:</div>
<div class='dcont'>".$dummy[10]."</div>
</div>
<div class='cat'>
<div class='subcat'>Music:</div>
<div class='dcont'>".$dummy[11]."</div>
</div>
<div class='cat'>
<div class='subcat'>Cinematography:</div>
<div class='dcont'>".$dummy[12]."</div>
</div>
<div class='lcat'>
<div class='subcat'>Editor:</div>
<div class='dcont'>".$dummy[13]."</div>
</div>
<div class='lcat'>
<div class='subcat'>Sound:</div>
<div class='dcont'>".$dummy[13]."</div>
</div>
</div>
</div>
JSFiddle Demo
Any help will be appreciated.
Since you have applied padding, the effective total width of both <div>'s with width 50% will be more than 100%. You can Apply box-sizing:border-box for both the <div>s to include the padding while calculating the width and height.
Still, inline-block elements will respect the linebreaks in your HTML which will be converted to a white space, Breaking your 100% total again. You can either try fixing it using these hackish methods, Or you can simply float them left and right respectively instead.
.checks {
width:100%;
}
.moinfo {
box-sizing:border-box;
float:left;
background:#F29400;
width:50%;
padding-left:10px;
padding-right:10px;
margin-top:30px;
color: white !important;
padding-bottom:20px;
height:300px;
}
.role {
box-sizing:border-box;
float:right;
background:green;
width:50%;
padding-left:10px;
padding-right:10px;
margin-top:30px;
color: white !important;
padding-bottom:20px;
height:300px;
}
.hmovie {
border-bottom:3px dotted #93117E;
color:white;
width:200px;
}
.cat {
float:left;
width:100%;
padding-bottom:3px;
border-bottom:2px dotted white;
}
.cat {
float:left;
width:100%;
padding-bottom:3px;
}
.subcat {
float:left;
width:40%;
}
.dcont {
float:left;
width:60%;
}
<div class='checks'>
<div class='moinfo'>
<h2 class='hmovie'>Movie Information</h2>
<div class='cat'>
<div class='subcat'>Genre:</div>
<div class='dcont'>".$dummy[0]."</div>
</div>
<div class='cat'>
<div class='subcat'>Year:</div>
<div class='dcont'>".$dummy[1]."</div>
</div>
<div class='cat'>
<div class='subcat'>Running Time:</div>
<div class='dcont'>".$dummy[2]."</div>
</div>
<div class='cat'>
<div class='subcat'>Language:</div>
<div class='dcont'>".$dummy[3]."</div>
</div>
<div class='cat'>
<div class='subcat'>Subtitles:</div>
<div class='dcont'>".$dummy[4]."</div>
</div>
<div class='cat'>
<div class='subcat'>Country:</div>
<div class='dcont'>".$dummy[5]."</div>
</div>
<div class='lcat'>
<div class='subcat'>Awards:</div>
<div class='dcont'>".$dummy[6]."</div>
</div>
</div>
<div class='role'>
<h2 class='hmovie'>Cast Information</h2>
<div class='cat'>
<div class='subcat'>Cast:</div>
<div class='dcont'>".$dummy[7]."</div>
</div>
<div class='cat'>
<div class='subcat'>Director:</div>
<div class='dcont'>".$dummy[8]."</div>
</div>
<div class='cat'>
<div class='subcat'>Writer:</div>
<div class='dcont'>".$dummy[9]."</div>
</div>
<div class='cat'>
<div class='subcat'>Producers:</div>
<div class='dcont'>".$dummy[10]."</div>
</div>
<div class='cat'>
<div class='subcat'>Music:</div>
<div class='dcont'>".$dummy[11]."</div>
</div>
<div class='cat'>
<div class='subcat'>Cinematography:</div>
<div class='dcont'>".$dummy[12]."</div>
</div>
<div class='lcat'>
<div class='subcat'>Editor:</div>
<div class='dcont'>".$dummy[13]."</div>
</div>
<div class='lcat'>
<div class='subcat'>Sound:</div>
<div class='dcont'>".$dummy[13]."</div>
</div>
</div>
</div>
You need to add display:inline-flex to your .checks.
.checks {
width: 100%;
display: inline-flex;
}
.moinfo {
background: #F29400;
width: 50%;
padding-left: 10px;
padding-right: 10px;
margin-top: 30px;
color: white !important;
padding-bottom: 20px;
height: 300px;
display: inline-block;
}
.role {
background: green;
width: 50%;
padding-left: 10px;
padding-right: 10px;
margin-top: 30px;
color: white !important;
padding-bottom: 20px;
height: 300px;
}
.hmovie {
border-bottom: 3px dotted #93117E;
color: white;
width: 200px;
}
.cat {
float: left;
width: 100%;
padding-bottom: 3px;
border-bottom: 2px dotted white;
}
.cat {
float: left;
width: 100%;
padding-bottom: 3px;
}
.subcat {
float: left;
width: 40%;
}
.dcont {
float: left;
width: 60%;
}
<div class='checks'>
<div class='moinfo'>
<h2 class='hmovie'>Movie Information</h2>
<div class='cat'>
<div class='subcat'>Genre:</div>
<div class='dcont'>".$dummy[0]."</div>
</div>
<div class='cat'>
<div class='subcat'>Year:</div>
<div class='dcont'>".$dummy[1]."</div>
</div>
<div class='cat'>
<div class='subcat'>Running Time:</div>
<div class='dcont'>".$dummy[2]."</div>
</div>
<div class='cat'>
<div class='subcat'>Language:</div>
<div class='dcont'>".$dummy[3]."</div>
</div>
<div class='cat'>
<div class='subcat'>Subtitles:</div>
<div class='dcont'>".$dummy[4]."</div>
</div>
<div class='cat'>
<div class='subcat'>Country:</div>
<div class='dcont'>".$dummy[5]."</div>
</div>
<div class='lcat'>
<div class='subcat'>Awards:</div>
<div class='dcont'>".$dummy[6]."</div>
</div>
</div>
<div class='role'>
<h2 class='hmovie'>Cast Information</h2>
<div class='cat'>
<div class='subcat'>Cast:</div>
<div class='dcont'>".$dummy[7]."</div>
</div>
<div class='cat'>
<div class='subcat'>Director:</div>
<div class='dcont'>".$dummy[8]."</div>
</div>
<div class='cat'>
<div class='subcat'>Writer:</div>
<div class='dcont'>".$dummy[9]."</div>
</div>
<div class='cat'>
<div class='subcat'>Producers:</div>
<div class='dcont'>".$dummy[10]."</div>
</div>
<div class='cat'>
<div class='subcat'>Music:</div>
<div class='dcont'>".$dummy[11]."</div>
</div>
<div class='cat'>
<div class='subcat'>Cinematography:</div>
<div class='dcont'>".$dummy[12]."</div>
</div>
<div class='lcat'>
<div class='subcat'>Editor:</div>
<div class='dcont'>".$dummy[13]."</div>
</div>
<div class='lcat'>
<div class='subcat'>Sound:</div>
<div class='dcont'>".$dummy[13]."</div>
</div>
</div>
</div>
There are 2 ways to do this:
You need to add "display:inline-block" to the second element + "box-sizing: border-box;" to both elements in order to include the padding in the "50%" width.
Your code should look like this:
.moreinfo{
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
display:inline-block;
width:50%;
}
Remove the display property and add "float:left" (this will actually change the display to block);
Add "overflow:hidden" to the parent.
http://jsfiddle.net/7jeye9y6/7/
you need to add
display:inline-block
to second box, and change width of boxes
http://jsfiddle.net/7jeye9y6/2
Just add display inline flex to you .checks class and -webkit-inline-flex if safari
.checks{
width:100%;
display:inline-flex;
}
You need to use display:inline-block for both the div. Also use box-sizing:border-box to calculate excess padding. Update your CSS like below.
.moinfo{
background:#F29400;
width:50%;
padding-left:10px;
padding-right:10px;
margin-top:30px;
color: white !important ;
padding-bottom:20px;
height:300px;
display:inline-block;
font-size: 14px;
box-sizing:border-box;
}
.role{
background:green;
width:50%;
padding-left:10px;
padding-right:10px;
margin-top:30px;
color: white !important ;
padding-bottom:20px;
height:300px;
font-size: 14px;
display:inline-block;
box-sizing:border-box;
}
DEMO
You are using 50% 50% and placing paddings left and right of 10px; this makes it more than 100%; also, either you choose float:left; or display:inline;
This Made them displayed inline:
.moinfo{
background:#F29400;
width:46%;
margin:0px;
padding-left:2%;
padding-right:2%;
margin-top:30px;
color: white !important ;
padding-bottom:20px;
height:300px;
display:inline-block;
float:left;
}
.role{
margin:0px;
background:green;
width:46%;
padding-left:2%;
padding-right:2%;
margin-top:30px;
color: white !important ;
padding-bottom:20px;
height:300px;
float:left;
}
Add this into your .moinfo and .role
display:inline-block;
box-sizing:border-box;