How to expand all inline block divs to fill parent? - html

If I have something like this
<div class="A">
<div class="B"></div>
<div class="C"></div>
</div>
css
.B, .C {
display:inline-block;
}
For both B and C, the width wraps it's content and doesn't fill width of A fully. But if I set its width to 100%, then each width is equal to the width of A, which then extends A to twice it's original size in width.
How can I change it so that, the width of B + the width of C = the original width of A.
Basically increase the width of B and C such that it fills the width of A, but keep them inline.
Does anyone know?
Thanks

The best use-case for this would be using Flexbox as you are saying they are dynamic:
.A {border: 1px solid #99f;}
.A div {border: 1px solid #999; height: 10px;}
/* Flex Box */
.A {display: flex;}
.A div {flex: auto;}
Two:
<div class="A">
<div class="B"></div>
<div class="C"></div>
</div>
Three:
<div class="A">
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
</div>
Random:
<div class="A">
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
</div>

Please note that this is not as elegant as Praveen Kumar's answer, but I thought I'd post a table-based answer:
.A {
display: table;
height: 50px;
width: 100%;
border: 2px solid #000;
}
.A > div {
display: table-cell;
border: 1px solid #fff;
background-color: red;
}
Example 1:
<div class="A">
<div class="B"></div>
<div class="C"></div>
</div>
Example 2:
<div class="A">
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
</div>
Example 3:
<div class="A">
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
<div class="E"></div>
<div class="F"></div>
<div class="G"></div>
</div>
Example 4:
<div class="A">
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
<div class="E"></div>
<div class="F"></div>
<div class="G"></div>
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
<div class="E"></div>
<div class="F"></div>
<div class="G"></div>
</div>
Example 5:
<div class="A">
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
<div class="E"></div>
<div class="F"></div>
<div class="G"></div>
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
<div class="E"></div>
<div class="F"></div>
<div class="G"></div>
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
<div class="E"></div>
<div class="F"></div>
<div class="G"></div>
<div class="B"></div>
<div class="C"></div>
<div class="D"></div>
<div class="E"></div>
<div class="F"></div>
<div class="G"></div>
</div>
Again, the amount of children is irrelevant. You can have as many as you require.

Related

How can I select all elements except those inside divs with particular classes

I'd like to find a way to select all the makes of cars except those that are inside a div with the class discontinued or scrapped. Here's my markup:
div:not(.discontinued):not(.scrapped) > .make {
color: green;
}
<div class="car">
<div class="make">NISSAN</div>
<div class="model">MICRA</div>
</div>
<div class="discontinued">
<div class="car">
<div class="make">FORD</div>
<div class="model">MONDEO</div>
</div>
</div>
<div class="scrapped">
<div class="car">
<div class="make">SEAT</div>
<div class="model">IBIZA</div>
</div>
</div>
<div class="scrapped">
<div class="preowned">
<div class="car">
<div class="make">BMW</div>
<div class="model">100</div>
</div>
</div>
</div>
<div class="car">
<div class="make">HONDA</div>
<div class="model">INTEGRA</div>
</div>
</div>
<div class="car">
<div class="make">PEUGEOT</div>
<div class="model">206</div>
</div>
<div class="car">
<div class="make">TOYOTA</div>
<div class="model">COROLLA</div>
</div>
As you can see above, I tried the following:
div:not(.discontinued):not(.scrapped) > .make
...but this still included FORD, SEAT, and BMW.
Unfortunately CSS selectors cannot traverse up parent elements, so if you are just trying to style them differently you may want to reverse your thought process and select ones that are .discontinued or .scrapped and apply overriding styles:
.model {
padding-left: 10px;
}
.make {
color: green;
}
.scrapped .make,
.discontinued .make {
color: red;
}
<div class="car">
<div class="make">NISSAN</div>
<div class="model">MICRA</div>
</div>
<div class="discontinued">
<div class="car">
<div class="make">FORD</div>
<div class="model">MONDEO</div>
</div>
</div>
<div class="scrapped">
<div class="car">
<div class="make">SEAT</div>
<div class="model">IBIZA</div>
</div>
</div>
<div class="scrapped">
<div class="preowned">
<div class="car">
<div class="make">SEAT</div>
<div class="model">IBIZA</div>
</div>
</div>
</div>
<div class="car">
<div class="make">HONDA</div>
<div class="model">INTEGRA</div>
</div>
<div class="car">
<div class="make">PEUGEOT</div>
<div class="model">206</div>
</div>
<div class="car">
<div class="make">TOYOTA</div>
<div class="model">COROLLA</div>
</div>
Why don't you try this style code,
div.make:not(.discontinued .make):not(.scrapped .make) {
color: green;
}

How do I set div like table with different width?

I have div to look like table, this is my code:
.cell {
border: 1px solid red;
display: table-cell
}
.tableLike {
padding-bottom: 30px;
display: table
}
.rowLike {
display: table-row
}
.rowLike .cell:nth-child(1),
.rowLike .cell:nth-child(3) {
width: 15%;
}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
Now all the the columns are in different width, and I don't know why. I want that div get different width but synchronize.
using display:table like this
.tableLike{width:100%;display:table;}
.cell{border:1px solid red;display:table-cell;}
.tableLike {display:table;}
.rowLike{display:table-row;}
.cell{border:1px solid red;display:table-cell;}
.tableLike{padding-bottom: 30px;}
.rowLike .cell:nth-child(1),.rowLike .cell:nth-child(3){ width: 15%;}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
Add the correct display styles:
.cell {
border: 1px solid red;
display: table-cell;
}
.tableLike {
padding-bottom: 30px;
display: table;
}
.rowLike {
display: table-row;
}
.rowLike .cell:nth-child(1),
.rowLike .cell:nth-child(3) {
width: 15%;
}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
.tableLike {display:table;}
.rowLike{display:table-row;}
.cell{border:1px solid red;display:table-cell;}
.tableLike{padding-bottom: 30px;}
.rowLike .cell:nth-child(1),.rowLike .cell:nth-child(3){ width: 33%;}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
I will do like this.
You can try, but it may not be the best answer.
.cell {
border-right:1px solid red;
border-bottom:1px solid red;
display: table-cell
}
.tableLike {
padding-bottom: 30px;
display: table
}
.rowLike {
display: table-row
}
.rowLike .cell:nth-child(1),
.rowLike .cell:nth-child(3) {
width: 15%;
}
.rowLike:nth-child(1) .cell:nth-child(1),
.rowLike:nth-child(1) .cell:nth-child(2),
.rowLike:nth-child(1) .cell:nth-child(3){
border-top:1px solid red;
}
.rowLike:nth-child(1) .cell:nth-child(1),
.icon-close{
border-left:1px solid red;
}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>

Why does Chrome draw two lines where Firefox displays one?

I am trying to make a grid of responsive squares, which would look similar to a squared paper. I used a pre-prepared solution, which I tried to adopt to my purpose. My HTML code looks like this (example grid of 4*4 squares):
.square {
float: left;
position: relative;
width: 25%;
padding-bottom: 25%;
margin: 0%;
overflow: hidden;
}
.content {
position: absolute;
height: 100%;
width: 100%;
padding: 0%;
}
.table {
display: table;
height: 100%;
width: 100%;
padding: 0%;
margin: 0%;
}
.table-cell {
display: table-cell;
vertical-align: middle;
height: 100%;
width: 100%;
padding: 0%;
margin: 0%;
border: thin solid black;
}
<div id="grid">
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
</div>
The grid is OK in Firefox. But when I look at it in Chrome, it displays two lines between second and third row (and between second and third column) instead of one. I tried to set .square background-color to black. It worked partially, but the line in question looks thicker than the others. Is there a batter solution?
There is no proper solution for this. Seems like Chrome rounds off widths on display: table but not on display: block. Slight change of markup produces consistent result:
.square {
float: left;
position: relative;
width: 25%;
padding-bottom: 25%;
margin: 0%;
overflow: hidden;
}
.content {
position: absolute;
height: 100%;
width: 100%;
padding: 0%;
}
.table {
/* removed display table */
height: 100%;
width: 100%;
padding: 0%;
margin: 0%;
}
.table-cell {
/* removed display table-cell */
vertical-align: middle;
height: 100%;
width: 100%;
padding: 0%;
margin: 0%;
border: thin solid black;
/* added */
box-sizing: border-box;
}
<div id="grid">
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
</div>
I guess your problem ist, that you have display:table and thus have double-borders inside yuor table. You can fix that with border-collapse:collapse inside your .table class.
Here's a working fiddle, no more thik lines, noe double borders in chrome: https://jsfiddle.net/Hoargarth/kh7fyegk/
Edit: I forgot to mention, that i also changed border: thin solid black; to border: 1px solid black; inside the fiddle, to remove the thick lines in chrome.
add border-collapse: collapse; in table class
.square {
float:left;
position: relative;
width: 25%;
padding-bottom : 25%;
margin:0%;
overflow:hidden;
}
.content {
position:absolute;
height:100%;
width:100%;
padding: 0%;
}
.table{
display:table;
height:100%;
width:100%;
padding: 0%;
margin: 0%;
border-collapse: collapse;
}
.table-cell{
display:table-cell;
vertical-align:middle;
height:100%;
width:100%;
padding: 0%;
margin: 0%;
border: thin solid black;
}
<div id="grid">
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell"></div>
</div>
</div>
</div>
</div>
If you remove the position: relative from the .square and add the height to .content does it solve your problem ?

Four column layout bootstrap

I got give a jsfiddle that asked the following:
Four Column Layout: Using a Bootstrap class, edit these divs from stacked to a 4 column layout
HTML:
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>
<div class="d"></div>
<div class="c"></div>
<div class="a"></div>
<div class="d"></div>
<div class="b"></div>
CSS:
div{
height: 50px;
min-width: 50px;
}
div.a{
background: #00FF00;
}
div.b{
background: #1234FF;
}
div.c{
background: #FbbF00;
}
div.d{
background: #FF3344;
}
For my answer I did the following:
HTML:
<div class="row-fluid">
<div class="span 3">
<div class="a"></div>
<div class="b"></div>
</div>
<div class="span 3">
<div class="c"></div>
<div class="d"></div>
</div>
<div class="span 3">
<div class="c"></div>
<div class="a"></div>
</div>
<div class="span 3">
<div class="d"></div>
<div class="b"></div>
</div>
CSS:
div{
height: 50px;
min-width: 50px;
display: inline-block;
}
div.a{
background: #00FF00;
}
div.b{
background: #1234FF;
}
div.c{
background: #FbbF00;
}
div.d{
background: #FF3344;
}
But I was told I was wrong with no explanation. Does anyone know how to achieve four stacked columns using bootstrap for the above code?
Here you go with the solution https://jsfiddle.net/yczxm9px/1/
.div{
height: 50px;
}
div.a{
background: #00FF00;
}
div.b{
background: #1234FF;
}
div.c{
background: #FbbF00;
}
div.d{
background: #FF3344;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 div a">
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 div b">
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 div c">
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 div d">
</div>
</div>
</div>
All the class are bootstrap class.
xs for Extra Small Screen
sm for Small Screen
md for Medium Screen
lg for Large Screen.

Struggling to draw a line across a series of divs

Here is my code
http://jsfiddle.net/B8JYN/1/
<style>
html, body {
height: 100%;
padding: 0px;
margin: 0px;
}
#outerdiv {
height: 50%;
width: 99%;
left:1%;
background-color: #000000;
position:absolute;
top:25%;
}
#fretboard {
position:absolute;
width: 100%;
top:5%;
height: 90%;
background-color: red;
}
.stringTitle {
height: 50%;
background-color: #000000;
position:absolute;
top:25%;
width:1%;
background-color: #fff;
}
.string{
height:16.666%
}
.fret{
width:8%;
float:left;
height:100%;
}
.fretEnd{
width:.3%;
background-color:#e7ebea;
float:left;
height:100%;
}
.E1{
background-color:green;
height: 3%;
margin-top: 11%;
}
.B{
background-color:green;
height: 3%;
margin-top: 23.5%;
}
.G{
background-color:green;
height: 3%;
margin-top: 23.5%;
}
.D{
background-color:green;
height: 3%;
margin-top: 23.5%;
}
.A{
background-color:green;
height: 3%;
margin-top: 23.5%;
}
.E2{
background-color:green;
height: 3%;
margin-top: 23.5%;
}
</style>
<div class="stringTitle">
<div class="string">E</div>
<div class="string">B</div>
<div class="string">G</div>
<div class="string">D</div>
<div class="string">A</div>
<div class="string">E</div>
</div>
<div id="outerdiv">
<div id="fretboard">
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fret">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
<div class="fretEnd">
<div class="E1"></div>
<div class="B"></div>
<div class="G"></div>
<div class="D"></div>
<div class="A"></div>
<div class="E2"></div>
</div>
</div>
</div>
I'm trying to get the green lines to be spaced equally in the vertical direction and continuously across from left to right. Hope that makes sense? I'm trying to make this using only percentages rather than specifying px
The percentage based margin-top value is relative to the width, therefore the positioning won't be consistent if the width of the browser is changed.
8 Box model - 8.3 Margin properties
The percentage is calculated with respect to the width of the generated box's containing block. Note that this is true for 'margin-top' and 'margin-bottom' as well. If the containing block's width depends on this element, then the resulting layout is undefined in CSS 2.1.
One solution would be to absolutely position the elements and use a percentage based top value. It's important to relatively position the parent element in order for them to be positioned absolutely relative to the parent, in this case, .fret.
UPDATED EXAMPLE HERE
.E1, .B, .G, .D, .A, .E2 {
position:absolute;
width:100%;
background-color:green;
height: 3%;
}
.E1 {
top:9.6%;
}
.B {
top:26.2%;
}
.G {
top:42.9%;
}
.D {
top:59.6%;
}
.A {
top:76.4%;
}
.E2 {
top:91.2%;
}
Those are just rough estimates. You can of course change the values depending on your needs.