HTML/CSS grid layout - html

How could I change this grid layout so that the second row of blocks sit just below the corresponding block above it instead of forming a completely new row?
http://jsfiddle.net/AndyMP/wSvrN/
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
#container {
position: absolute;
width: 60%;
left: 50%;
margin-left: -30%;
border: 1px dotted #333;
padding: 20px;
}
.box1 {
position: relative;
float: left;
width: 100px;
height: 150px;
background: #666;
margin: 0 15px 15px 0;
}
.box2 {
position: relative;
float: left;
width: 100px;
height: 200px;
background: #666;
margin: 0 15px 15px 0;
}
.box3 {
position: relative;
float: left;
width: 100px;
height: 100px;
background: #666;
margin: 0 15px 15px 0;
}
HTML
<div id="container">
<div class="box1"></div>
<div class="box3"></div>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box2"></div>
<div class="box1"></div>
<div class="box1"></div>
<div class="box3"></div>
<div class="box2"></div>
</div>

You can not achieve this with Pure CSS. You have to use http://masonry.desandro.com/ for this.

Do you mean like this ?
http://jsfiddle.net/LtLrx/
CSS:
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
#container {
position: absolute;
width: 60%;
left: 50%;
margin-left: -30%;
border: 1px dotted #333;
padding: 20px;
}
.contleft
{
float: left;
margin-right: 15px;
width: 30%;
position: relative;
height: 100%;
}
.contmiddle
{
float: left;
margin-right: 15px;
width: 30%;
position: relative;
height: 100%;
}
.contright
{
float: left;
width: 30%;
position: relative;
height: 100%;
}
.box1 {
position: relative;
float: left;
width: 100px;
height: 150px;
background: #666;
margin: 0 15px 15px 0;
}
.box2 {
position: relative;
float: left;
width: 100px;
height: 200px;
background: #666;
margin: 0 15px 15px 0;
}
.box3 {
position: relative;
float: left;
width: 100px;
height: 100px;
background: #666;
margin: 0 15px 15px 0;
}
HTML:
<div id="container">
<div class="contleft">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box1"></div>
</div>
<div class="contmiddle">
<div class="box2"></div>
<div class="box1"></div>
<div class="box1"></div>
<div class="box2"></div>
</div>
<div class="contright">
<div class="box3"></div>
<div class="box1"></div>
<div class="box2"></div>
<div class="box1"></div>
</div>
</div>

I don't exactly get what you want. When I put that code into a test file, I get the following in my browser:
To me, it looks like the last two blocks are exactly below the other blocks in that same column.
A problem may be that you are specifying the width of the container as a percentage of the screen, and the width of the blocks as an absolute value.
Please comment, so I can make my answer clearer, this is all the info I can make from your question.

Related

unable to get height as 100 percent

