CSS - Prevent an element from wrapping in a progress bar - html

I'm designing an animated progress bar to display ratings on my website. At the end of the bar, I want to display inside a circle the rating number (out of 10) corresponding to the final progress % of the bar. I want to have a responsive design.
My problem arises when dealing with a high progress %, such as 95%. The circle with the rating value is sent down to the next line. It is also the case when resizing my browser with a progress value such as 75%. With lower values, everything is fine. I tried to play around with negative margin-left and margin-right values for #ratingnumber, which seems to help a bit but still had trouble keeping the rating circle on the progress bar for really high progress %.
I'm looking for the CSS tweak to keep the rating circle on the progress bar for every rating cases.
jsfiddle for 95%: http://jsfiddle.net/4pzm98b0
jsfiddle for 50%: http://jsfiddle.net/z1wtqebj/
<div id="progressbar">
<div id="progress"></div>
<div id="ratingnumber">
9.5
</div>
</div>
body {
background-color: #aaa;
padding: 40px;
}
#progressbar {
width: 100%;
height: 20px;
background-color: white;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
border-radius: 25px;
padding: 3px;
border: 3px solid #666666;
clear: both;
}
#progress {
background: green;
height: 20px;
width: 0%;
max-width: 100%;
float: left;
-webkit-animation: progress 2s 1 forwards;
-moz-animation: progress 2s 1 forwards;
-ms-animation: progress 2s 1 forwards;
animation: progress 2s 1 forwards;
-webkit-border-top-right-radius: 8px;
-webkit-border-bottom-right-radius: 8px;
-moz-border-radius-topright: 8px;
-moz-border-radius-bottomright: 8px;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
-webkit-border-top-left-radius: 20px;
-webkit-border-bottom-left-radius: 20px;
-moz-border-radius-topleft: 20px;
-moz-border-radius-bottomleft: 20px;
border-top-left-radius: 20px;
border-bottom-left-radius: 20px;
}
#ratingnumber{
border: 4px solid green;
background: white;
padding: 10px;
float: left;
font-size: 28px;
font-family: 'Roboto Condensed', sans-serif;
font-weight: bold;
border-radius: 50%;
position: relative;
left: -30px;
top: -24px;
}
#-webkit-keyframes progress {
from { }
to { width: 95% }
}
#-moz-keyframes progress {
from { }
to { width: 95% }
}
#-ms-keyframes progress {
from { }
to { width: 95% }
}
#keyframes progress {
from { }
to { width: 95% }
}

Add white-space: nowrap to the parent element, #progressbar. Then remove float: left from the children elements, and change the display to inline-block in order for them to respect the white-space property on the parent. Set vertical-align: top on the children in order to fix the vertical alignment.
Updated Example
#progressbar {
white-space: nowrap;
}
#ratingnumber, #progress {
display: inline-block;
vertical-align: top;
}
The positioning on the #ratingnumber element also needs to be changed to:
#ratingnumber {
position: relative;
top: -20px;
}

Related

Angular zooming out changes the shape of the badge

So I am using Angular Material badge and I want the shape to be full circle if the content is single digit and zoom out on chrome normally using the zoom or ctrl - / + . However I am either getting an ellipsis as the badge content grows or it is a circle with curved edges for small values and it becomes smaller and not centered as we zoom out.
.nav-link-badge {
#media (min-width: 576px){
display: absolute !important;
align-items: center !important;
width: auto !important;
right: unset !important;
text-align: center !important;
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
font-size: 11px;
font-weight: 600;
border-radius: 20px;
transition: opacity 0.2s ease-in-out 0.1s;
margin-left: 8px;
+ .collapsable-arrow {
margin-left: 8px;
}
}
}
Please suggest how I can get the desired behaviour in Angular badge. thank you
media ( min-width: 576px){
.nav-link-badge {
display: absolute !important;
align-items: center !important;
width: 35px;
height: 35px;
right: unset !important;
text-align: center !important;
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
font-size: 11px;
font-weight: 600;
border-radius: 20px;
transition: opacity 0.2s ease-in-out 0.1s;
margin-left: 8px;
border-radius: 50%;

CSS progress bar animation

I am having a progess bar which should become filled up by 50% width.
This is my current html and css for the progress bar.
HTML:
<div id="ProgressBar">
<div id="Progress"></div>
</div>
CSS:
#ProgressBar {
width: 100%;
height: 30px;
border: 1px solid black;
border-radius: 7px;
padding: 4px;
}
#Progress {
width: 10%;
background-color: #4A90E2;
height: 100%;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
border-color: #4A90E2;
-webkit-transition: width 2s; /* For Safari 3.1 to 6.0 */
transition: width 2s;
}
#Progress:hover {
width: 50%;
}
As you can see the transition is starting after a hover over the progress. My goal is to have this transaition starting directly after the page loads. I know there are some examples in the internet but they are all having fade-in effects only and I can't figure it out.
I appreciate your help.
Here my fiddle:
https://jsfiddle.net/Anokrize/ssL9fjy9/
(I would like to avoid any javascript or jquery, if that is possible)
How about doing it with keyframes, like this:
#ProgressBar {
width: 100%;
height: 30px;
border: 1px solid black;
border-radius: 7px;
padding: 4px;
}
#Progress {
width: 50%;
background-color: #4A90E2;
height: 100%;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
border-color: #4A90E2;
animation-name: progressBar;
animation-iteration-count: 1;
animation-duration: 2s;
}
#keyframes progressBar {
0% {
width: 10%;
}
100% {
width: 50%;
}
}
<div id="ProgressBar">
<div id="Progress"></div>
</div>
A straight forward way of getting this done is through jquery:
$(window).load(function() {
$("#Progress").css("width", "50%");
});
Usually you'd want something feeding a progress bar so it's actually showing progress... but if you just want it to start on load, you can use the animation property with keyframes.
#ProgressBar {
width: 100%;
height: 30px;
border: 1px solid black;
border-radius: 7px;
padding: 4px;
}
#Progress {
width: 10%;
background-color: #4A90E2;
height: 100%;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
border-color: #4A90E2;
animation: progress 1s ease-out forwards;
}
#keyframes progress {
from { width: 10%; }
to { width: 50%; }
}

