I am making a simple gauge meter which has minimum and maximum value as 0 and 2 respectively.
I am able to achieve the UI so far like,
.sc-gauge { width:200px; height:200px; margin:200px auto; }
.sc-background { position:relative; height:100px; margin-bottom:10px; background-color:gray; border-radius:150px 150px 0 0; overflow:hidden; text-align:center; }
.sc-mask { position:absolute; top:20px; right:20px; left:20px; height:80px; background-color:#fff; border-radius:150px 150px 0 0 }
.sc-percentage { position:absolute; top:100px; left:-200%; width:400%; height:400%; margin-left:100px; background-color:#00aeef; }
.sc-percentage { transform:rotate(70deg); transform-origin:top center; }
.sc-min { float:left; }
.sc-max { float:right; }
.sc-avg {position: absolute; top: 75%;left: 50%;}
.sc-value { position:absolute; top:50%; left:0; width:100%; font-size:48px; font-weight:700 }
<div class="sc-gauge">
<div class="sc-background">
<div class="sc-percentage"></div>
<div class="sc-mask"></div>
<span class="sc-value">0.7 gb</span>
</div>
<span class="sc-min">0</span>
<span class="sc-avg">1</span>
<span class="sc-max">2</span>
</div>
But the expected output needs to be like this,
The pending UI includes,
-> Placing of 0 and 2 exactly at the left beginning and and right ending of the chart.
-> Making small line in left, top and right of the chart.
-> Placing number 1 at top center of the chart..
If my points are unclear then kindly refer the attached image for exact UI.
Things I have tried to make the number 0 and 2 to left and right like image is,
.sc-percentage {
position: relative;
}
.sc-min {
position: absolute;
left: 0;
}
.sc-max {
position: absolute;
left: 0;
}
To make the line at top of the chart and to place number 1 there, I have tried,
.sc-avg {position: absolute; top: 75%;left: 50%;}
But this doesn't work the way as expected ..
I am stuck with this css work for long time.. Please kindly help me to achieve the the exact UI like in the given image.
Try this:
(You can adjust the position in the top and left/right css properties)
.sc-gauge {
width:200px;
height:200px;
margin:200px auto;
}
.sc-background {
position:relative;
height:100px;
margin-bottom:10px;
background-color:gray;
border-radius:150px 150px 0 0;
overflow:hidden;
text-align:center;
}
.sc-mask {
position:absolute;
top:20px;
right:20px;
left:20px;
height:80px;
background-color:#fff;
border-radius:150px 150px 0 0
}
.sc-percentage {
position:absolute;
top:100px;
left:-200%;
width:400%;
height:400%;
margin-left:100px;
background-color:#00aeef;
}
.sc-percentage {
transform:rotate(70deg);
transform-origin:top center;
}
.sc-min {
position: relative;
top:-13%;
left: -7%;
font-size: 12px;
color: gray;
}
.line-min{
color: #00aeef;
}
.sc-max {
position: relative;
top: -13%;
left: 82%;
font-size: 12px;
color: gray;
}
.line-max{
color: gray;
}
.sc-avg {
position: relative;
top: -68%;
left: 41%;
font-size: 12px;
color: gray;
}
.line-avg {
position: relative;
top: -59%;
right: -37%;
color: gray;
}
.sc-value {
position:absolute;
top:50%;
left:0;
width:100%;
font-size:38px;
font-weight:700;
}
<div class="sc-gauge">
<div class="sc-background">
<div class="sc-percentage"></div>
<div class="sc-mask"></div>
<span class="sc-value">0.7 gb</span>
</div>
<span class="sc-min">0
<span class="line-min">_</span>
</span>
<span class="sc-avg">1</span>
<span class="line-avg">|</span>
<span class="sc-max">
<span class="line-max">_</span> 2</span>
</div>
Is this what you want buddy?
.sc-gauge {
position: relative;
width: 200px;
height: 200px;
margin: 200px auto;
}
.sc-background {
position: relative;
height: 100px;
margin-bottom: 10px;
background-color: gray;
border-radius: 150px 150px 0 0;
overflow: hidden;
text-align: center;
}
.sc-mask {
position: absolute;
top: 20px;
right: 20px;
left: 20px;
height: 80px;
background-color: #fff;
border-radius: 150px 150px 0 0;
}
.sc-percentage {
position: absolute;
top: 100px;
left: -200%;
width: 400%;
height: 400%;
margin-left: 100px;
background-color: #00aeef;
}
.sc-percentage {
transform: rotate(70deg);
transform-origin: top center;
}
.sc-min {
float: left;
}
.sc-max {
float: right;
}
.sc-avg {
position: absolute;
top: -12%;
left: 50%;
text-align: center;
transform: translate(-50%, -50%);
}
.sc-value {
position: absolute;
top: 50%;
left: 0;
width: 100%;
font-size: 38px;
font-weight: 700;
}
.sc-gauge::after {
content: "";
width: 2px;
height: 10px;
background-color: lightgray;
position: absolute;
top: -10px;
left: 50%;
}
https://codepen.io/DineshRout/pen/NWdZKMw?editors=1100
On the wrap element with class .sc-gauge you need add position: relative; after this you can use position: absolute; for the child elements
Try to replace this classes:
.sc-gauge {
position: relative;
width: 200px;
height: 200px;
margin: 200px auto;
}
.sc-min {
position: absolute;
left: -20px;
margin-top: -27px;
}
.sc-avg {
position: absolute;
top: -23px;
left: 50%;
}
.sc-max {
position: absolute;
right: -20px;
margin-top: -27px;
}
Example:
.sc-background {
position: relative;
height: 100px;
margin-bottom: 10px;
background-color: gray;
border-radius: 150px 150px 0 0;
overflow: hidden;
text-align: center;
}
.sc-mask {
position: absolute;
top: 20px;
right: 20px;
left: 20px;
height: 80px;
background-color: #fff;
border-radius: 150px 150px 0 0
}
.sc-percentage {
position: absolute;
top: 100px;
left: -200%;
width: 400%;
height: 400%;
margin-left: 100px;
background-color: #00aeef;
}
.sc-percentage {
transform: rotate(70deg);
transform-origin: top center;
}
.sc-value {
position: absolute;
top: 50%;
left: 0;
width: 100%;
font-size: 48px;
font-weight: 700
}
/* */
.sc-gauge {
position: relative;
width: 200px;
height: 200px;
margin: 200px auto;
}
.sc-min {
position: absolute;
left: -20px;
margin-top: -27px;
}
.sc-avg {
position: absolute;
top: -23px;
left: 50%;
}
.sc-max {
position: absolute;
right: -20px;
margin-top: -27px;
}
<div class="sc-gauge">
<div class="sc-background">
<div class="sc-percentage"></div>
<div class="sc-mask"></div>
<span class="sc-value">0.7 gb</span>
</div>
<span class="sc-min">0</span>
<span class="sc-avg">1</span>
<span class="sc-max">2</span>
</div>
Related
The below code does not work, perhaps because I am using class and id in the same div. I know they are supposed to work.
Reference: Can I use DIV class and ID together in CSS?
.PB {
position: relative;
margin: 0 auto;
background-color: #000;
width: 201px;
height: 422px;
z-index: 1;
}
#pb1-1 {
position: absolute;
margin: 0px;
background-color: green;
width: 65px;
height: 98.5px;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
z-index: 2;
text-align: right;
font-size: 14px;
-webkit-text-stroke: 1px white;
}
#pb1-2 {
position: absolute;
margin: 0px;
background-color: yellow;
width: 65px;
height: 98.5px;
top: 0px;
right: 0px;
bottom: 0px;
left: 68px;
z-index: 2;
text-align: right;
font-size: 14px;
-webkit-text-stroke: 1px white;
}
#pb1-3 {
position: absolute;
margin: 0px;
background-color: red;
width: 65px;
height: 98.5px;
top: 0px;
right: 0px;
bottom: 0px;
left: 136px;
z-index: 2;
text-align: right;
font-size: 14px;
-webkit-text-stroke: 1px white;
}
.pu:hover {
font-size: 24px;
background-color: #999999;
}
<div class="PB">
<div id="pb1-1" class="pu">1 </div>
<div id="pb1-2" class="pu">2 </div>
<div id="pb1-3" class="pu">3 </div>
</div>
Can someone tell me what I am doing wrong?
You need to overwrite your :hover CSS rules using !important, because id's are always given more preference than classes. Like:
.pu:hover {
font-size:24px !important;
background-color:#999999 !important;
}
Have a look at the updated snippet below:
.PB {
position:relative;
margin:0 auto;
background-color:#000;
width:201px;
height:422px;
z-index: 1;
}
#pb1-1 {position:absolute; margin:0px; background-color:green; width:65px; height:98.5px; top:0px; right:0px; bottom:0px; left:0px; z-index:2; text-align:right; font-size:14px; -webkit-text-stroke: 1px white;}
#pb1-2 {position:absolute; margin:0px; background-color:yellow; width:65px; height:98.5px; top:0px; right:0px; bottom:0px; left:68px; z-index:2; text-align:right; font-size:14px; -webkit-text-stroke: 1px white;}
#pb1-3 {position:absolute; margin:0px; background-color:red; width:65px; height:98.5px; top:0px; right:0px; bottom:0px; left:136px; z-index:2; text-align:right; font-size:14px; -webkit-text-stroke: 1px white;}
.pu:hover {
font-size:24px!important;
background-color:#999999!important;
}
<div class="PB">
<div id="pb1-1" class="pu">1 </div>
<div id="pb1-2" class="pu">2 </div>
<div id="pb1-3" class="pu">3 </div>
</div>
Hope this helps!
This is because style of your ID's are overriding class styles (including with hover effect).
More information about cascading order can be found here: https://www.w3.org/TR/2011/REC-CSS2-20110607/cascade.html#cascade
In your example, I would avoid using !important, and use only classes to define styles:
.PB {
position: relative;
margin: 0 auto;
background-color: #000;
width: 201px;
height: 422px;
z-index: 1;
}
.pu {
position: absolute;
margin: 0;
width: 65px;
height: 98.5px;
top: 0;
right: 0;
bottom: 0;
z-index: 2;
text-align: right;
font-size: 14px;
-webkit-text-stroke: 1px white;
}
.pb1-1 { background-color: green; left: 0; }
.pb1-2 { background-color: yellow; left: 68px; }
.pb1-3 { background-color: red; left: 136px; }
.pu:hover {
font-size: 24px;
background-color: #999999;
}
<div class="PB">
<div class="pu pb1-1">1 </div>
<div class="pu pb1-2">2 </div>
<div class="pu pb1-3">3 </div>
</div>
You can try this with pseudo classes
.PB {
position: relative;
margin: 0 auto;
background-color: #000;
width: 201px;
height: 422px;
z-index: 1;
}
.pu {
position: absolute;
margin: 0;
width: 65px;
height: 98.5px;
top: 0;
right: 0;
bottom: 0;
z-index: 2;
text-align: right;
font-size: 14px;
-webkit-text-stroke: 1px white;
}
.pu:nth-child(1) { background-color: green; left: 0; }
.pu:nth-child(2) { background-color: yellow; left: 68px; }
.pu:nth-child(3) { background-color: red; left: 136px; }
.pu:hover {
font-size: 24px;
background-color: #999999;
}
<div class="PB">
<div class="pu">1 </div>
<div class="pu">2 </div>
<div class="pu">3 </div>
</div>
Click here!
Add <style type="text/css"> attribute. That's your problem. It will work.
I am trying to place my leftbody and rightbody over top of my MidBody but it doesnt seem to work. I thought placing the Midbody to relative and the left and right bodies to absolute with a z-index would help but it doesnt. So i am clueless right now. Any help would be greatly appreciated.
.Header {
background-color: #CCCCCC;
width: calc(100%-16px);
height: 100px;
border-radius: 5px;
}
.MidBody {
background-color: #141414;
width: calc(100%-16px);
height: 850px;
margin-top: 3px;
border-radius: 5px;
position: relative;
}
.footer {
background-color: #CCCCCC;
width: calc(100%-16px);
height: 50px;
margin-top: 5px;
border-radius: 5px;
}
#leftbody {
background-color: #F1F1F1;
width: calc(50%-16px);
height: 425px;
float: left;
margin-left: 3px;
position: absolute;
z-index: 1;
}
#rightbody {
background-color: #F1F1F1;
width: calc(50%-16px);
height: 425px;
float: right;
position: absolute;
z-index: 1;
}
<div class="Header"></div>
<div class="MidBody">
<div id="leftbody"></div>
<div id="rightbody"></div>
</div>
<div class="footer"></div>
I changed
float:left; -> left:0;
float:right; -> right:0;
and
width:calc(50%-16px); -> width:50%;
Final css :
.Header {
background-color:#CCCCCC;
width: calc(100%-16px);
height: 100px;
border-radius: 5px;
}
.MidBody {
background-color:#141414;
width: calc(100%-16px);
height: 850px;
margin-top:3px;
border-radius: 5px;
position: relative;
}
.footer {
background-color:#CCCCCC;
width:calc(100%-16px);
height: 50px;
margin-top: 5px;
border-radius: 5px;
}
#leftbody {
background-color:#F1F1F1;
width:50%;
height:425px;
left:0;
margin-left: 3px;
position: absolute;
z-index: 9999;
}
#rightbody {
background-color:#F1F1F1;
width:50%;
height:425px;
right:0;
position: absolute;
z-index: 9999;
}
<div class="Header"></div>
<div class="MidBody">
<div id="leftbody"></div>
<div id="rightbody"></div>
</div>
<div class="footer"></div>
Use position: fixed; instead of position: absolute;
I want to make this shape :
there supposed to be 3 div shapes like this. I built already some shape, but I want to see how this shape will fit in my website
I already built this :
codepan
css example for what i did :
.mainOuterDiv{
height:300px;
overflow:hidden;
background:#FFF;
}
.middDiv{
width:70%;
height:75px;
background-color: #0CF;
margin:0px auto;
position:relative;
margin-top:50%;
}
.innerLeft{
position: absolute;
left: -60px;
top: -20px;
width: 60px;
height: 100%;
z-index: 1;
transform: skew(180deg,215deg);
background-color: #0CF;
}
.innerRight{
position: absolute;
right: -60px;
top: -20px;
width: 60px;
height: 100%;
z-index: 1;
transform: skew(180deg,145deg);
background-color: #0CF;
}
.textDiv{
z-index:9999;
width:100%;
height:100%;
position:absolute;
background-color: #0CF;
}
is there a way to make this in css ?
Here is the responsive version with skewY i have used :pseudo elements
* {
box-sizing: border-box;
}
.container {
width: 300px;
height: 300px;
margin: 0 auto;
border: 1px solid black;
position: relative;
}
.content {
background: white;
z-index: 1;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
padding: 15px;
}
.shadow {
width: 70%;
position: absolute;
left: 50%;
height: 18%;
bottom: 18%;
background: #7092BE;
border: 1px solid black;
transform: translateX(-50%);
z-index: -1;
}
.shadow:before,
.shadow:after {
content: '';
position: absolute;
width: 30%;
background: #7092BE;
height: 100%;
bottom: -28%;
border: 1px solid black;
}
.shadow:before {
left: -30%;
transform: skewY(-23deg);
}
.shadow:after {
right: -30%;
transform: skewY(23deg);
}
.ribbon {
width: 70%;
position: absolute;
left: 50%;
height: 18%;
bottom: -1px;
background: #7092BE;
border: 1px solid black;
transform: translateX(-50%);
z-index: 1;
}
.ribbon:before,
.ribbon:after {
content: '';
position: absolute;
width: 30%;
background: #7092BE;
height: 100%;
top: -28%;
border: 1px solid black;
}
.ribbon:before {
left: -30%;
transform: skewY(23deg);
}
.ribbon:after {
right: -30%;
transform: skewY(-23deg);
}
hr {
margin: 20px;
0
}
<div class="container">
<div class="content">
Nullam dictum felis eu pede
</div>
<div class="shadow"></div>
<div class="ribbon"></div>
</div>
<hr>
<div class="container" style="width:200px; height:200px;">
<div class="content">
Nullam dictum felis eu pede
</div>
<div class="shadow"></div>
<div class="ribbon"></div>
</div>
There is some example :
.container
{
position:relative;
width:400px; height:302px;
overflow:hidden;
}
.mainDiv
{
height:300px; width:300px;
background-color:white;
border:solid 1px black;
position:absolute;
left:0;right:0;margin:auto;
}
.middDiv
{
height:55px; width:70%;
background-color:lightblue;
position:absolute;
bottom:0;left:0;right:0;
margin:auto;
z-index:10;
}
.leftDiv, .rightDiv
{
position:absolute;
bottom:26px;
width:30%;height:48px;
background-color:blue;
z-index:10;
}
.leftDiv
{
left:-13%;
transform:rotate(30deg) skew(30deg);
}
.rightDiv
{
right:-13%;
transform:rotate(-30deg) skew(-30deg);
}
.leftBDiv, .rightBDiv
{
position:absolute;
width:13%; height:47px;
bottom:59px;
background-color:black;
z-index:9;
}
.leftBDiv
{
left:-12%;
transform:rotate(-30deg) skew(-30deg);
}
.rightBDiv
{
right:-12%;
transform:rotate(30deg) skew(30deg);
}
<div class="container">
<div class="mainDiv">
<div class="middDiv"></div>
<div class="leftDiv"></div>
<div class="rightDiv"></div>
<div class="leftBDiv"></div>
<div class="rightBDiv"></div>
</div>
</div>
I use different colors for middle, left and right blocks so You can see it.
If You will use border for those divs, You have to change positions: left, right and bottom for all of them.
There is fiddle example, too.
I am trying to create a lifted corner, 3d box effect on the bottom and top of a div. I am able to create the desired effect on bottom of the div, but cannot figure out how to mimic the effect on the top. Does anyone know how to achieve this on both the bottom and top of a div?
Here is a JSFiddle: https://jsfiddle.net/rnejan81/
body {
background-color: #e2e2e2;
}
.box h3{
text-align:center;
position:relative;
top:80px;
}
.box {
width:70%;
height:200px;
background:#FFF;
margin:40px auto;
}
.effect2
{
position: relative;
}
.effect2:before, .effect2:after
{
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width:300px;
background: #777;
box-shadow: 0 15px 10px #777;
transform: rotate(-3deg);
}
.effect2:after
{
transform: rotate(3deg);
right: 10px;
left: auto;
}
<div class="box effect2 effect3">
<h3>Effect 2</h3>
</div>
I just wrapped your box with another div and got the desired output
EDIT: Demo had some alignment issue before, thanks for #zaqx for pointing out that. this is the updated fiddle.
Here is the fiddle
body {
background-color: #e2e2e2;
}
.box h3{
text-align:center;
position:relative;
top:80px;
}
.box {
width:70%;
height:200px;
background:#FFF;
margin:40px auto;
}
/*==================================================
* Effect 2
* ===============================================*/
.effect2
{
position: relative;
}
.effect2:before, .effect2:after
{
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width:300px;
background: #777;
box-shadow: 0 15px 10px #777;
transform: rotate(-3deg);
}
.effect2:after
{
transform: rotate(3deg);
right: 10px;
left: auto;
}
.effect-wrapper {
position: relative;
}
.effect-wrapper:before, .effect-wrapper:after {
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 16%;
width: 52%;
top: 8%;
height: 5px;
max-width: 300px;
background: #777;
box-shadow: 0 15px 10px #777;
transform: rotate(183deg);
}
.effect-wrapper:after {
transform: rotate(177deg);
right: 16%;
left: auto;
}
<div class="effect-wrapper">
<div class="box effect2 effect3">
<h3>Effect 2</h3>
</div>
</div>
I am having problem, aligning the div on 3rd box, Result will be like below.
HTML
<div class="hbox">
<div class="h1"></div>
<div class="h2"></div>
<div class="h3"></div>
</div>
CSS
.hbox
{
float: left;
width: 323px;
height: 188px;
margin: 88px 0 0 5px;
background:url("http://oi59.tinypic.com/96j3g0.jpg") no-repeat;
}
.h1
{float: left;
position: relative;
width:62px;
height:62px;
border-radius:100%;
left: 79px;
top: 24px;
z-index: 2; background:#000;}
http://jsfiddle.net/1mmj24ny/
try pseudo-element :before his code DEMO
.hbox
{
float: left;
width: 323px;
height: 188px;
margin: 88px 0 0 5px;
background:url("http://oi59.tinypic.com/96j3g0.jpg") no-repeat;
position:relative;
}
.hbox:before {
background: none repeat scroll 0 0 #fff;
content: "";
height: 115px;
left: 27px;
position: absolute;
top: 58px;
width: 282px;
z-index: 10;
}
.h1
{float: left;
position: relative;
width:62px;
height:62px;
border-radius:100%;
left: 79px;
top: 24px;
z-index: 2; background:#000;}
.h2
{float: left;
position: relative;
width:62px;
height:62px;
border-radius:100%;
left: 79px;
top: 24px;
z-index: 2; background:#ccc;}
.h3
{float: left;
position: relative;
width:62px;
height:62px;
border-radius:100%;
left: 79px;
top: 24px;
z-index: 2; background:#ff0000;}
Just a quick fix. Add a div with bg white inside .hbox
CSS
.white_div {
position: absolute;
width: 282px;
height: 110px;
background: #fff;
bottom: 17px;
left: 27px;
z-index:100;
}
DEMO
try this
.hbox {
float: left;
width: 323px;
height: 188px;
margin: 88px 0 0 5px;
background: url("http://oi59.tinypic.com/96j3g0.jpg") no-repeat;
position: relative;
}
.hbox:before {
background: none repeat scroll 0 0 #fff;
content: "";
height: 115px;
left: 27px;
position: absolute;
top: 58px;
width: 282px;
z-index: 10;
}
.h1 {
float: left;
position: relative;
width: 62px;
height: 62px;
border-radius: 100%;
left: 79px;
top: 24px;
z-index: 2;
background: #000;
}
.h2 {
float: left;
position: relative;
width: 62px;
height: 62px;
border-radius: 100%;
left: 79px;
top: 24px;
z-index: 2;
background: #ccc;
}
.h3 {
float: left;
position: relative;
width: 62px;
height: 62px;
border-radius: 100%;
left: 79px;
top: 24px;
z-index: 2;
background: #ff0000;
}
<div class="hbox">
<div class="h1"></div>
<div class="h2"></div>
<div class="h3"></div>
</div>