I have created a div and inside the div I have made bars for which I have to set max-height and height as 100% but I do not know what is the problem as the height 100% is not showing. Can anyone help me out with this. I want to show the bars height to be placed according to the values but the problem is the height is only showing when I am setting height in pixels it is not working when I place height as 100% I want to show the height to be 100% can anyone help me out with fixing this issue for me please would be grateful for your help.
Here is my code -
.bar_graph {
width: 341px;
height: 258px;
background-color: #fff;
position: absolute;
top: 15px;
left: 15px;
padding: 20px 12px;
display: block;
border: 1px solid #a3a3a3;
}
span.line_gr {
display: block;
background-color: #3d4a7b;
margin: auto;
width: 24px;
max-height: 177px;
margin-left: 0;
height: 100%;
}
.bars_area {
width: 238px;
float: right;
position: absolute;
bottom: -8px;
right: 0;
}
.bars {
float: left;
margin: 0 10px;
margin-top: 20px;
height: 100%;
width: 27px;
}
.bars >p {
font-size: 12px;
margin: 0;
line-height: 30px;
font-weight: bold;
}
.head_graph > h2 {
font-size: 14px;
font-weight: bold;
margin-bottom: 6px;
color: #000;
}
.bar_main {
height: 200px;
position: relative;
}
.bar_main > .line {
height: 60px;
width: 100%;
border-top: 1px solid #ccc;
line-height: 20px;
font-size: 12px;
}
<div class="bar_graph">
<div class="head_graph"><h2>Heading</h2></div>
<div class="bar_main">
<div class="line">3000,000 Mil</div>
<div class="line">200,000</div>
<div class="line">100,000</div>
<div class="line"></div>
<div class="bars_area">
<div class="bars">
<span class="line_gr"></span>
<p>2016</p>
</div>
<div class="bars">
<span class="line_gr"></span>
<p>2015</p>
</div>
<div class="bars">
<span class="line_gr"></span>
<p>2014</p>
</div>
<div class="bars">
<span class="line_gr"></span>
<p>2013</p>
</div>
<div class="bars">
<span class="line_gr"></span>
<p>2012</p>
</div>
</div>
</div>
</div>
I do not know what is the problem as the height 100% is not showing
A height in percent only works if the parent element also has a height (either set explicitly, or implicitly based on other properties, such as an absolute positioned element with top and bottom given).
Your .bars_area does not have such a height, so trying a height in percentage on the children won’t work either.
As others says it won't work. I can suggest you a different approach if you like you can do it.Use div instead of span.Remember I am just suggesting you another approach according your code not an answer.
.bar_graph {
width: 341px;
height: 258px;
background-color: #fff;
position: absolute;
top: 15px;
left: 15px;
padding: 20px 12px;
display: block;
border: 1px solid #a3a3a3;
}
.inner {
position: absolute;
width:5px;
height:200px;
background: grey;
bottom:25px;
}
span.line_gr {
display: block;
background-color: #3d4a7b;
margin: auto;
width: 24px;
max-height: 177px;
margin-left: 0;
height: 100%;
}
.bars_area {
width: 238px;
float: right;
position: absolute;
bottom: -8px;
right: 0;
}
.bars {
float: left;
margin: 0 10px;
margin-top: 20px;
height: 100%;
overflow: hidden;
}
.bars >p {
font-size: 12px;
margin: 0;
line-height: 30px;
font-weight: bold;
}
.head_graph > h2 {
font-size: 14px;
font-weight: bold;
margin-bottom: 6px;
color: #000;
}
.bar_main {
height: 200px;
position: relative;
}
.bar_main > .line {
height: 60px;
width: 100%;
border-top: 1px solid #ccc;
line-height: 20px;
font-size: 12px;
}
<div class="bar_graph">
<div class="head_graph"><h2>Heading</h2></div>
<div class="bar_main">
<div class="line">3000,000 Mil</div>
<div class="line">200,000</div>
<div class="line">100,000</div>
<div class="line"></div>
<div class="bars_area">
<div class="bars">
<div class="inner"></div>
<p>2016</p>
</div>
<div class="bars">
<div class="inner"></div>
<p>2015</p>
</div>
<div class="bars">
<div class="inner"></div>
<p>2014</p>
</div>
<div class="bars">
<div class="inner"></div>
<p>2013</p>
</div>
<div class="bars">
<div class="inner"></div>
<p>2012</p>
</div>
</div>
</div>
</div>
First set .bars_area to height 100% and then set position relative on .bars
I hope it is what you want.
.bar_graph {
width: 341px;
height: 258px;
background-color: #fff;
position: absolute;
top: 15px;
left: 15px;
padding: 20px 12px;
display: block;
border: 1px solid #a3a3a3;
}
span.line_gr {
display: block;
background-color: #3d4a7b;
margin: auto;
width: 24px;
max-height: 177px;
margin-left: 0;
height: 100%;
}
.bars_area {
width: 238px;
float: right;
position: absolute;
bottom: -8px;
right: 0;
height: 100%;
}
.bars {
float: left;
margin: 0 10px;
margin-top: 20px;
height: 100%;
width: 27px;
position: relative;
}
.bars >p {
font-size: 12px;
margin: 0;
line-height: 30px;
font-weight: bold;
}
.head_graph > h2 {
font-size: 14px;
font-weight: bold;
margin-bottom: 6px;
color: #000;
}
.bar_main {
height: 200px;
position: relative;
}
.bar_main > .line {
height: 60px;
width: 100%;
border-top: 1px solid #ccc;
line-height: 20px;
font-size: 12px;
}
<div class="bar_graph">
<div class="head_graph"><h2>Heading</h2></div>
<div class="bar_main">
<div class="line">3000,000 Mil</div>
<div class="line">200,000</div>
<div class="line">100,000</div>
<div class="line"></div>
<div class="bars_area">
<div class="bars">
<span class="line_gr"></span>
<p>2016</p>
</div>
<div class="bars">
<span class="line_gr"></span>
<p>2015</p>
</div>
<div class="bars">
<span class="line_gr"></span>
<p>2014</p>
</div>
<div class="bars">
<span class="line_gr"></span>
<p>2013</p>
</div>
<div class="bars">
<span class="line_gr"></span>
<p>2012</p>
</div>
</div>
</div>
</div>
The parent element should have margins and padding set to 0. Then, the child element can be given that property of height:100%;

