How to create cube window with css? - css

I found this image online and tryed to create these boxes with css. I failed. Has anyone an idea how to solve this problem?
This is my code. The problem is the left bar:
.box {
position: relative;
margin: 10px;
display: inline-block;
}
.content {
border-top: 2px solid red;
border-right: 2px solid red;
padding: 5px;
}
.box:before {
content: '';
position: absolute;
top: 0;
left: -10px;
height: 100%;
width: 10px;
background-color: red;
transform: skew(-45deg) rotate(-45deg);
}
.box:after {
content: '';
position: absolute;
bottom: -10px;
left: -5px;
height: 10px;
width: 100%;
background-color: red;
transform: skew(-45deg);
}
<div class="box">
<div class="content">
CONTENT<br />
Some more content
</div>
</div>

border-image with linear-gradient can do it:
.box {
margin: 10px;
display: inline-block;
border-style:solid;
border-width:2px 2px 15px 15px;
border-image-slice:2 2 15 15; /* same as border-width*/
border-image-source:linear-gradient(-45deg,transparent 9px,red 0 calc(100% - 9px),transparent 0);
}
.content {
padding: 5px;
}
<div class="box">
<div class="content">
CONTENT<br> Some more Content
</div>
</div>
<div class="box">
<div class="content">
CONTENT<br> more Content
</div>
</div>
<div class="box">
<div class="content">
AA BB
</div>
</div>
With CSS variables to have better control:
.box {
--b:2; /* border length (without unit!!)*/
--c:15; /* the cube perspective (without unit!!)*/
--g:calc((var(--c) - var(--b))*0.707px); /* 0.707 = cos(45deg) = sin(45deg) */
margin: 10px;
display: inline-block;
border-style:solid;
border-width:calc(var(--b)*1px) calc(var(--b)*1px) calc(var(--c)*1px) calc(var(--c)*1px);
border-image-slice:var(--b) var(--b) var(--c) var(--c);
border-image-source:linear-gradient(-45deg,transparent var(--g),red 0 calc(100% - var(--g)),transparent 0);
}
.content {
padding: 5px;
}
<div class="box">
<div class="content">
CONTENT<br> Some more Content
</div>
</div>
<div class="box" style="--b:3;--c:10">
<div class="content">
CONTENT<br> more Content
</div>
</div>
<div class="box" style="--b:1;--c:20">
<div class="content">
AA BB
</div>
</div>
<div class="box" style="--b:1;--c:5">
<div class="content">
AA BB
</div>
</div>
You can also have it in any direction you want:
.box {
--b:2; /* border length (without unit!!)*/
--c:15; /* the cube perspective (without unit!!)*/
--g:calc((var(--c) - var(--b))*0.707px); /* 0.707 = cos(45deg) = sin(45deg) */
margin: 10px;
display: inline-block;
border-style:solid;
}
.bottom-left {
border-width:calc(var(--b)*1px) calc(var(--b)*1px) calc(var(--c)*1px) calc(var(--c)*1px);
border-image-slice:var(--b) var(--b) var(--c) var(--c);
border-image-source:linear-gradient(-45deg,transparent var(--g),red 0 calc(100% - var(--g)),transparent 0);
}
.top-right {
border-width:calc(var(--c)*1px) calc(var(--c)*1px) calc(var(--b)*1px) calc(var(--b)*1px) ;
border-image-slice: var(--c) var(--c) var(--b) var(--b);
border-image-source:linear-gradient(-45deg,transparent var(--g),red 0 calc(100% - var(--g)),transparent 0);
}
.top-left {
border-width:calc(var(--c)*1px) calc(var(--b)*1px) calc(var(--b)*1px) calc(var(--c)*1px) ;
border-image-slice:var(--c) var(--b) var(--b) var(--c);
border-image-source:linear-gradient(45deg,transparent var(--g),red 0 calc(100% - var(--g)),transparent 0);
}
.bottom-right {
border-width:calc(var(--b)*1px) calc(var(--c)*1px) calc(var(--c)*1px) calc(var(--b)*1px) ;
border-image-slice:var(--b) var(--c) var(--c) var(--b);
border-image-source:linear-gradient(45deg,transparent var(--g),red 0 calc(100% - var(--g)),transparent 0);
}
.content {
padding: 5px;
}
<div class="box bottom-left">
<div class="content">
CONTENT<br> Some more Content
</div>
</div>
<div class="box top-right" style="--b:3;--c:10">
<div class="content">
CONTENT<br> more Content
</div>
</div>
<div class="box bottom-right" style="--b:1;--c:20">
<div class="content">
AA BB
</div>
</div>
<div class="box top-left" style="--b:1;--c:5">
<div class="content">
AA BB
</div>
</div>
We can also add more 3D effect by adjusting the coloration and using a different technique with clip-path
.box {
--b:2px; /* border length*/
--c:15px; /* the cube perspective */
--g:calc(var(--c)*0.707); /* 0.707 = cos(45deg) = sin(45deg) */
margin: 10px;
display: inline-block;
padding:var(--b) var(--b) var(--c) var(--c);
background:
linear-gradient(-45deg,transparent var(--g),#cc0404 0) left /var(--c) 100%,
linear-gradient(135deg,transparent var(--g),red 0) bottom /100% var(--c),
linear-gradient(red,red) top /100% var(--b),
linear-gradient(red,red) right /var(--b) 100%;
background-repeat:no-repeat;
clip-path:
polygon(0% calc(var(--c) - var(--b)), calc(var(--c) - var(--b)) 0%,
100% 0%,
100% calc(100% - var(--c) + var(--b)), calc(100% - var(--c) + var(--b)) 100%,
0% 100%);
}
.content {
padding: 5px;
}
<div class="box">
<div class="content">
CONTENT<br> Some more Content
</div>
</div>
<div class="box" style="--b:3px;--c:10px">
<div class="content">
CONTENT<br> more Content
</div>
</div>
<div class="box" style="--b:1px;--c:20px">
<div class="content">
AA BB
</div>
</div>
<div class="box" style="--b:1px;--c:5px">
<div class="content">
AA BB
</div>
</div>
A Codepen demo to play with the code

One way to achieve this effect is to use a ::before pseudo-element with a clip-path applied to it.
In the example below, I have repeatedly used the values 10px and 2px though these could straightforwardly be replaced with CSS Custom Properties such as:
:root {
--cube-depth: 10px;
--cube-border: 2px;
}
and then used throughout the stylesheet as var(--cube-depth) and var(--cube-border).
Working Example:
.cube {
position: relative;
float: left;
margin: 0 4px 8px 4px;
padding: 2px 2px calc(2px + 10px) calc(2px + 10px);
color: rgb(237, 62, 68);
box-sizing: border-box;
}
.cube::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgb(237, 62, 68);
clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px, 10px 0, 10px calc(100% - 10px), calc(100% - 2px) calc(100% - 10px), calc(100% - 2px) 2px, 10px 2px);
}
.size-80x100 {
width: calc(100px + 10px);
height: calc(80px + 10px);
}
.size-80x200 {
width: calc(200px + 10px);
height: calc(80px + 10px);
}
.size-80x360 {
width: calc(360px + 10px);
height: calc(80px + 10px);
}
.size-80x440 {
width: calc(440px + 10px);
height: calc(80px + 10px);
}
<div class="cube size-80x100">80 x 100</div>
<div class="cube size-80x440">80 x 440</div>
<div class="cube size-80x360">80 x 360</div>
<div class="cube size-80x200">80 x 200</div>

