Custom Progress Bar Html and CSS layout - html

I'm trying to make a 'custom' progress bar with numbers at each end of the progress bar. Left hand number being the current value, and the right hand side being the max/target value. I've got it so that I'm showing the two numbers but I can't seem to position the right hand number correctly.
What I'm trying to achieve is...
and what I currently have is...
This is what I currently have code wise...
JSFiddle
.progress-outer {
width: 96%;
margin: 10px 2%;
padding: 3px;
text-align: center;
background-color: #f4f4f4;
border: 1px solid #dcdcdc;
color: #fff;
border-radius: 20px;
}
.progress-inner {
min-width: 15%;
white-space: nowrap;
overflow: hidden;
padding: 5px;
border-radius: 20px;
background-color: orange;
}
.progressBarCurrent {
color: black;
float: left;
}
.progressBarGoal {
color: black;
float: right;
}
<div class="progress-outer">
<div class="progress-inner" style="width:27%;">
<span class="progressBarCurrent">50g</span>
<span class="progressBarGoal">180g</span>
</div>
</div>
I've tried putting the the second span outside the the progress inner div but then moves the text outside the whole thing and I couldn't work out how to move it into the correct place.
Can anyone help?

I have an interesting solution using linear-gradients, its pretty close, try playing around with the margins and outline to get border right.
.progress-outer {
width: 96%;
display: flex;
height: 35px;
margin: 10px 2%;
text-align: center;
border: 1px solid #dcdcdc;
background-image: linear-gradient( 80deg, orange 37% , #f4f4f4 37% );
border-radius: 20px;
justify-content: center;
align-items: center;
}
.progressBarCurrent {
color: black;
text-align: left;
width: 50%;
position: relative;
margin: 0px;
margin-left: 20px;
}
.progressBarGoal {
color: black;
position: relative;
text-align: right;
width: 50%;
margin: 0px;
margin-right: 20px;
}
<div class="progress-outer">
<span class="progressBarCurrent">50g</span>
<span class="progressBarGoal">180g</span>
</div>

Instead of float:left you can use position:absolute
.progress-outer {
width: 96%;
margin: 10px 2%;
padding: 3px;
text-align: center;
background-color: #f4f4f4;
border: 1px solid #dcdcdc;
color: #fff;
border-radius: 20px;
position: relative;
}
.progress-inner {
min-width: 15%;
white-space: nowrap;
overflow: hidden;
padding: 5px;
border-radius: 20px;
background-color: orange;
}
.progressBarCurrent {
color: black;
float: left;
}
.progressBarGoal {
color: black;
position: absolute;
right: 5px;
}
<div class="progress-outer">
<div class="progress-inner" style="width:27%;">
<span class="progressBarCurrent">50g</span>
<span class="progressBarGoal">180g</span>
</div>
</div>

Related

CSS text not centered properly because of the object location

I want to have my text in the middle. Since I added the element in the same line, the text offsets towards the right.
My code looks like this:
.property {
background-color: #497ba7;
color: #ffff;
text-align: center;
margin-left: 50px;
margin-right: 50px;
padding: 5px;
}
.navbtntop {
cursor: pointer;
float: left;
font-size: 20px;
background-color: #497ba7;
color: #fff;
border-color: rgba(0, 0, 255, 0.082);
border-radius: 3px;
text-decoration: none;
padding: 7px;
width: 20%;
text-align: center;
margin-left: 5.5%;
}
Previous
<h2 class="property">MDU Layout</h2>
Where is the problem then?
cols layout
Your idea (Keep the right col "center" to all wrapper area).
One way is by using one "empty" div (20% - 60% - 20%).
The other way is to add margin-right: 20%; for the right col.
.display_grid{
display: grid;
border: 2px solid orange;
grid-template-columns: 20% auto 20%;
}
.left {
border: 1px solid black;
display: block;
background-color: red;
padding: 20px;
color: #fff;
text-align: center;
}
.right {
background-color: blue;
color: #ffff;
text-align: center;
border: 1px solid red;
margin: 0px;
}
<div class="display_grid">
Left
<h2 class="right">Right</h2>
<div>
</div>
position absolute
One more way to achieve this is by position absolute (Old approach - but in your case, if the "left col" width/content change Maybe there is no choice).
Cons: less responsive + the text could overlap.
.relative_wrapper{
display: grid;
position: relative;
border: 2px solid orange;
grid-template-columns: 20% auto;
}
.left {
border: 1px solid black;
display: block;
background-color: red;
padding: 20px;
color: #fff;
text-align: center;
}
.right {
background-color: blue;
color: #ffff;
text-align: center;
border: 1px solid red;
margin: 0px;
/* position absolute */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="relative_wrapper">
Left
<h2 class="right">Right</h2>
<div>
</div>
https://medium.com/front-end-weekly/absolute-centering-in-css-ea3a9d0ad72e

Stop the text moving down on hover

I have a text in the middle of the div block with a font size 80px. When I hover on the div block, it will change the border size from 1px to 5px with a blue color but the text will moves down.
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
.calendarday-number:hover {
margin: 12px 2px;
}
.calendarday-container:hover {
border: 5px solid #2e7ad1;
}
.add-day-ico {
display: none;
width: 21px;
height: 21px;
margin: 22px 0px;
float: right;
}
.calendarday-container:hover .add-day-ico {
display: block;
margin: 22px 0px;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" sytle="height: 21px; width: 21px;" align="right" style="margin-top: 3px;" class="add-day-ico">
</a>
</div>
Jsfiddle: http://jsfiddle.net/f0k6r9nb/
I have tried to change the margin in the calendarday-container:hover .add-day-ico but it didn't help to resolve the issue.
Can you please show me an example how I can stop the text moving down on hover?
Thank you.
Changing the width of the border from 1px to 5px and recalculating the inner parts is not a practical solution. You could use an additional element, which has 5px of transparent border and change it to 5px of colored border on hover.
Another simple solution would be to use outline instead, as it doesn't add to the elements dimensions:
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-container:hover {
outline: 5px solid #2e7ad1;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
.add-day-ico {
opacity: 0;
width: 21px;
height: 21px;
position: absolute;
bottom: 0;
right: 0;
}
.calendarday-container:hover img {
opacity: 1;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" class="add-day-ico">
</a>
</div>
A typical approach to showing a border on hover is to have the non-hover state be transparent or a color that matches the background along with the width matching that of the border when hovered.
In this case, there's an existing 1px border. Here, I would change the gray border blue, then use an inset box-shadow to add the additional 4px of the border.
Note: I also removed some margin for .calendarday-number on hover so the number does not shift.
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
/*
.calendarday-number:hover {
margin: 12px 2px;
}
*/
.calendarday-container:hover {
border-color: #2e7ad1;
box-shadow: inset 0 0 0 4px #2e7ad1;
}
.add-day-ico {
display: none;
width: 21px;
height: 21px;
margin: 22px 0px;
float: right;
}
.calendarday-container:hover .add-day-ico {
display: block;
margin: 22px 0px;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" sytle="height: 21px; width: 21px;" align="right" style="margin-top: 3px;" class="add-day-ico">
</a>
</div>
Add this:
.calendarday-container {
border: 5px solid transparent;
outline: 1px solid #ccc;
outline: none;
}
.calendarday-container:hover {
outline: none;
}
Remove this:
.calendarday-number:hover {
margin: 12px 2px;
}
You can use a pseudo element like this. I also removed lot of unnecessary css that was fighting each other
* { margin: 0; padding: 0; box-sizing: border-box; }
body { margin: 5%; }
/* Normal */
.calendarday-container {
width: 150px; height: 150px;
position: relative;
display: flex; align-items: center; justify-content: center;
}
.calendarday-container:after {
content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0;
border: 1px solid #ccc; z-index: -1;
}
.caldndarday-add { text-decoration: none; }
.calendarday-number { font-size: 80px; color: #ccc; }
.add-day-ico { width: 24px; height: 24px; position: absolute; bottom: -8px; right: -8px; }
/* Hover FX */
.calendarday-container:hover:after { border: 10px solid navy; }
.calendarday-container:hover .calendarday-number { color: navy; }
<div class="calendarday-container" data-day="0" data-dropable="true">
<a class="caldndarday-add" href="/autoresponder/create_day.php?day=0" data-action="click">
<span class="calendarday-number">0</span>
<img class="add-day-ico" src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png">
</a>
</div>
The text was moving down because, There was increase in border-width from 1px to 5px while hover.
You can either maintain a outline around the box using outline property, and keeping the border: 5px solid transparent to border: 5px solid #2e7ad1 while hovering.
I've created a working fiddle for you, for better understanding: Link to Jsfiddle

html button has excess whitespace above due to text content

So I have the following code below.
.innerDiv1 {
display: inline-block;
width: 45%;
border-right: 1px solid;
padding-right: 5px
}
.innerDiv2 {
display: inline-block;
width: 45%;
padding-left: 5px;
}
.inner2 {
border: 1px solid black;
}
.rect {
width: 0%;
height: 20px;
background-color: #4CAF50;
text-align: center;
line-height: 30px;
color: black;
font-size: 12;
}
.sendreceiveBtn {
height: 25px;
width: 100%;
font-size: 12px;
max-height: 25px;
}
<div>
<div class="inlineItems" id="progBtnBar">
<div class="innerDiv1">
<div class="inner2">
<div id="myProgress">
<div class="rect">0%</div>
</div>
</div>
</div>
<div class="innerDiv2">
<button class=sendreceiveBtn>Transmit</button>
</div>
</div>
</div>
I need to line up a button vertically with another div, with both as inline-block inside another div, so they end up next to eachother, preferably the exact same size. However, something about the button is pushing it down a bit. Nothing I have done so far has been able to change this EXCEPT for increasing the font of the text in the button. What is making this space, and how can I get these to line up?
this is the culprit:
.rect {
line-height: 30px;
}
Vertical align allows multiple siblings to share the same vertical position.
.innerDiv1 {
display: inline-block;
width: 45%;
border-right: 1px solid;
padding-right: 5px
vertical-align: middle;
}
.innerDiv2 {
display: inline-block;
width: 45%;
padding-left: 5px;
vertical-align: middle;
}
You can see a working example in the following jsfiddle: https://jsfiddle.net/gkotxdt7/
Replace Your existing CSS with below:
.innerDiv1 { display: table-cell; width: 45%; border-right: 1px solid; padding-right: 5px; vertical-align: middle; }
.innerDiv2 { display: table-cell; width: 45%; padding-left: 5px; vertical-align: middle; }
.inner2 { border: 1px solid black; }
.rect { width: 0%; height: 20px; background-color: #4CAF50; text-align: center; line-height: 30px; color: black; font-size: 12; }
.sendreceiveBtn { min-height: 25px; width: 100%; font-size: 12px; height: auto; }
#progBtnBar{
display: table;
width: 100%;
height: auto; }
Thats it. It will resolve the issue.

How can I get three bits of text to line up left, right, and centre using HTML and CSS?

I have been trying to get three bits of text (styled to look like buttons) to line up left, centre, and right using HTML and CSS, no Flexbox or JS, but without success. How can this be achieved? This is what I need:
Here is my code:
#row1 {padding: 20px 20px 5px 20px;
overflow: hidden; }
.button-container {display: block; text-align: center;}
.button-left {
padding: 0 5px;
text-align: center;
border: 1px solid;
float: left;
font-size: 75%; }
.button-right {
padding: 0 5px;
text-align: center;
border: 1px solid;
float: right;
font-size: 75%; }
.button-centre {
padding: 0 5px;
text-align: center;
border: 1px solid;
font-size: 75%; }
<div id="row1">
<div class="button-container">
<span class="button-left">previous</span>
<span class="button-centre">issue</span>
<span class="button-right">next</span>
</div><!--close button-container">
</div><!--close r1-->
Flexbox is ideal for this type of a problem:
#row1 {
padding: 20px 20px 5px 20px;
overflow: hidden;
}
.button-container {
display: flex; /* displays flex-items (children) inline */
justify-content: space-between; /* MDN: The items are evenly distributed within the alignment container along the main axis. The spacing between each pair of adjacent items is the same. */
align-items: center; /* centers them vertically */
}
.button-left {
padding: 0 5px;
text-align: center;
border: 1px solid;
font-size: 75%;
}
.button-right {
padding: 0 5px;
text-align: center;
border: 1px solid;
font-size: 75%;
}
.button-centre {
padding: 0 5px;
text-align: center;
border: 1px solid;
font-size: 75%;
}
<div id="row1">
<div class="button-container">
<span class="button-left">previous</span>
<span class="button-centre">index</span>
<span class="button-right">next</span>
</div>
</div>
Alternative without Flexbox:
* {margin: 0; padding: 0; box-sizing: border-box}
#row1 {padding: 20px 20px 5px 20px}
.button-container {position: relative}
.button-left {
position: absolute;
left: 0;
padding: 0 5px;
text-align: center;
border: 1px solid;
font-size: 75%; }
.button-right {
position: absolute;
right: 0;
padding: 0 5px;
text-align: center;
border: 1px solid;
font-size: 75%; }
.button-centre {
position: absolute;
left: calc(50% - 17px);
padding: 0 5px;
text-align: center;
border: 1px solid;
font-size: 75%; }
<div id="row1">
<div class="button-container">
<span class="button-left">previous</span>
<span class="button-centre">issue</span>
<span class="button-right">next</span>
</div>
</div>
Changes made: .button-container {position: relative}, also added position: absolute to all the children with appropriate values of the left and right properties, for the middle child the value of the left property calc(50% - 17px) is calculated based on it's width (padding and border included) which is 34px divided by 2 and deducted from 50%.
HTML
<div id="row1">
<div class="button-container">
<span class="button">previous</span>
<span class="button">index</span>
<span class="button">next</span>
</div><!--close button-container">
</div><!--close r1-->
CSS
#row1 {
padding: 20px 20px 5px 20px;
overflow: hidden;
}
.button-container {display: block; text-align: center;}
.button {
padding: 0 5px;
text-align: center;
border: 1px solid;
font-size: 75%; }
You can use Flexbox, assuming you just want all the buttons to be next to each other you can give your .button-container the property display:flex;.
Here's a JSFiddle.
Your button container is already a block level element, since you are using a <div> so you don't need the display:block
.btns {
position: relative;
display: inline-block;
font-size: 0;
}
.btns a {
position: relative;
display: inline-block;
text-decoration: none;
background-color: #F4F4F4;
color: #000;
font-size: 14px;
padding: 5px 15px;
transition: all .3s ease-in-out;
}
.btns a:hover {
background-color: #777;
color: #FFF;
}
.btns a:first-child {
border-radius: 10px 0 0 10px;
border-right: 1px solid #CCC;
}
.btns a:last-child {
border-radius: 0 10px 10px 0;
border-left: 1px solid #CCC;
}
<div class="btns">
Previous
Index
Next
</div>
Simplest way would be to just add a <br>tag after each button, line this:
<div id="row1">
<div class="button-container">
<span class="btns button-left">previous</span>
<br>
<span class="btns button-centre">index</span>
<br>
<span class="btns button-right">next</span>
<br>
</div><!--close button-container">
</div><!--close r1-->

Three divs showing on hover css

I have 3 divs and each should have a hover function to show text over the background image.
That works, sort of.... What is happening is when you hover over one all three show the text. How can I fix it so only the one being hovered over shows?
For the css
.circleBase {
border-radius: 50%;
width: 185px;
height: 185px;
border: 2px solid black;
background-color: #fff;
margin: 0 auto;
}
.c1 {
margin: 0 auto;
float: left;
height: 185px;
width: 185px;
background: url(../images/pencil2.png) no-repeat center center;
background-color: #fff;
border: solid red 1px;
}
.c2 {
margin: 0 auto;
float: left;
height: 185px;
width: 185px;
background: url(../images/up.png) no-repeat center center;
background-color: #fff;
border: solid red 1px;
}
.c3 {
margin: 0 auto;
float: left;
height: 185px;
width: 185px;
background: url(../images/email.png) no-repeat center center;
background-color: #fff;
border: solid red 1px;
}
.hidden1 {
font-size: 20px;
color: black;
display: none;
margin-top: 75px;
}
.hidden2 {
font-size: 20px;
color: black;
display: none;
}
.hidden3 {
font-size: 20px;
color: black;
display: none;
}
.full:hover .hidden1{
display: block;
}
.full:hover .hidden2{
display: block;
}
.full:hover .hidden3{
display: block;
}
For the html I have
<div class="full">
<div class="box"><div class="circleBase c1">Web Design</div></div>
<div class="box"><div class="circleBase c2">SEO Services</div></div>
<div class="box"><div class="circleBase c3">Contact Us</div></div>
</div>
Thanks for reading!
Jim
Make sure you qualify correctly which div is being hovered in the selector, something like this:
.box:hover a{display:inline; /*or any value except none */ }
You were probably using the .full class, or just div