CSS overflow and white-space not working

Current Situation
Using the following code I show a couple of divs floated to the left.
* {
margin: 0;
padding: 0;
border: none;
box-sizing: border-box;
}
.container {
width: 100%;
height: 100%;
}
.header {
height: 80px;
position: fixed;
width: 100%;
background: green;
}
.inner-container {
position: absolute;
top: 80px;
left: 0px;
right: 0px;
bottom: 0px;
overflow: auto;
white-space: nowrap;
}
.column {
height: 500px;
width: 150px;
background: red;
float: left;
margin: 5px;
}
<div class="container">
<div class="header">
</div>
<div class="inner-container">
<div class="column">
</div>
<div class="column">
</div>
<div class="column">
</div>
</div>
</div>
Current result:
Problem
What I want is that the red boxes don't wrap within its container. I want both, a vertical and horizontal scroll bar if the space is not enough. For the vertical scrollbar it works. What am I missing?
JSFiddle: https://jsfiddle.net/brainchest/j6zh400v/
A fix I found was to change the .column from being a float: left to display: inline-block. This treats each column as a "word" (like a word in text) and thus the white-space: no-wrap; applies. Otherwise, the float: left changes the way the element gets positioned.
Edited Fiddle: https://jsfiddle.net/9bo4f5pv/
Use display: flex on the parent, then flex: 0 0 150px on the columns.
* {
margin: 0;
padding: 0;
border: none;
box-sizing: border-box;
}
.container {
width: 100%;
height: 100%;
}
.header {
height: 80px;
position: fixed;
width: 100%;
background: green;
}
.inner-container {
position: absolute;
top: 80px;
left: 0px;
right: 0px;
bottom: 0px;
overflow: auto;
display: flex;
}
.column {
height: 500px;
flex: 0 0 150px;
background: red;
margin: 5px;
}
<div class="container">
<div class="header">
</div>
<div class="inner-container">
<div class="column">
</div>
<div class="column">
</div>
<div class="column">
</div>
</div>
</div>

Div overlay two sibling div who will fill parent

I have 4 div, which look something like this
Desired output:
Current code:
<div class="center aligned" style="width: 100%;height: 7em; padding: 2em; position:absolute;">
<div class="ui small grey label fluid progress_padding_top_bottom" style="z-index:1;height: 7em; border-radius: 0; padding-right: 0; padding-left: 0; background-color: #E8E8E8 !important;">
<div style="background-color: #21BA45; width: 5%; height: 7em; float:left;"></div>
<div style="background-color: #ffdd00; width: 20%; height: 7em; float:left;"></div>
<div style="width: 100%;" class="center aligned">ABC</div>
</div>
Update: This is a part of a progress bar, so both red and yellow width will change
Wrap the colored divs in their own container and position it absolutely unde rthe content.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.wrapper {
width: 50%;
margin: 1em auto;
background: lightgrey;
height: 7em;
display: flex;
justify-content: center;
align-items: center;
position: relative;
font-weight: bold;
}
.content {
position: relative;
z-index: 1;
}
.underlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
.red {
height: 100%;
background: red;
width: 25%;
float: left;
}
.yellow {
height: 100%;
background: yellow;
float: left;
width: 25%;
}
<div class="wrapper">
<div class="content">ABC</div>
<div class="underlay">
<div class="red"></div>
<div class="yellow"></div>
</div>
</div>
This produces what you're trying to putput
https://jsfiddle.net/wcsfnbuL/
<div class="center aligned" style="width: 100%;height: 7em; padding: 2em; position:absolute;">
<div style="background-color: red; width: 15%; height: 7em; float:left; margin: auto;"></div>
<div style="background-color: #ffdd00; width: 15%; height: 7em; text-align: center; vertical-align: middle; line-height: 7em; float:left; margin: auto;">ABC</div>
<div class="ui small grey label fluid progress_padding_top_bottom" style="z-index:1;height: 7em; border-radius: 0; padding-right: 0; padding-left: 0; background-color: #E8E8E8; float: left; width: 15%"></div>
</div>