Manipulation of single <li> items in a <nav><ul></ul></nav>

I am creating a custom side navigation for one of my home projects and I recently was informed that instead of using several <nav> tags and placing them manually I should use a single <nav> and then a list on the inside. This however, has caused issues the replication of the way the side nav I had set up works
The following .css is the code which produces the format of the side navigation
nav {
display: block;
color: black;
padding: 10px;
text-transform: uppercase;
right: 0px;
position: fixed;
z-index: 3000;
width: 20px;
height: 20px;
line-height: 20px;
text-align: center;
-webkit-transition: all 250ms ease-out !important;
-moz-transition: all 250ms ease-out !important;
transition: all 250ms ease-out !important;
border: 1mm;
border-color: #CCCCFF;
border-left-style: solid;
}
#topnav:hover,
#nav2:hover,
#nav3:hover,
#nav4:hover,
#nav5:hover,
#nav6:hover,
#botnav:hover {
z-index: 5000;
width: 3cm;
background-color: black;
border-style: solid;
border-right-style: none;
color: white;
-webkit-border-top-left-radius: 4mm;
-moz-border-radius-topleft: 4mm;
border-top-left-radius: 4mm;
-webkit-border-bottom-left-radius: 4mm;
-moz-border-radius-bottomleft: 4mm;
border-bottom-left-radius: 4mm;
}
nav:hover span {
display: none;
}
#topnav {
top: 100px;
background-color: white;
border-top-style: solid;
-webkit-border-top-left-radius: 4mm;
-moz-border-radius-topleft: 4mm;
border-top-left-radius: 4mm;
}
#topnav:hover:before {
content: "Top";
}
#nav2 {
top: 140px;
background-color: red;
}
#nav2:hover:before {
content: "Red";
}
#nav3 {
top: 180px;
background-color: blue;
}
#nav3:hover:before {
content: "blue";
}
#nav4 {
top: 220px;
background-color: green;
}
#nav4:hover:before {
content: "green";
}
#nav5 {
top: 260px;
background-color: purple;
}
#nav5:hover:before {
content: "purple";
}
#nav6 {
top: 300px;
background-color: orange;
}
#nav6:hover:before {
content: "orange";
}
#botnav {
top: 340px;
background-color: white;
border-bottom-style: solid;
-webkit-border-bottom-left-radius: 4mm;
-moz-border-radius-bottomleft: 4mm;
border-bottom-left-radius: 4mm;
}
#botnav:hover:before {
content: "200";
}
This can be seen put in place on the JSFiddle
Whilst editing my code I have had an issue when you hover over a list item. When the <li> item extends, it extends the <nav> and the <ul> as well. This is not what I intended it to do. I intended it to only extend <li> item.
.sidenav {
display: block;
color: black;
text-transform: uppercase;
right: 0px;
top: 10%;
position: fixed;
z-index: 3000;
text-align: center;
border: 1mm;
border-color: #CCCCFF;
border-style: solid;
border-right-style: none;
-webkit-border-bottom-left-radius: 4mm;
-moz-border-radius-bottomleft: 4mm;
border-bottom-left-radius: 4mm;
-webkit-border-top-left-radius: 4mm;
-moz-border-radius-topleft: 4mm;
border-top-left-radius: 4mm;
}
.sidenav ul {
list-style-type: none;
}
.sidenav li {
padding: 10px;
width: 20px;
height: 20px;
line-height: 20px;
-webkit-transition: all 250ms ease-out !important;
-moz-transition: all 250ms ease-out !important;
transition: all 250ms ease-out !important;
}
.sidenav li:hover {
width: 3cm;
background-color: white;
}
This can be seen put in place in this JSFiddle.
I thought this might be able to be masked by setting the text-align: right and then change the text-align of the <li> item being hovered over, only when it was being hovered over. This works however it then meant the whole of the border moved out instead of only the border around the <li> item being hovered over and the background colours of the <li> items are also extended out instead of just the one being hovered over.
The question
Essentially my question is how do I need to edit my css so that the nav bar which is structured like
<nav>
<ul>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
</ul>
</nav>
behave in the same way my first structure shown in the first JSFiddle did? How can I manipulate a single <li> tag without effecting the whole <ul> or <nav>?
So the reason that the sidenav is expanding when the li elements do, is because there's no explicit width placed on that parent element. So it's defaulting to width: auto. Thus, when the li elements expand, so does the parent. I've got a solution working that approximates your original example.
Here is the updated fiddle.
I only made a few small updates to get it working. Here they are:
.sidenav {
width: 40px;
}
.sidenav li {
position: relative;
right: 0;
}
.sidenav li:hover {
right: 200%;
}
Note, these are styles added in addition to what was already there, nothing removed. Hopefully this at least helps you get on the right path with this new solution!