Related

coloring percentage part of an annulus [duplicate]

I've found pretty nice "percent pie chart" and want to create it with CSS only. No animation is required. Just static "picture".
I understand If I wanna create this kind of chart I need to use elements like these
The questions are
How to create element #2 ?
How to manage shape of element #2 for smaller (5%) or higher percent (80%) values ?
New answer 2021
With some modern techniques we can improve the code. You can have rounded edges and also consider animation:
#property --p{
syntax: '<number>';
inherits: true;
initial-value: 1;
}
.pie {
--p:20; /* the percentage */
--b:22px; /* the thickness */
--c:darkred; /* the color */
--w:150px; /* the size*/
width:var(--w);
aspect-ratio:1/1;
position:relative;
display:inline-grid;
margin:5px;
place-content:center;
font-size:25px;
font-weight:bold;
font-family:sans-serif;
}
.pie:before,
.pie:after {
content:"";
position:absolute;
border-radius:50%;
}
.pie:before {
inset:0;
background:
radial-gradient(farthest-side,var(--c) 98%,#0000) top/var(--b) var(--b) no-repeat,
conic-gradient(var(--c) calc(var(--p)*1%),#0000 0);
-webkit-mask:radial-gradient(farthest-side,#0000 calc(99% - var(--b)),#000 calc(100% - var(--b)));
mask:radial-gradient(farthest-side,#0000 calc(99% - var(--b)),#000 calc(100% - var(--b)));
}
.pie:after {
inset:calc(50% - var(--b)/2);
background:var(--c);
transform:rotate(calc(var(--p)*3.6deg - 90deg)) translate(calc(var(--w)/2 - 50%));
}
.animate {
animation:p 1s .5s both;
}
.no-round:before {
background-size:0 0,auto;
}
.no-round:after {
content:none;
}
#keyframes p{
from{--p:0;}
}
body {
background:#ddd;
}
<div class="pie" style="--p:20"> 20%</div>
<div class="pie" style="--p:40;--c:darkblue;--b:10px"> 40%</div>
<div class="pie no-round" style="--p:60;--c:purple;--b:15px"> 60%</div>
<div class="pie animate" style="--p:80;--c:orange;"> 80%</div>
<div class="pie animate no-round" style="--p:90;--c:lightgreen"> 90%</div>
Old answer
You can do this with multiple background.
From 0% to 50%:
.box {
width: 100px;
height: 100px;
display: inline-block;
border-radius: 50%;
padding: 5px;
background:
linear-gradient(#ccc, #ccc) content-box,
linear-gradient(var(--v), #f2f2f2 50%, transparent 0),
linear-gradient(to right, #f2f2f2 50%, blue 0);
}
<div class="box" style="--v:-90deg"></div><!-- 0% -->
<div class="box" style="--v:-45deg"></div><!-- 12.5% -->
<div class="box" style="--v: 0deg"></div><!-- 25% -->
<div class="box" style="--v: 45deg"></div><!-- 37.5% -->
<div class="box" style="--v: 90deg"></div><!-- 50% -->
<p>The formula is [p = (18/5) * x - 90]. <small>Where x is the percentage and p the degree</small></p>
<p>for x = 5% --> p = -72deg </p>
<div class="box" style="--v:-72deg"></div>
From 50% to 100%:
.box {
width:100px;
height:100px;
display:inline-block;
border-radius:50%;
padding:5px;
background:
linear-gradient(#ccc,#ccc) content-box,
linear-gradient(var(--v), blue 50%,transparent 0),
linear-gradient(to right, #f2f2f2 50%,blue 0);
}
<div class="box" style="--v:-90deg"></div><!-- 50% -->
<div class="box" style="--v:-45deg"></div><!-- 62.5% -->
<div class="box" style="--v: 0deg"></div><!-- 75% -->
<div class="box" style="--v: 45deg"></div><!-- 87.5% -->
<div class="box" style="--v: 90deg"></div><!-- 100% -->
<p>The formula is [p = (18/5) * x - 270]. <small>Where x is the percentage and p the degree</small></p>
<p>for x = 80% --> p = 18deg </p>
<div class="box" style="--v:18deg"></div>
You can combine both like this:
.box {
width:100px;
height:100px;
display:inline-block;
border-radius:50%;
padding:5px;
background:
linear-gradient(#ccc,#ccc) content-box,
linear-gradient(var(--v), #f2f2f2 50%,transparent 0) 0/calc(var(--s)*100%) ,
linear-gradient(var(--v), blue 50%,transparent 0) 0/calc((1 - var(--s))*100%),
linear-gradient(to right, #f2f2f2 50%,blue 0);
}
<div class="box" style="--v:-90deg;--s:1"></div>
<div class="box" style="--v:0deg;--s:1"></div>
<div class="box" style="--v:90deg;--s:1"></div>
<div class="box" style="--v:0deg;--s:0"></div>
<div class="box" style="--v:90deg;--s:0"></div>
Now we can optimize like below to consider percetange value:
.box {
--v:calc( ((18/5) * var(--p) - 90)*1deg);
width:100px;
height:100px;
display:inline-block;
border-radius:50%;
padding:10px;
background:
linear-gradient(#ccc,#ccc) content-box,
linear-gradient(var(--v), #f2f2f2 50%,transparent 0) 0/min(100%,(50 - var(--p))*100%),
linear-gradient(var(--v), transparent 50%,blue 0) 0/min(100%,(var(--p) - 50)*100%),
linear-gradient(to right, #f2f2f2 50%,blue 0);
}
<div class="box" style="--p:5;"></div>
<div class="box" style="--p:20;"></div>
<div class="box" style="--p:50;"></div>
<div class="box" style="--p:60;"></div>
<div class="box" style="--p:75;"></div>
<div class="box" style="--p:100;"></div>
Related question to get another version: Creating a static pie chart with CSS
We can also consider mask to add transparency:
.box {
--v:calc( ((18/5) * var(--p) - 90)*1deg);
width:100px;
height:100px;
display:inline-block;
border-radius:50%;
padding:10px;
background:
linear-gradient(var(--v), #f2f2f2 50%,transparent 0) 0/min(100%,(50 - var(--p))*100%),
linear-gradient(var(--v), transparent 50%,blue 0) 0/min(100%,(var(--p) - 50)*100%),
linear-gradient(to right, #f2f2f2 50%,blue 0);
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite:destination-out;
mask-composite:exclude;
}
body {
background:linear-gradient(to right,red,yellow);
}
<div class="box" style="--p:5;"></div>
<div class="box" style="--p:20;"></div>
<div class="box" style="--p:50;"></div>
<div class="box" style="--p:60;"></div>
<div class="box" style="--p:75;"></div>
<div class="box" style="--p:100;"></div>
Also like below:
.box {
--v:calc( ((18/5) * var(--p) - 90)*1deg);
width:100px;
height:100px;
display:inline-block;
border-radius:50%;
padding:10px;
background:
linear-gradient(var(--v), transparent 50%,blue 0) 0/min(100%,(var(--p) - 50)*100%),
linear-gradient(to right, transparent 50%,blue 0);
-webkit-mask:
linear-gradient(var(--v), #f2f2f2 50%,transparent 0) 0/min(100%,(50 - var(--p))*100%),
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite:destination-out;
mask-composite:exclude;
}
body {
background:linear-gradient(to right,red,yellow);
}
<div class="box" style="--p:5;"></div>
<div class="box" style="--p:20;"></div>
<div class="box" style="--p:50;"></div>
<div class="box" style="--p:60;"></div>
<div class="box" style="--p:75;"></div>
<div class="box" style="--p:100;"></div>
Related: Border Gradient with Border Radius
Using the new conic gradient, this can be managed with a single div which just landed in Chrome as an experimental property.
Image of Result
:root {
--size: 100px;
--bord: 10px;
}
.chart {
width: var(--size);
height: var(--size);
margin: 1em auto;
border-radius: 50%;
background-image: conic-gradient(lightseagreen var(--value), lightgrey var(--value));
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.chart::after {
content: "";
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: calc(100% - var(--bord));
height: calc(100% - var(--bord));
background: white;
border-radius: inherit;
}
p {
position: relative;
z-index: 1;
font-size: 2em;
}
.x-60 {
--value: 60%;
}
.x-20 {
--value: 20%;
}
<div class="chart x-60">
<p>60%</p>
</div>
<div class="chart x-20">
<p>20%</p>
</div>
With thanks for Temani Afif it's possible to achieve this without the pseudo element using a border and leveraging background-clip...
background:
linear-gradient(white,white) padding-box,
conic-gradient(lightseagreen var(--value), lightgrey var(--value)) border-box;
:root {
--size: 100px;
--bord: 10px;
}
.chart {
width: var(--size);
height: var(--size);
margin: 1em auto;
border: var(--bord) solid transparent;
border-radius: 50%;
background: linear-gradient(white, white) padding-box, conic-gradient(lightseagreen var(--value), lightgrey var(--value)) border-box;
position: relative;
display: flex;
justify-content: center;
align-items: center;
font-size: 2em;
}
.x-60 {
--value: 60%;
}
.x-20 {
--value: 20%;
}
<div class="chart x-60">
<p>60%</p>
</div>
<div class="chart x-20">
<p>20%</p>
</div>
Hey gus you can add small CSS styles
.circle {
position: relative;
top: 5px;
left: 5px;
text-align: center;
width: 100px;
height: 100px;
border-radius: 100%;
background-color: #ffffff;
}
.circle-border {
position: relative;
text-align: center;
width: 110px;
height: 110px;
margin-left: 30%;
border-radius: 100%;
background-color: #E53B3B;
background: linear-gradient(0deg, lightgray 100%, black 0%)
}
HTML
<div class="circle-border" id="circleElement">
<div class="circle" id="circleElementValue">
aaa
</div>
</div>
JS : display the % of filling automatically
// let i = 75;
// let deg=Math.round(1.8*i);
// let completed=0;
// let remaining=100-i;
// // completed = (remaining>50)? 50 : completed;
// let backgroundStlye = 'linear-gradient('+deg+'deg, lightgray '+remaining +'%, black '+completed + '%)';
// setTimeout(function(){
// console.log(backgroundStlye);
// document.getElementById("circleElement").style.background =backgroundStlye;
// },i*100);
for(let i=1;i<=100;i++){
let deg=Math.round(1.8*i);
let completed=i;
let remaining=100-i;
completed = (remaining<50)? 0 : completed;
let backgroundStlye = 'linear-gradient('+deg+'deg, lightgray '+remaining +'%, black '+completed + '%)';
setTimeout(function(){
console.log(backgroundStlye);
document.getElementById("circleElement").style.background =backgroundStlye;
document.getElementById("circleElementValue").innerHTML = i+'%';
},i*100);
}
I created sample https://codepen.io/arun-b-shet/pen/mdVVWXo
HOPE you enjoyyyyyyyyyyyy

place 2 inline columns vertically to middle of background

you can help me with UIkit or css manually!
i am using UIkit framework and the problem is that i really don't understand how to place two inline columns at middle of background(vertically)!
here is screenshot what i have, i think then you will understand my problem]1
this is code of this section with columns:
<section id="header" class="gradient bg bg-gradient ">
<div uk-grid style="margin: 0 auto;" class="uk-flex uk-flex-middle uk-flex-space-between uk-grid-item-match">
<div class="uk-width-3-5#m">
<div class="uk-flex-inline">
<hr class="uk-divider-small">
<p>DISTRIBUTED LEDGER TECHNOLOGY</p>
</div>
<p>
<h1><span style="color: #6d6d6d">BRINGING</span> <span style="color: white">A GOLD STANDART TO THE</span>
<span style="color: rgba(4,149,247,1);">BLOCKCHAIN</span></h1></p>
</div>
<div class="uk-width-expand#m uk-flex">
<video loop muted playsinline uk-video="autoplay: inview">
<source src="https://quirksmode.org/html5/videos/big_buck_bunny.mp4" type="video/mp4">
<source src="https://quirksmode.org/html5/videos/big_buck_bunny.ogv" type="video/ogg">
</video>
</div>
</div>
</section>
here is my main.css
.gradient {
height: 900px;
width: 100%;
background: linear-gradient(180deg, #092436 0%, rgba(13, 17, 22, 0) 100%);
box-shadow: 0 2px 4px 0 rgba(255, 255, 255, 0.12);
}
.bg {
height: 900px;
width: 100%;
background-color: #0D1116;
box-shadow: 0 2px 4px 0 rgba(255, 255, 255, 0.12);
}
.bg-gradient{
position:absolute;
top:0px;
z-index: -1;
}
.thin-text{
font-weight: 200;
}
html,body{
letter-spacing: 2px;
}
.uk-button-text {
letter-spacing: 2px;
padding:5px;
}
.uk-navbar{
border-bottom: 1px solid rgba(4,149,247,0.1);
}
.hover{
transition: 0.3s;
}
.hover:hover{
background-color: rgba(4,149,247,0.1);
}
.padding-header {
padding: 200px 100px 100px 100px;
}
my 2 columns are inside .bg and .gradient!
<section id="header" class="gradient bg bg-gradient uk-flex">
<div class="uk-margin-auto uk-margin-auto-vertical">
<div uk-grid>
</div>
</div>
</section>
You can use the following solution to place two inline columns vertically in the middle of the background:
.uk-width-expand#m {
margin: 0 auto;
}

CSS - Div Not Centering [duplicate]

This question already has answers here:
CSS center display inline block?
(9 answers)
Closed 5 years ago.
body {
background: #212121;
}
.wrapper {
height: 100%;
width: 100%;
overflow: hidden;
}
.holder{
height: 50%;
width: 100%;
position: absolute;
top: 25%;
left: 0%;
}
.content {
height: 100%;
width: 400px;
margin: 10px;
display: inline-block;
background: #424242;
-webkit-box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 1);
-moz-box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 1);
box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 1);
}
.detailBox {
height: 100%;
display: inline-block;
font-size: 0;
margin: 0 auto;
}
<div class="wrapper">
<div class="holder">
<div class="detailBox">
<div class="content" id="row1">
<div class="wordInputContainer">
<div class="inputBox">
</div>
</div>
</div>
<div class="content" id="row2">
<div class="wordOutputContainer">
<div class="listBox">
<!-- List Elements Go Here -->
<!-- Words Output In Alphabetical Order [A - Z] -->
</div>
</div>
</div>
<div class="content" id="row3">
<div class="wordStatisticContainer">
<div class="wordCount"></div>
<div class="commonLetter"></div>
<div class="commonWord"></div>
<div class="longestWord"></div>
<div class="shortestWord"></div>
</div>
</div>
</div>
</div>
</div>
Even though I have margin: 0 auto; on the .detailedBox it still isn't centering. Is it because it doesn't have a fix width? It doesn't have a fixed width because I want the .detailedBox to be the width of all the .content's combined, but also centered.
If you change .detailBox to have display: flex (instead of inline-block) and then do justify-content: center then it'll center that div horizontally.
Since .detailBox is set to inline-block, it cannot be centered by using margin:0 auto. One way to understand this is that the "margin centering" technique relies on "filling up" available horizontal space. But there is no available space when using an inline element. (Reference: margin:auto; with inline-block.)
Also note that:
10.3.9 'Inline-block', non-replaced elements in normal flow
If 'width' is 'auto', the used value is the shrink-to-fit width as for floating elements.
A computed value of 'auto' for 'margin-left' or 'margin-right' becomes a used value of '0'.
— w3.org
One alternative is to let .detailBox default to display:block and set text-align:center to horizontally center it's child .content elements, which are inline-block.
body {
background: #212121;
}
.wrapper {
height: 100%;
width: 100%;
overflow: hidden;
}
.holder {
height: 50%;
width: 100%;
position: absolute;
top: 25%;
left: 0%;
}
.content {
height: 100%;
width: 100px;
margin: 10px;
display: inline-block;
background: #424242;
-webkit-box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 1);
-moz-box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 1);
box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 1);
}
.detailBox {
height: 100%;
font-size: 0;
text-align:center;
}
<div class="wrapper">
<div class="holder">
<div class="detailBox">
<div class="content" id="row1">
<div class="wordInputContainer">
<div class="inputBox">
</div>
</div>
</div>
<div class="content" id="row2">
<div class="wordOutputContainer">
<div class="listBox">
<!-- List Elements Go Here -->
<!-- Words Output In Alphabetical Order [A - Z] -->
</div>
</div>
</div>
<div class="content" id="row3">
<div class="wordStatisticContainer">
<div class="wordCount"></div>
<div class="commonLetter"></div>
<div class="commonWord"></div>
<div class="longestWord"></div>
<div class="shortestWord"></div>
</div>
</div>
</div>
</div>
</div>
You mentioned that you want .detailBox to be the width of all the content combined. So, if for some reason you need .detailBox to remain inline-block, you could set text-align:center on it's parent, .holder. Like this:
body {
background: #212121;
}
.wrapper {
height: 100%;
width: 100%;
overflow: hidden;
}
.holder {
height: 50%;
width: 100%;
position: absolute;
top: 25%;
left: 0%;
text-align:center;
}
.content {
height: 100%;
width: 100px;
margin: 10px;
display: inline-block;
background: #424242;
-webkit-box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 1);
-moz-box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 1);
box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 1);
}
.detailBox {
height: 100%;
display:inline-block;
font-size: 0;
}
<div class="wrapper">
<div class="holder">
<div class="detailBox">
<div class="content" id="row1">
<div class="wordInputContainer">
<div class="inputBox">
</div>
</div>
</div>
<div class="content" id="row2">
<div class="wordOutputContainer">
<div class="listBox">
<!-- List Elements Go Here -->
<!-- Words Output In Alphabetical Order [A - Z] -->
</div>
</div>
</div>
<div class="content" id="row3">
<div class="wordStatisticContainer">
<div class="wordCount"></div>
<div class="commonLetter"></div>
<div class="commonWord"></div>
<div class="longestWord"></div>
<div class="shortestWord"></div>
</div>
</div>
</div>
</div>
</div>

Length of <p> element changing position of parent?

I currently have a set of 'product' divs inside a wrapping containers. These product divs contain an image, header and p text. For some reason, the length of the p text is changing the position of the parent product div. Here is a screenshot: https://gyazo.com/9504729541e6bee17a27e4121af3a1c9
The p and h2 elements both have 0 padding and margins.
I will try to keep my code as minimal as possible.
HTML:
<div id="content" class="wrapper">
<div id="content-container">
<div id="product-container">
<div class="product-wrapper">
<div id="product" class="unhidden">
<div class="image-container">
<img src="assets/home-bg.jpg" class="thumbnail">
</div>
<div class="product-text">
<h2>Mexican Nachos - £6.99</h2>
<p>Tortilla chips and melted cheese with the option of salsa, jalapenos, ground meat, guacamole and tomatoes.</p>
</div>
</div>
<div id="product" class="unhidden">
<div class="image-container">
<img src="assets/enchilada.jpg" class="thumbnail">
</div>
<div class="product-text">
<h2>Enchiladas - £10.99</h2>
<p>Tortilla chips and melted cheese with the option of salsa, jalapenos, ground meat, guacamole and tomatoes.</p>
</div>
</div>
<div id="product" class="unhidden">
<div class="image-container">
<img src="assets/quesadilla.jpg" class="thumbnail">
</div>
<div class="product-text">
<h2>Quesadilla - £4.99</h2>
<p>Shorter length test</p>
</div>
</div>
<div id="product" class="unhidden">
<div class="image-container">
<img src="assets/shrimp.jpg" class="thumbnail">
</div>
<div class="product-text">
<h2>Shrimp Stir Fry - £10.99</h2>
</div>
</div>
</div>
</div> <!-- Product container -->
</div> <!-- Content container -->
</div> <!-- Content-wrapper container -->
CSS:
#content {
height: 100%;
padding-top: 100px;
}
.wrapper {
width: 65%;
margin: 0 auto;
}
#content-container {
display: inline-block;
width: 100%;
height: 100%;
background-color: white;
box-shadow: -20px 0px 25px -20px #000000, 20px 0px 25px -20px #000000;
overflow: scroll;
}
#product-container {
width: 100%;
height: 100%;
padding-top: 25px;
}
.product-wrapper {
width: 80%;
height: 100%;
margin: 0px auto;
text-align: center;
}
#product {
display: inline-block;
height: 352px;
width: 200px;
margin: 10px;
border: solid 2px black;
}
.image-container {
height: 200px;
width: 200px;
}
.product-text {
font-family: 'Open Sans Condensed';
height: 150px;
width: 100%;
text-align: center;
color: black;
border-top: solid 2px black;
background: #FFFFFF; /* Old browsers */
background: -moz-linear-gradient(top, #009641 0%, #a1d54f 96%, #80c217 100%, #7cbc0a 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, #009641 0%,#a1d54f 96%,#80c217 100%,#7cbc0a 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #009641 0%,#a1d54f 96%,#80c217 100%,#7cbc0a 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
}
.product-text h2 {
font-size: 23px;
padding: 0;
margin: 0;
}
.product-text p {
font-style: italic;
font-weight: 700;
padding: 0;
margin: 0;
}
.thumbnail {
position: relative;
height: 200px;
width: 200px;
cursor: pointer;
z-index: 1200;
}
Your #product elements are display: inline-block. This means they will take inline level characteristics, one of which is baseline alignment (i.e., vertical-align: baseline).
Override the default setting with vertical-align: top.
(Also, you have multiple elements with id="product". ID values should be unique on a page. Consider switching to class="product" instead.)
add vertical-align:top to #product.
#product {
display: inline-block;
height: 352px;
width: 200px;
vertical-align: top;
margin: 10px;
border: solid 2px black;
}
And one more thing, its not a best practice to have same id's for different elements. Instead make it .product class.

Apply gradient to bottom of container if height is greater than X pixels

Note: I am not simply asking how to put a gradient to the bottom of a div. I'm asking how to only show the gradient if the div is greater than a certain height.
I currently have this:
https://jsfiddle.net/fwtj44bj/3/
I want to apply this gradient to the bottom of any .container that is great than 100px in height:
http://www.colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&0+0,1+100
Meaning that the second row of the first .container should have the gradient over the boxes, but the second .container should have no gradient.
How can this be done?
My thinking is to somehow make use of max-height, but I'm not sure how.
HTML:
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
CSS:
.container {
width: 332px;
margin-bottom: 48px;
}
.box {
width: 100px;
height: 100px;
display: inline-block;
background: red;
margin-right: 8px;
}
You need javascript to get the height of div. after that you can set a class that will add gradient.
If you want gradient over boxes then we use ::after pseudo class.
have a look please
var heights = document.getElementsByClassName('container');
for (var i = 0; i < heights.length; i++) {
var height = heights[i].offsetHeight;
if(height > 104){
heights[i].className += " gradient";
}
}
.container {
width: 332px;
margin-bottom: 48px;
padding:0px;
position:relative;
}
.box {
width: 100px;
height: 100px;
display: inline-block;
background: red;
margin-right: 8px;
}
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&0+0,1+100 */
.gradient::after{
display:inline-block;
position:absolute;
z-index:999;
bottom:0px;
left:0px;
width:100%;
height:100%;
content:' ';
background: -moz-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */
}
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
Without javascript. Use :after selector.Position your container as relative and then offset the :after element by 100px.
.container {
width: 332px;
margin-bottom: 48px;
position: relative;
}
.box {
width: 100px;
height: 100px;
display: inline-block;
background: red;
margin-right: 8px;
}
.container:after {
content: '';
position: absolute;
top: 100px;
left:0;
right: 0;
bottom: 0;
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%);
}
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
If you add jQuery to your project you can do this by adding a css class after checking each .container div's height.
https://jsfiddle.net/fwtj44bj/5/
$(".container").each(function(){
if ($(this).height() > 100) {
$(this).addClass("gradient");
}
});
Edit
I edited my answer so the pseudo element have height:calc(100% - 100px); instead of just height:100%, this way you don't need to have overflow:hidden on .container
How about this: check fiddle
.container{
width: 332px;
margin-bottom: 48px;
position:relative;
}
.container:after{
content:' ';
position:absolute;
bottom:0px;
width:100%;
height:calc(100% - 100px);
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(255,0,255,1) 100%);
}
Obvious limitations: .container should have position:relative and overflow:hidden.

Resources