layout 3 columns and 2 columns height does not match

screenshot
Image size is 100% width.
Trying to make two columns and three columns below.
Fourth and fifth column height does not match the column height.
padding-right 5px must also apply.
a,b,c = image size (224x224)
d = image size (448x224)
e = image size (224x224)
How can I do this?
<div id="box-wrapper">
<div class="box-banner">
<div class="box-button"><img src="/224/random/ffffff"></div>
<div class="box-button"><img src="/224/random/ffffff"></div>
<div class="box-button"><img src="/224/random/ffffff"></div>
</div>
<div class="box-banner-two">
<div class="box-button-two"><img src="/448x224/random/ffffff"></div>
<div class="box-button-two"><img src="/224/random/ffffff"></div>
</div>
</div>
#box-wrapper {
padding-top: 10px !important;
padding-left: 5px !important;
padding-right: 5px !important;
height: 100%;
position: relative;
float: left;
}
.box-banner,
.box-banner-two {
width: 100%;
height: 100%;
position: relative;
float: left;
}
.box-button {
float: left;
width: 32.444%;
margin: 0 5px 5px 0;
}
.box-button img,
.box-button-two img {
width: 100%;
}
.box-banner .box-button:nth-child(3) {
margin-right: 0px;
float: right !important;
}
.box-banner-two .box-button-two:nth-child(1) {
float: left;
width: 64.888%;
margin: 0 5px 5px 0;
}
.box-banner-two .box-button-two:nth-child(2) {
float: right;
width:32.444%;
margin: 0 5px 5px 0;
margin: 0;
}
I modified the html and css posted by you to achieve the same effect. I hope this helps.
Try to avoid important as much as possible.
*, *:after {
box-sizing: border-box;
}
a {
display: block;
text-decoration: none;
background-color: burlywood;
height: 224px;
text-align: center;
line-height: 224px;
}
#box-wrapper {
padding: 10px 5px 0 5px;
height: 100%;
position: relative;
}
.clearfix:after {
display: table;
clear: both;
content: '';
}
.box-button {
float: left;
width: 33.333%;
padding: 0 5px 5px 0;
}
.col-2 {
width: 66.666%;
}
<div id="box-wrapper">
<div class="box-banner clearfix">
<div class="box-button">
A Link
</div>
<div class="box-button">
A Link
</div>
<div class="box-button">
A Link
</div>
</div>
<div class="box-banner clearfix">
<div class="box-button col-2">
A Link
</div>
<div class="box-button">
A Link
</div>
</div>
</div>
Your are over complicating stuff with margin and paddings. The secret here is using box-sizing: border-box. Understand it better here
Apply the box-sizing to the .banner and its childrens
.banner {
box-sizing: border-box;
}
.banner * {
box-sizing: inherit;
}
Also apply to the img the width and padding you need
.banner img {
width: 100%;
}
.banner > * {
padding: 5px;
}
To better help you on layout add col- classes to each img parent
.col1-3 {
width: 33.333%;
}
.col2-3 {
width: 66.666%;
}
The html:
<div class="banner cf">
<div class="col1-3"><img src="http://www.okcourtsidehoops.com/okcourtsidehoops/wp-content/uploads/2013/04/images-21.jpg" /></div>
<div class="col1-3"><img src="http://www.okcourtsidehoops.com/okcourtsidehoops/wp-content/uploads/2013/04/images-21.jpg" /></div>
<div class="col1-3"><img src="http://www.okcourtsidehoops.com/okcourtsidehoops/wp-content/uploads/2013/04/images-21.jpg" /></div>
</div>
<div class="banner cf">
<div class="col2-3"><img src="http://www.amnh.org/var/ezflow_site/storage/images/media/amnh/images/learn-teach/program-images/teacher-programs-images-folder/data-viz-images-folder/data-viz-webinar-image-3/655567-3-eng-US/data-viz-webinar-image-3_imagelarge.jpg" /></div>
<div class="col1-3"><img src="http://www.okcourtsidehoops.com/okcourtsidehoops/wp-content/uploads/2013/04/images-21.jpg" /></div>
</div>
A working example:
http://codepen.io/sandrina-p/pen/PGQKrQ
try this..
#box-wrapper {
padding-top: 10px !important;
padding-left: 5px !important;
padding-right: 5px !important;
height: 100%;
position: relative;
}
.box-banner,
.box-banner-two {
width: 100%;
height: 100%;
position: relative;
float: left;
}
.box-button {
float: left;
width: 32.444%;
margin: 0 5px 5px 0;
}
.box-button img,
.box-button-two img {
width: 100%;
}
.box-banner .box-button:nth-child(3) {
float: right !important;
}
.box-banner-two .box-button-two:nth-child(1) {
float: left;
width: 64.888%;
margin: 0 5px 5px 0;
}
.box-banner-two .box-button-two:nth-child(2) {
float: right;
width:32.444%;
margin: 0 5px 5px 0;
margin: 0;
}
<div id="box-wrapper">
<div class="box-banner">
<div class="box-button"><img src="/224/random/ffffff"></div>
<div class="box-button"><img src="/224/random/ffffff"></div>
<div class="box-button"><img src="/224/random/ffffff"></div>
</div>
<div class="box-banner-two">
<div class="box-button-two"><img src="/448x224/random/ffffff"></div>
<div class="box-button-two"><img src="/224/random/ffffff"></div>
</div>
<div style="clear:both;"></div>
</div>
<div style="clear:both;"></div>