Bar fill and Bar unfilled doesn't ovelap

I am trying to create a CSS progress bar however for some reason the UNFILL part (white background) doesn't overlap with the green background which is the FILL part.
Any idea how to make it like that?
Also which browser this should ONLY or WILL NOT work for since this is a #Keyframe CSS3?
CSS:
.container{
width: 400px;
margin: 0 auto;
}
.bar{
width: 100%;
background: #141414;
padding: 17px;
-webkit-border-top-right-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
-moz-border-radius-topright: 5px;
-moz-border-radius-bottomright: 5px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
.bar-fill{
height: 15px;
display: block;
background: #45c9a5;
width: 0%;
border-radius: 8px;
-webkit-transition: width 0.8s ease;
transition: width 0.8s ease;
-webkit-animation: mymove 5s infinite;
animation: mymove 5s infinite;
}
.bar-unfill{
height: 15px;
display: block;
background: #fff;
width: 100%;
border-radius: 8px;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes mymove {
from {width: 0%;}
to {width: 100%;}
}
/* Standard syntax */
#keyframes mymove {
from {width: 0%;}
to {width: 100%;}
}
.title{
background: #545965;
color: #fff;
padding: 15px;
float: left;
position: relative;
right: 60px;
-webkit-border-top-left-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-bottomleft: 5px;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
Here is the JSFIDDLE: https://jsfiddle.net/xdbb3ypc/1/
Thanks!
Please provide JSFIDDLE ALSO
Just position 'filled' part inside 'unfilled', ie something like that:
<div class="container">
<div class="title">Testing</div>
<div class="bar">
<span class="bar-unfill">
<span class="bar-fill"></span>
</span>
</div>
</div>
you should position the filled bar inside the unfilled bar, to allow it to be drawn on top of it
<div class="container">
<div class="title">Testing</div>
<div class="bar">
<span class="bar-unfill">
<span class="bar-fill"></span>
</span>
</div>
</div>
JSFiddle: https://jsfiddle.net/z4kn3p40/

Need a loading icon to show on a mouseclick with just CSS

Is there a way to get a loading icon to show when a button/link is clicked, with just CSS/HTML?
I'm using FontAwesome so I figured I could use their classes to spin a loading icon, but I can't find a way to get it to spin after a specific action (mouseclick).
Basically this is all the code:
<i class="fa fa-circle-o-notch fa-spin"></i> Spin
The only way I could manage now was hiding it in background color.. but that doesn't seem very professional:
body {
background: none repeat scroll 0 0 #dcdcdc;
color: white;
}
.fa {
color: #dcdcdc;
}
a:active .fa {
color: red;
}
Any suggestions?
If an element that looks like a button is acceptable, you can do this with CSS as long as you don't need to support IE8. It works by using a label "for" a checkbox or radio as your button. Then, the :checked CSS pseudo class does the trick!
This example sets the background color of a div, but you can set whatever properties you need.
label {
display: inline-block;
background-color: #28529c;
color: white;
padding: 4px 8px;
}
#loading {
background-color: transparent;
width: 20px;
height: 20px;
}
#hidden-flag {
display: none;
}
#hidden-flag:checked ~ #loading {
background-color: green;
display: inline-block;
padding-left: 10px;
}
<input id="hidden-flag" type="radio">
<label for="hidden-flag">Button</label>
<div id="loading"></div>
Needs a bit of work, But as I'm off to beddy byes now I'm not carrying on with it, Up early tomorrow. Pure css sort of unfinished example. When the new page is loaded just bring in a new set of buttons to click.
#to_click:visited {
content:"";
display: block;
float: left;
position: relative;
margin: 40px 30px;
border-radius: 100px;
width: 20px;
height: 20px;
border: 5px solid #57E;
border-top-color: transparent;
border-bottom-color: transparent;
animation-name: rotateclock;
animation-duration: .75s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
#to_click:before {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
border-radius: 100px;
width: 10px;
height: 10px;
border: 5px solid #57E;
border-left-color: transparent;
border-right-color: transparent;
}
#to_click:after {
content: "";
display: block;
position: absolute;
top: 5px;
left: 5px;
border-radius: 100px;
width: 0px;
height: 0px;
border: 5px solid #57E;
border-top-color: transparent;
border-bottom-color: transparent;
}
#keyframes rotateclock {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
Click Me