Right now I have this:
But I need something like this:
HTML
<div id="content">
<div class="block" style="height:600px;">
</div>
<div class="block" style="height:500px;">
</div>
<div class="block" style="height:500px;">
</div>
...
</div>
CSS
.block
{
width:350px;
background-color:white;
border-radius:5px;
margin-right:80px;
margin-bottom:80px;
display:inline-block;
}
#content
{
position:relative;
display:inline;
overflow:auto;
}
I tried using columns but that didn't work well, it showed one column only even though the column count was higher than 1.
Here is my solution:
HTML:
<div class="grid-container">
<div class="third">
<div class="grid grid1">
<p>Grid 1</p>
</div>
<div class="grid grid2">
<p>Grid 2</p>
</div>
</div>
<div class="third">
<div class="grid grid3">
<p>Grid 3</p>
</div>
<div class="grid grid4">
<p>Grid 4</p>
</div>
</div>
<div class="third">
<div class="grid grid5">
<p>Grid 5</p>
</div>
<div class="grid grid6">
<p>Grid 6</p>
</div>
</div>
</div>
CSS:
.grid-container {
width: 100%;
text-align: center;
margin-top: 15px;
}
.third {
display: inline-table;
width: 30%;
}
.grid {
border: 1px solid black;
margin: 10px 0;
}
.grid1 {
height: 200px;
}
.grid2 {
height: 100px;
}
.grid3 {
height: 100px;
}
.grid4 {
height: 350px;
}
.grid5 {
height: 200px;
}
.grid6 {
height: 200px;
}
Now i have used lots of css classes here (grid1, grid2 ...), they normally dont have to be used, just set height: auto so it takes the height needed to show all content.
Working example can be found here:
http://cssdeck.com/labs/full/nuauntmo
Depending on what you are trying to achieve, you could put the vertically stacked blocks in separate containers. Something like this:
HTML:
<div id="content">
<div class="col">
<div class="block" style="height:600px;">
</div>
<div class="block" style="height:500px;">
</div>
</div>
<div class="col">
<div class="block" style="height:500px;">
</div>
<div class="block" style="height:500px;">
</div>
</div>
...
CSS:
.col {
display: inline-block;
margin-right:80px;
vertical-align: top;
}
.block {
width:350px;
background-color:#ccc;
border-radius:5px;
margin-bottom:80px;
display:block;
vertical-align: top;
}
#content {
position:relative;
display:inline;
overflow:auto;
}
The columns will wrap if there is not enough horizontal space though, so the container would have to have a fixed width.
try adding vertical-align property in css.
.block
{
width:350px;
background-color:grey;
border-radius:5px;
margin-right:80px;
margin-bottom:80px;
display:inline-block;
vertical-align: top;
}
Related
I'm trying to understand how to build a 4 boxes square like the one on the printscreen. I've found that layout on Apple's website and I pretty like it!
I tried with bootstrap and flexbox. I think flexbox is a better solution, but I didn't find a way to reproduce this layout.
Anybody can help me to figure out how to create that layout?
If you'd like to use bootstrap, this is easily doable.
.noMargin {
margin: 0px;
}
.one {
background-color: red;
}
.two {
background-color: yellow;
}
.three {
background-color: green;
}
.four {
background-color: blue;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row noMargin">
<div class="col one">
one
</div>
<div class="col two">
two
</div>
</div>
<div class="row noMargin">
<div class="col three">
three
</div>
<div class="col four">
four
</div>
</div>
</div>
If you would like to do pure html/css:
.row {
display: flex;
width: 100%;
}
.row div {
width: 50%;
}
.noMargin {
margin: 0px;
}
.one {
background-color: red;
}
.two {
background-color: yellow;
}
.three {
background-color: green;
}
.four {
background-color: blue;
}
<div class="row noMargin">
<div class="one">
one
</div>
<div class="two">
two
</div>
</div>
<div class="row noMargin">
<div class="three">
three
</div>
<div class="four">
four
</div>
</div>
<!DOCTYPE html>
<html>
<head>
<title>Box</title>
<style>
#div1{
height:300px;
width:300px;
background-color:red;
margin:0;
}
#div2{
height:300px;
width:300px;
background-color:green;
position:relative;
left:320px;
bottom:300px;
}
#div3{
height:300px;
width:300px;
background-color:yellow;
position:relative;
bottom:280px;
}
#div4{
height:300px;
width:300px;
background-color:blue;
position:relative;
left:320px;
bottom:580px;
}
</style>
</head>
<body>
<div id="div1">
</div>
<div id="div2">
</div>
<div id="div3">
</div>
<div id="div4">
</div>
</body>
</html>
I'm building a website, and I'm trying to get a div element to stick to the right side of the page.
However, when my other divs, that contain blog post data/images scroll over to the next page, the div gets entered down.
How do I prevent the right side column from being entered down, while still allowing my blog post entries to scroll over?
Here is my code, what's relevant anyways. I'm sorry if this is a beginner question (it really is). I appreciate all the help I can get.
Thanks.
.column {
float:left;
}
.column.main {
width:70%;
min-height:1px;
}
.column.side {
width:20%;
min-height:1px;
}
.column.left {
width:10%;
background-color:012C40;
height:85%;
min-width:1px;
}
.column.right {
width:10%;
background-color:012C40;
height:85%;
float:right;
min-height:1px;
}
.postAd {
width:19%;
height:32%;
float:left;
background-color:DAEBF2;
text-align:center;
display:inline-block;
margin:.5%;
overflow: auto;
}
.postAd img {
width:80%;
height:80%;*/
}
<div class="column left">
</div>
<!--middle content-->
<div class="postAd">
<img src="images/Sunset.JPG" alt="sunset">
<p>Text here!</p>
</div>
<div class="postAd">
<img src="images/Sunset.JPG" alt="sunset">
<p>Text here!</p>
</div>
<div class="postAd">
<img src="images/Sunset.JPG" alt="sunset">
<p>Text here!</p>
</div>
<div class="postAd">
<img src="images/Sunset.JPG" alt="sunset">
<p>Text here!</p>
</div>
<div class="postAd">
</div>
<!--right side content-->
<div class="column right">
</div>
First of all, thanks for all of the proposed solutions! However, I've tried each one, and I'm running into problems. I have a navigation bar on top of my website, and each one overwrites that bar. When I try to make adaptations, I get the same problem as before. How do I implement these without completely destroying the layout of my website?
Again, huge thanks to everyone that responded.
You can use flex positioning like below
.parent
{
display:flex;
}
.right
{
flex:1; /*which is equal to 1 portion of width */
}
.left
{
flex:1; /*which is equal to 1 portion of width */
}
.center
{
flex:8; /*which is equal to 8 portion of width */
}
I suggest you to watch this video on youtube .
There are many different methods. One of the simpler ones is to use:
display:table-cell
I added a middle column for the example.
.column {
display:table-cell;
vertical-align:top;
}
.column.left {
width:10%;
background-color:#012C40;
color:#ffffff;
}
.column.right {
width:10%;
background-color:#012C40;
color:#ffffff;
}
.postAd {
min-width:23.5%;
height:32%;
background-color:#DAEBF2;
text-align:center;
display:inline-block;
margin:0.5%;
overflow: auto;
}
.postAd img {
width:80%;
height:80%;
}
<div class="column left">
[column left]
</div><!-- .column.left -->
<div class="column middle">
<div class="postAd">
[image]
<p>Text here!</p>
</div>
<div class="postAd">
[image]
<p>Text here!</p>
</div>
<div class="postAd">
[image]
<p>Text here!</p>
</div>
<div class="postAd">
[image]
<p>Text here!</p>
</div>
<div class="postAd">
[image]
<p>Text here!</p>
</div>
</div><!-- .column.middle -->
<div class="column right">
[column right]
</div><!-- .column.right -->
I think this what you are looking to do
The right-left columns should be position:fixed then I just put width:150px then for the right column width:150px and I set up for the middle content margin-left: 150px and margin-right: 150px; that's all
and I used for items in the middle content to show flex-warp
this code:
flex-wrap: wrap;
padding: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
align-items: left;
justify-content: left;
Here's the code:
<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
}
html {
height: 100%;
}
.column-left {
height: 100%;
width: 15%;
position: fixed;
z-index: 999;
top: 0;
left: 0;
background-color: #d6c4ff;
overflow-x: hidden;
padding-top: 60px;
}
.column-right {
height: 100%;
width: 15%;
position: fixed;
z-index: 999;
top: 0;
right: 0;
background-color: #d6c4ff;
overflow-x: hidden;
padding-top: 60px;
}
.middle-content{
margin-left: 17%;
margin-right: 17%;
height: 100%;
padding: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
flex-wrap: wrap;
align-items: left;
justify-content: left;
}
.postAd {
width:19%;
height:32%;
float:left;
background-color:#DAEBF2;
text-align:center;
display:inline-block;
margin:.5%;
overflow: auto;
}
.postAd img {
width:80%;
height:80%;*/
}
</style>
</head>
<body>
<!--left side content-->
<div class="column-left">
</div>
<!--middle content-->
<div class="middle-content">
<div class="postAd">
<img src="images/Sunset.JPG" alt="sunset">
<p>Text here!</p>
</div>
<div class="postAd">
<img src="images/Sunset.JPG" alt="sunset">
<p>Text here!</p>
</div>
<div class="postAd">
<img src="images/Sunset.JPG" alt="sunset">
<p>Text here!</p>
</div>
<div class="postAd">
<img src="images/Sunset.JPG" alt="sunset">
<p>Text here!</p>
</div>
<div class="postAd">
<img src="images/Sunset.JPG" alt="sunset">
<p>New here!</p>
</div>
<div class="postAd">
<img src="images/Sunset.JPG" alt="sunset">
<p>New here!</p>
</div>
</div>
<!--right side content-->
<div class="column-right">
</div>
</body>
</html>
You should use position: fixed; on the right div.
I have some problems with my DIV table.. maybe there is a better way to do this.
I want to have all columns to be the same height as the highest column. Is there a way to do it? or is there another way to make this work ?
I have to made a jsfiddle example here with my code: http://jsfiddle.net/rb500o4L/ (right column is higher than left, middle and the logo column.)
My CSS code:
div.round-border {
border: solid 1px;
border-color: #002F67;
border-radius: 10px;
}
#container {
display: table;
width: 100%;
}
#row {
display: table-row;
}
#cell {
display: table-cell;
}
#cell-logo {
display: table-cell;
width: 200px;
}
My HTML code:
<div id="container">
<div id="row">
<div id="cell">
<div class="round-border">
<h4>Left Col</h4>
<p>...</p>
</div>
</div>
<div id="cell">
<div class="round-border">
<h4>Middle Col</h4>
<p>...</p>
</div>
</div>
<div id="cell">
<div class="round-border">
<h4>Right Col</h4>
<p>...</p>
<p>...</p>
</div>
</div>
<div id="cell-logo">
<div class="round-border">
<h4>LOGO AREA</h4>
<p>...</p>
</div>
</div>
</div>
</div>
I appreciate any recommendation.
use this css
div.round-border {
border: solid 1px;
border-color: #002F67;
border-radius: 10px;
}
container {
width: 100%;
}
row {
height:auto;
}
#cell
{
height:auto;
min-height:400px;
width:50px;
display:inline-block;
}
#cell-logo {
width: 50px;
}
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;
I have the following HTML:
<p>messy</p>
<div class="row">
<div class="cell">
<div class="one wrapper">1</div>
</div>
<div class="cell">
<div class="two wrapper">2</div>
</div>
<div class="cell">
<div class="three wrapper">
<div class="foo">3</div>
</div>
</div>
</div>
<p>good</p>
<div class="row">
<div class="cell">
<div class="one wrapper">1</div>
</div>
<div class="cell">
<div class="two wrapper">2</div>
</div>
<div class="cell">
<div class="three wrapper">3</div>
</div>
</div>
With this CSS:
.row {
display: table;
table-layout: fixed;
overflow: hidden;
background-color:blue;
width:100%;
}
.cell {
display: table-cell;
overflow: hidden;
padding: 0;
}
.wrapper {
overflow: hidden;
position: relative;
padding:0;
display: block;
height:42px;
background-color:red;
}
.one {
width:100px;
}
.two {
width:40px;
}
.three {
width:100px;
}
.foo {
padding: 10px;
}
You can see the fiddle here.
Why is three messing up the layout in case a child has a padding? I've read various articles about margin collapsing in the past, but I could'nt fix this layout using one of the techniques.
It's simple just add vertical-align: middle; in .cell Class.
jsFiddle