Positioning circle and line together for timeline

I would like to implement timeline part on my website.
I have picture how it should look but I can't think any good way to do it.
How it should look:
Actual code:
js fiddle
<div class="right ">
what should I put here to get that circle?
</div>
Most confusing part is how to get that circle and that line together?
Could anyone suggest anything?
Thank you.
You could use :after, changing the styles to your liking.
.border needs to be positioned non-statically.
.wrapper {
width: 1030px;
background-color: #534741;
height: 500px;
}
.right {
color: #fff;
width: 90%;
text-align: right;
padding: 10px 10px 0 0;
display: block;
}
.border {
border-bottom: 2px solid #000;
width: 50%;
float: right;
margin: 10px 140px 0 10px;
position: relative;
}
.border:after {
/* Position and border */
display: block;
content: '';
border: 2px solid #000;
position: absolute;
width: 32px;
right: -34px; /*** -(Width+Border) ***/
height: 32px;
bottom: -18px; /*** -((Height/2)+Border) ***/
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
}
.text {
float: right;
width: 300px;
margin-right: 90px;
}
<div class="wrapper">
<div class="right">
<h2>Text</h2>
</div>
<div class="right">
<h3>2014</h3>
</div>
<div class="right "></div>
<div class="right border"></div>
<div class="right text">
<p>Lorem ipsum doloremLorem ipsum doloremLorem ipsum doloremLorem ipsum doloremLorem ipsum dolorem</p>
</div>
</div>
JSFiddle
Try to make it with positioning and borer radius. Or simply use images.
.content-wrapper {
position: relative;
width: 400px;
margin-bottom: 30px;
}
.line .circle {
width: 50px;
height: 50px;
border-radius: 25px;
border: 1px solid black;
position: absolute;
top: -25px;
}
.line {
position: relative;
border-bottom: 1px solid black;
}
.odd .line {
margin-right: 50px;
}
.even .line {
margin-left: 50px;
}
.odd .circle {
right: -50px;
}
.even .circle {
left: -50px;
}
.content,
.header {
padding: 0 60px;
}
.odd .content,
.odd .header {
text-align: right;
}
.even .content,
.even .header {
text-align: left;
}
<div class="content-wrapper odd">
<div class="header">Some title</div>
<div class="line">
<div class="circle"></div>
</div>
<div class="content">Loerm ipsum dolerom</div>
</div>
<div class="content-wrapper even">
<div class="header">Some title</div>
<div class="line">
<div class="circle"></div>
</div>
<div class="content">Loerm ipsum dolerom</div>
</div>
Below code should work:
.box-with-circle {
width: 90%;
position: relative;
}
.box-with-circle .circle {
width: 40px;
height: 40px;
position: absolute;
top: 0;
left: 0;
margin -20px 0 0 -20px;
border: 1px solid #000;
background-color: #fff;
z-index: 1;
border-radius: 50%;
}
.box-with-circle hr {
position: relative;
top: 20px;
}
<div class="box-with-circle">
<div class="circle"></div>
<hr />
</div>