I'm trying to get a input slider within another parent div. The
desired result looks like this:
The problem is when I try this the input slider gets a huge width, and
the height is messed up aswel.
I made Fiddle:
.wrapper {
display: inline-block;
width: 100%;
max-width: 100px;
background: #353434;
color: rgba(255, 255, 255, 0.9);
box-shadow: inset 0px 0px 4px 0px rgba(0, 0, 0, 0.75);
font-family: 'Raleway', 'Helvetica Neue', 'Helvetica', 'Arial'
}
.wrapper-header {
display: flex;
flex-flow: row nowrap;
justify-content: center;
padding: .5rem;
}
.wrapper-middle {
display: flex;
justify-content: center;
align-items: center;
}
.wrapper-end {
display: flex;
flex-flow: row nowrap;
justify-content: center;
height: 340px;
padding-top: 1rem;
padding-bottom: 1rem;
}
.slider-value {
min-width: 24px;
padding: .25rem;
border-radius: 2px;
color: #1fcc1f;
background: #333;
box-shadow: inset 0 0 3px 3px rgba(0, 0, 0, 0.5);
font-family: 'VT323', monospace;
text-align: center;
}
.button {
padding: .55rem;
border-radius: 2px;
background: linear-gradient(to bottom, #4f4f4f 0%, #0e0e0e 100%);
box-shadow: 0px 0px 1px 1px rgba(0, 0, 0, 0.5);
}
.wrapper-end-left {
height: 100%;
background: red;
}
.wrapper-end-right {
height: 100%;
background: blue;
}
[type='range'] {
-webkit-appearance: none; /* Hides the slider so that custom slider can be made */
margin: 0;
padding: 0;
width: 30rem;
height: 1.5em;
transform: rotate(-90deg);
background: transparent;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
box-sizing: border-box;
border: none;
width: 1.5em; height: 1.5em;
border-radius: 50%;
background: #f90;
}
input[type=range]::-webkit-slider-runnable-track {
box-sizing: border-box;
border: none;
margin: 0;
padding: 0;
width: 100%; height: 100%;
background: #ccc;
}
<div class="wrapper">
<div class="wrapper-header">
<div class="button">
x
</div>
<div class="button">
x
</div>
</div>
<div class="wrapper-middle">
<div class="slider-value">
1
</div>
</div>
<div class="wrapper-end">
<div class="wrapper-end-left">
<input type="range">
</div>
<div class="wrapper-end-right">
two
</div>
</div>
</div>
Does someone know why this is happening?
Already read a lot here about input sliders but can't fix it.
https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/
https://codepen.io/freoted/pen/WGvxmN
https://jsfiddle.net/rwaldron/XukVc/
It is a little hacky but it resembles the desired layout now slightly closer - not tested to see how this would fare at different locations on the page or at different sizes. one of the key things that changed the layout was setting the transform-origin and tweaking the location with translate3d
document.addEventListener('DOMContentLoaded',(e)=>{
document.querySelector('[type="range"]').addEventListener('change',(e)=>{
document.querySelector('div.slider-value').textContent=e.target.value > 0 ? e.target.value : e.target.value * -1;
});
});
.wrapper {
display: inline-block;
width: 100%;
max-width: 100px;
background: #353434;
color: rgba(255, 255, 255, 0.9);
box-shadow: inset 0px 0px 4px 0px rgba(0, 0, 0, 0.75);
font-family: 'Raleway', 'Helvetica Neue', 'Helvetica', 'Arial'
}
.wrapper,.wrapper *{
box-sizing: border-box;
}
.wrapper-header {
display: flex;
flex-flow: row nowrap;
justify-content: center;
padding: .5rem;
}
.wrapper-middle {
display: flex;
justify-content: center;
align-items: center;
}
.wrapper-end {
display: flex;
flex-flow: row nowrap;
justify-content: center;
height: 340px;
padding-top: 1rem;
padding-bottom: 1rem;
}
.slider-value {
min-width: 24px;
padding: .25rem;
border-radius: 2px;
color: #1fcc1f;
background: #333;
box-shadow: inset 0 0 3px 3px rgba(0, 0, 0, 0.5);
font-family: 'VT323', monospace;
text-align: center;
}
.button {
padding:0.55rem;
border-radius:2px;
background: linear-gradient(to bottom, #4f4f4f 0%, #0e0e0e 100%);
box-shadow: 0px 0px 1px 1px rgba(0, 0, 0, 0.5);
}
.wrapper-end-left {
height: 100%;
padding:0;
margin:0 1.25rem 0 0;
display:flex;
flex-direction:column;
flex-wrap:no-wrap;
align-content:center;
justify-content:stretch;
}
.wrapper-end-right {
height:100%;
width:0.75rem!important;
background:linear-gradient(0deg, rgba(13,60,2,1) 0%, rgba(57,241,17,1) 79%, rgba(245,157,63,1) 92%, rgba(255,0,0,1) 100%);
}
.wrapper-end-left,
.wrapper-end-right{
width:2rem;
}
[type='range'] {
-webkit-appearance:none;
margin:0;
padding:0;
flex:1;
height:1.5rem;
width:19.2rem;
transform-origin:5% 50%;
transform:rotate(-90deg) translate3d( -8.6rem, -0.25rem, 0 );
background:transparent;
outline:0;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance:none;
border:none;
width:1.5em;
height:1.5em;
border-radius:50%;
background:black;
border:2px solid silver;
margin:-0.35rem 0 0 0;
}
input[type=range]::-webkit-slider-runnable-track {
box-sizing:border-box;
border:none;
margin:0;
padding:0;
height:0.5rem;
flex:1;
background:#ccc;
}
<div class="wrapper">
<div class="wrapper-header">
<div class="button">x</div>
<div class="button">x</div>
</div>
<div class="wrapper-middle">
<div class="slider-value">0</div>
</div>
<div class="wrapper-end">
<div class="wrapper-end-left"><input type="range" step=3 min=-60 max=12 value=0 /></div>
<div class="wrapper-end-right"> </div>
</div>
</div>
Related
I would like to add a badge to my navbar. It should look like the one in the image below.
My current Approach
I use two divs for this. One above and one below. The lower one should do the rounding.
My approach works not so good and I find it more hacky as good.
Question
I wonder if there is a better, cleaner way? Can somebody help me?
Thanks in advance, Max
* {
margin: 0;
padding: 0;
font-family: Verdana,Geneva,sans-serif;
}
body {
background-color: #f1f1f1;
}
nav {
height: 80px;
background-color: white;
padding:10px 80px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
}
.badge-top {
background: #ccc;
margin-top:-10px;
height:25px;
padding-top:20px;
padding-left:5px;
padding-right:5px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
font-size:0.8rem;
font-weight:bold;
width:30px;
text-align: center;
}
.badge-bottom {
background: #ccc;
color:#ccc;
border-radius:50px;
margin-top:-10px;
}
.badge-bottom:after {
content: '.';
}
<nav>
<div>logo</div>
<div>
<button class="btn nav-btn">SUBMIT</button>
</div>
<div>
<div class="badge-top">123</div>
<div class="badge-bottom"></div>
</div>
</nav>
Really no reason for multiple elements. Note that I've put box-sizing: border-box on your stylesheet. This makes sizing calculations much easier by including padding, etc. Most layout libraries do this.
* {
margin: 0;
padding: 0;
font-family: Verdana, Geneva, sans-serif;
box-sizing: border-box;
}
body {
background-color: #f1f1f1;
}
nav {
height: 80px;
background-color: white;
padding: 10px 80px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
}
.badge {
background: #ccc;
width: 40px;
height: 60px;
padding-top: 26px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
font-size: 0.8rem;
font-weight: bold;
text-align: center;
border-radius: 0 0 20px 20px;
}
<nav>
<div>logo</div>
<div>
<button class="btn nav-btn">SUBMIT</button>
</div>
<div class="badge">
123
</div>
</nav>
div {
position: relative;
width: 2.5rem;
height: 4.5rem;
border-bottom-left-radius: 1.25rem;
border-bottom-right-radius: 1.25rem;
box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.4);
background-color: #bfbfbf;
}
span {
position: absolute;
bottom: 1rem;
left: 50%;
transform: translate(-50%);
color: #222;
font-weight: bold;
}
<div>
<span>420</span>
</div>
I'm looking to make div.box and button.navBtn responsive.
Currently when the page is resized to 871px width, the buttons instantly stack on top of each other and the long div.box is squished until it clashes into the buttons. The "final look" (around 500px wide) doesn't even look that bad honestly and is the ideal way this window would look on smaller screens. I'm just trying to make the transition to that size nicer.
Preferably I'd like the buttons to resize themselves gradually with div.box until they hit a certain width and then stack on top of each other however I can't figure out how to apply the correct media query to do this. I feel as if my divider is causing some type of issue a well with spacing but I'm not entirely sure. It does have some whitespace I can't get rid of and is set to 2em width.
I'm also not sure why div.main stops resizing once you hit around 495px width. I'm gonna make sure I use Bootstrap or something next time to avoid this...
Any help would be appreciated. Here's a big snippet of code:
html {
min-height: 100%;
}
body {
display: flex;
justify-content: center;
font-family: 'Lora', serif;
margin: .8em;
background-color: #151b20;
background-size: cover;
background-position: center;
background-attachment: fixed;
background-repeat: no-repeat;
overflow-y: scroll;
}
h1 {
color: rgb(250, 250, 250);
display: flex;
justify-content: center;
font-size: 3.5em;
margin-top: 0px;
margin-bottom: 10px;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
h2 {
color: rgb(250, 250, 250);
display: flex;
font-size: 1.7em;
justify-content: center;
padding-top: 5px;
margin-bottom: 16px;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
a {
color: rgb(250, 250, 250);
}
ul {
padding-left: 0px;
}
li {
color: rgb(250, 250, 250);
display: flex;
justify-content: center;
list-style: none;
font-size: 1.5em;
margin-bottom: 5px;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
button {
background: rgba(0, 0, 0, 0);
background-image: url(Pictures/blank.png);
color: #a5afaa;
border: 3.5px solid transparent;
border-radius: .6em;
padding: 2.8em;
/* transition: all 0.2s; */
background-repeat: no-repeat;
}
button:hover {
border-color: #fff8cc;
box-shadow: 0em 0em 1em 0em #fff8cc;
cursor: url('Pictures/glove-lg.png'), auto;
}
.main {
border: solid 2px #939388;
border-radius: 10px;
background-image: url(Pictures/texture.png);
background-color: #0f0f3de8;
box-shadow: 0 0.1em 0.3em 0.1em rgba(0, 0, 0, 0.6);
margin-top: 20px;
}
.inner {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
margin: 20px;
}
.decoration {
outline: 2px solid rgba(128, 128, 128, 0.4);
outline-offset: -5px;
border-radius: 10px;
border-top-width: 1px;
border-bottom-width: 1px;
border-top-style: solid;
border-bottom-style: solid;
}
.box {
background-color: #080824;
box-shadow: inset 0 0 5px rgba(255, 255, 255, 0.6);
border-radius: 3px;
margin: 30px;
padding: 1px;
}
.wrapper {
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
.navHome {
display: inline-block;
position: relative;
margin-top: 15px;
}
.navBtn {
border: solid 2px #939388;
background-image: none;
background-color: #0f0f3d;
width: 25em;
box-shadow: 0 0.1em 0.3em 0.1em rgba(0, 0, 0, 0.6);
}
.navText {
color: white;
font-family: 'Lora', serif;
font-size: 2em;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
line-height: 0em;
}
.divider {
display: inline-block;
width: 2em;
height: auto;
}
.aboutText {
color: white;
font-family: 'Lora', serif;
font-size: 1.5em;
text-align: center;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
line-height: 1.5em;
}
#about {
padding-top: 25px;
}
#homeList {
margin-bottom: 0px;
}
#homeBox {
padding: 30px;
padding-top: 20px;
}
#media screen and (max-width: 992px) {
h1 {
text-align: center;
padding: 3px;
}
}
<body>
<div class="wrapper">
<div class="main">
<div class="decoration">
<div id="about">
<h1>I mean, it kinda works...</h1>
<ul id="homeList">
<li>Long List Item #1</li>
<li>Long List Item #2</li>
</ul>
<div id="innerHome" class="inner">
<div id="homeBox" class="box">
<a href="" class="navHome">
<button class="navBtn">
<div class="navText">About</div>
</button>
</a>
<div class="divider"></div>
<a href="" class="navHome">
<button class="navBtn">
<div class="navText">Items</div>
</button>
</a>
</div>
</div>
</div>
</div>
</div>
For the buttons to resize themselves you can't give them an explicit width like you do in .navBtn. You need to make them have a certain percentage of the parent and when they hit their minimal witdh they wrap.
Without that change the best that can be done is making the parent smaller when the elements wrap like so:
#homeBox {
width: min-content;
}
#media (min-width: 992px) {
#homeBox {
width: auto;
}
}
html {
min-height: 100%;
}
body {
display: flex;
justify-content: center;
font-family: 'Lora', serif;
margin: .8em;
background-color: #151b20;
background-size: cover;
background-position: center;
background-attachment: fixed;
background-repeat: no-repeat;
overflow-y: scroll;
}
h1 {
color: rgb(250, 250, 250);
display: flex;
justify-content: center;
font-size: 3.5em;
margin-top: 0px;
margin-bottom: 10px;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
h2 {
color: rgb(250, 250, 250);
display: flex;
font-size: 1.7em;
justify-content: center;
padding-top: 5px;
margin-bottom: 16px;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
a {
color: rgb(250, 250, 250);
}
ul {
padding-left: 0px;
}
li {
color: rgb(250, 250, 250);
display: flex;
justify-content: center;
list-style: none;
font-size: 1.5em;
margin-bottom: 5px;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
button {
background: rgba(0, 0, 0, 0);
background-image: url(Pictures/blank.png);
color: #a5afaa;
border: 3.5px solid transparent;
border-radius: .6em;
padding: 2.8em;
/* transition: all 0.2s; */
background-repeat: no-repeat;
}
button:hover {
border-color: #fff8cc;
box-shadow: 0em 0em 1em 0em #fff8cc;
cursor: url('Pictures/glove-lg.png'), auto;
}
.main {
border: solid 2px #939388;
border-radius: 10px;
background-image: url(Pictures/texture.png);
background-color: #0f0f3de8;
box-shadow: 0 0.1em 0.3em 0.1em rgba(0, 0, 0, 0.6);
margin-top: 20px;
}
.inner {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 20px;
}
.decoration {
outline: 2px solid rgba(128, 128, 128, 0.4);
outline-offset: -5px;
border-radius: 10px;
border-top-width: 1px;
border-bottom-width: 1px;
border-top-style: solid;
border-bottom-style: solid;
}
.box {
background-color: #080824;
box-shadow: inset 0 0 5px rgba(255, 255, 255, 0.6);
border-radius: 3px;
margin: 30px;
padding: 1px;
}
.wrapper {
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
.navHome {
margin-top: 15px;
display: inline-block;
position: relative;
}
.navBtn {
border: solid 2px #939388;
background-image: none;
background-color: #0f0f3d;
box-shadow: 0 0.1em 0.3em 0.1em rgba(0, 0, 0, 0.6);
/* max-width: 25em; */
width: 25em;
}
.navText {
color: white;
font-family: 'Lora', serif;
font-size: 2em;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
line-height: 0em;
}
.divider {
display: inline-block;
width: 2em;
height: auto;
}
.aboutText {
color: white;
font-family: 'Lora', serif;
font-size: 1.5em;
text-align: center;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
line-height: 1.5em;
}
#about {
padding-top: 25px;
}
#homeList {
margin-bottom: 0px;
}
#homeBox {
padding: 30px;
padding-top: 20px;
}
#homeBox {
width: min-content;
}
#media (min-width: 992px) {
#homeBox {
width: auto;
}
}
#media screen and (max-width: 992px) {
h1 {
text-align: center;
padding: 3px;
}
}
<body>
<div class="wrapper">
<div class="main">
<div class="decoration">
<div id="about">
<h1>I mean, it kinda works...</h1>
<ul id="homeList">
<li>Long List Item #1</li>
<li>Long List Item #2</li>
</ul>
<div id="innerHome" class="inner">
<div id="homeBox" class="box">
<a href="" class="navHome">
<button class="navBtn">
<div class="navText">About</div>
</button>
</a>
<div class="divider"></div>
<a href="" class="navHome">
<button class="navBtn">
<div class="navText">Items</div>
</button>
</a>
</div>
</div>
</div>
</div>
</div>
I've been trying to make this responsive. When I shrink the size of the window or look at it on a phone, I would like it to put the second column in a new row so I have 3 rows and each has 100% of it.
Also, there might be a better way of doing this where you don't use tables so if you could suggest something else I would be grateful.
PHP
<!DOCTYPE html>
<html lang="hr">
<head>
<?php
$title = "Foto | Album";
$description = "Web aplikacija za besplatno dijelenje fotografija";
$keywords = "dijelenje fotografija, komentiranje, kategorije";
include "includes/head.php";
?>
</head>
<body>
<div class="red">
<?php include "includes/header.php"; ?>
</div>
<div class="red">
<table class="t-kolona-12 d-kolona-12">
<tr>
<td id="table1"> <?php include "includes/navigation.php"; ?> </td>
<td rowspan="2"><section id="sadrzaj" class="t-kolona-9 d-kolona-12">
<!--sadržaj-->
</section>
</tr>
<tr>
<td> <?php include "includes/aside.php"; ?></td>
</tr>
</table>
</div>
<div class="red">
<?php include "includes/footer.php"; ?>
</div>
</body>
</html>
CSS
body{
margin: 0;
}
#zaglavlje{
margin-bottom: 20px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
height: 310px;
background: url(../images/slike/header_img1.jpg) no-repeat center center/cover;
display: flex;
justify-content: center;
align-items: center;
}
#zaglavlje h1{
color: #ffffff;
margin: 0;
font-size: 50px;
text-shadow: 2px 2px 2px black;
}
#navigacija ul{
list-style-type: none;
margin: 0;
padding: 0;
padding: 0;
}
#navigacija li{
margin-bottom: 7px;
background-color: #d8dde2;
text-align: center;
box-shadow: 0 1px 3px rga(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
#navigacija a{
color: #000000;
text-decoration: none;
display: block;
padding: 10px;
}
#navigacija li:hover{
background-color: #c7cbcf;
}
#sadrzaj{
box-shadow: 0px 1px 3px rgba(0,0,0,0.12), 0px 1px 2px rgba(0,0,0,0.24);
margin-bottom:20px;
min-height:500px;
max-height:2000px;
overflow:auto;
}
#prijava form{
padding: 15px;
background-color: #d8dde2;
color: #000000;
box-shadow: 0 1px 3px rga(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
#prijava h2{
text-align: center;
margin: 0 0 10px 0;
}
#prijava label{
display: block;
width: 90%;
margin: auto;
}
#prijava input[type="text"], #prijava input[type="password"]{
display: block;
width: 90%;
margin: auto;
}
#prijava input[type="submit"]{
display: block;
margin: auto;
color: #000000;
background-color: #d8dde2;
font-size: 16px;
}
#podnozje{
background-color: #bbbfc4;
color: #000000;
text-align: center;
font-size: 14px;
box-shadow: 0 1px 3px rga(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
#table1{
width: 300px;
}
/* responzivnost */
img, video, iframe, object{
max-width: 100%;
}
#media(min-width: 700px){
#navigacija li{
text-align: left;
}
}
#media(min-width: 750px){
#zaglavlje{
background: url(../images/slike/header_img_mobile1.jpg) no-repeat center center/cover;
}
}
/* layout */
*{
box-sizing: border-box;
}
.red:after{
content: "";
clear: both;
display: block;
}
/* mobile */
[class*="kolona"]{
float: left;
padding: 10px;
width: 100%;
}
/* tablet*/
#media (min-width:700px){
.t-kolona-1{width:8.33%;}
.t-kolona-2{width:16.66%;}
.t-kolona-3{width:25%;}
.t-kolona-4{width:33.33%;}
.t-kolona-5{width:41.66%;}
.t-kolona-6{width:50%;}
.t-kolona-7{width:58.33%;}
.t-kolona-8{width:66.66%;}
.t-kolona-9{width:75%;}
.t-kolona-10{width:83.33%;}
.t-kolona-11{width:91.66%;}
.t-kolona-12{width:100%;}
}
/* desktop */
#media (min-width:1100px){
.d-kolona-1{width:8.33%;}
.d-kolona-2{width:16.66%;}
.d-kolona-3{width:25%;}
.d-kolona-4{width:33.33%;}
.d-kolona-5{width:41.66%;}
.d-kolona-6{width:50%;}
.d-kolona-7{width:58.33%;}
.d-kolona-8{width:66.66%;}
.d-kolona-9{width:75%;}
.d-kolona-10{width:83.33%;}
.d-kolona-11{width:91.66%;}
.d-kolona-12{width:100%;}
}
I am trying to make a progress bar as is shown here in the about section however I am just lost.
I can make a bar and a box but neither look anywhere near as good as that and I cannot for the life of me get them to be beside each other with equal height. I just keep getting something along the lines of
What I am trying to achieve in case website goes down:
.myskills {
width: 45vw;
height: 100%;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
justify-content: center;
height: 2vh;
}
.skillName {
background-color: blue;
width: 5vw;
float: left;
height: 100%;
font-size: 2em;
}
.meter {
float: left;
width: 80%;
height: 100%;
/* Can be anything */
position: relative;
background: #555;
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: hotpink;
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
position: relative;
overflow: hidden;
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"></span>
</div>
</div>
</div>
This code below will give you the percentage sign on the right of the percentage bar. A lot of this is purely layering with hmtl/css.
Here are some links for layering and z-index:
https://www.tutorialspoint.com/css/css_layers.htm#:~:text=The%20CSS%20layers%20refer%20to,element%20should%20come%20at%20bottom.
https://www.w3schools.com/cssref/pr_pos_z-index.asp
https://css-tricks.com/almanac/properties/z/z-index/
.myskills {
width: 90%%;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
}
.skillLevel{
right: 0;
font-size: 1.7em;
position: absolute;
}
.skillName {
background-color: rgb(77, 252, 208);
float: left;
font-size: 2em;
}
.meter {
float: left;
width: 100%;
/* Can be anything */
position: relative;
background: rgb(218, 217, 217);
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: rgb(31, 134, 117);
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"><span class="skillLevel">90%</span></span>
</div>
</div>
</div>
Well, IMO you should use less vh and vw. Your font simply defines the height and the width of the text part. By removing them, you get something as you want as I understood (I also removed useless properties) :
.myskills {
width: 45vw;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
}
.skillName {
background-color: blue;
font-size: 2em;
}
.meter {
float: left;
width: 100%;
/* Can be anything */
position: relative;
background: #555;
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: hotpink;
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"></span>
</div>
</div>
</div>
Now, if it was my progress bar I'd use flex instead of width for .meter, I'd take a smaller font size and put padding to the text :
.myskills {
width: 45vw;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
}
.skillName {
background-color: blue;
font-size: 18px;
padding: 3px 10px;
}
.meter {
float: left;
flex: 1;
/* Can be anything */
position: relative;
background: #555;
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: hotpink;
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"></span>
</div>
</div>
</div>
I'd like to have a button at the bottom of a table, in the middle of the bottom of the table, centered. I did add left:30% and right:30% so the button locates at the middle, however, I noticed in Chrome this get rendered differently than Safari or Firefox, in Chrome, the percentages are not the same, thus the button ends up a little more to the left than right, and not centered/middled. Try it below.
How can I get this to work the same in Chrome too? Why are the percentages rendered differently, what's the best technique to centre this element that needs to be in absolute positioning?
.panel {
background-color: #fff;
border-radius: 10px;
padding: 15px 25px;
position: relative;
width: 100%;
z-index: 10;
}
.table {
box-shadow: 0px 10px 13px -6px rgba(0, 0, 0, 0.08), 0px 20px 31px 3px rgba(0, 0, 0, 0.09), 0px 8px 20px 7px rgba(0, 0, 0, 0.02);
display: flex;
flex-direction: column;
height:350px;
background:lightblue;
}
.table * {
text-align: center;
}
.contact-button {
bottom: -25px;
background: #f9f9f9;
border-radius: 10px;
left: 30%;
right: 30%;
margin: 0 auto;
position:absolute;
}
.btn {
display: inline-block;
padding: 8px 32px;
cursor: pointer;
text-align: center;
vertical-align: middle;
white-space: nowrap;
outline: none;
line-height: inherit;
background-color: white;
border: 1px solid black;
color: black;
font-size: 14px;
letter-spacing: 2px;
}
<div class="panel table">
<button class="btn contact-button">CONTACT MORE INFO</button>
</div>
You can just move the button from the div and create something like this
<div class="panel table"></div>
<div class="wrapper">
<button class="btn contact-button">CONTACT MORE INFO</button>
</div>
This way you don't have to use position:absolute; you can just use
display:flex;
justify-content:center;
If you want more support for older browser versions, please check this article
Check the example below
.panel {
background-color: #fff;
border-radius: 10px;
position: relative;
width: 100%;
z-index: 10;
}
.table {
box-shadow: 0px 10px 13px -6px rgba(0, 0, 0, 0.08), 0px 20px 31px 3px rgba(0, 0, 0, 0.09), 0px 8px 20px 7px rgba(0, 0, 0, 0.02);
display: flex;
flex-direction: column;
height: 350px;
background: lightblue;
}
.table * {
text-align: center;
}
.contact-button {
bottom: -25px;
background: #f9f9f9;
border-radius: 10px;
left: 30%;
right: 30%;
margin: 0 auto;
}
.btn {
display: inline-block;
padding: 8px 32px;
cursor: pointer;
text-align: center;
vertical-align: middle;
white-space: nowrap;
outline: none;
line-height: inherit;
border: 1px solid black;
color: black;
font-size: 14px;
letter-spacing: 2px;
}
.wrapper {
display: flex;
justify-content: center;
}
body {
margin: 0;
}
<div class="panel table">
</div>
<div class="wrapper">
<button class="btn contact-button">CONTACT MORE INFO</button>
</div>
You can use this also it may help you without changing much things:
.contact-button {
background: #f9f9f9;
border-radius: 10px;
margin: 0 auto;
margin-top:370px;
}
have a look on this bin: https://jsbin.com/gipibecedu/edit?html,css,output