Bootstrap 4 Progress bar alignment - html

I'm trying to create a rating indicator using bootstrap 4 progress bar. Following is what I'm trying to achieve. However bootstrap progress bar using flex hence I can't align the text in the left and right.
JSFiddle
HTML
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<div class="review__rating__stats">
<span class="review__rating__progress">
<span class="review__rating__level">5 Star</span>
<span class="progress">
<span class="progress-bar" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></span>
</span>
<span class="review__rating__count">68</span>
</span>
</div>
</div>
</div>

You might have to set a width for .review__rating__count. The "3" was causing the misalignment because it's a single digit, whereas other counts are double digits, which take up more spaces.
Now you can even set .review__rating__stats as flexbox, then use flex: to set a default width for .review__rating__count.
Layout
<div class="container">
<div class="row">
<div class="col-12 col-md-6">
<div class="review__rating__stats">
<div class="review__rating__progress">
<strong class="review__rating__level">5 Star</strong>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 68%"
aria-valuenow="68" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<strong class="review__rating__count">68</strong>
</div>
<div class="review__rating__progress" />
...
</div>
</div>
</div>
</div>
Styles
.review__rating__progress {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
}
.review__rating__progress .review__rating__level,
.review__rating__progress .review__rating__count {
/* 10% is the default width for the level and count labels */
flex: 1 1 10%;
}
.review__rating__progress .review__rating__level {
text-align: right;
}
.review__rating__progress .progress {
margin: 0.25rem 1rem;
flex-grow: 8;
}
Result
demo: https://jsfiddle.net/davidliang2008/j4y70wfz/36/

Put each progress bar in row like such:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<div class="container review__rating__stats">
<div class="row review__rating__progress">
<span class="col-sm-2 review__rating__level">5 Star</span>
<div class="col-sm-9 align-self-center">
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<span class="col-sm-1 review__rating__count">68</span>
</div>
</div>
</div>
</div>
Note that the div that contains the progress bar must have the align-self-center class otherwise it won't be vertically centered.

Related

How can I align the last element of a flexbox to the right with taking into account space-around?

I have a flex-div with 7 elements in it.
<div class="d-flex flex-wrap justify-content-around">
<div style="width: 350px">
[...]
</div>
[6 more identical divs]
</div>
On large screens, there are 3 divs in each row, on medium screens 2 and on small screens only 1. The last element is always centered but I want it to be aligned right. I tried margin-left: auto on the last element but due to justify-content-around there should be space on the right (first 2 rows on large screens, first 3 rows on medium screens). Unfortunately, margin-left: auto pushes the last element all the way to the right without the space from justify-content-around. How can I position the last element exactly as if it was an element of the right column?
.d-flex {
display: flex
}
.flex-wrap {
flex-wrap: wrap
}
.justify-content-around {
justify-content: space-around
}
.card {
border: 1px solid rgba(0, 0, 0, .125)
}
.ml-auto {
margin-left: auto
}
<h3>
Without margin-left: auto
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card" style="width: 200px">
1
</div>
<div class="card" style="width: 200px">
2
</div>
<div class="card" style="width: 200px">
3
</div>
<div class="card" style="width: 200px">
4
</div>
<div class="card" style="width: 200px">
5
</div>
<div class="card" style="width: 200px">
6
</div>
<div class="card" style="width: 200px">
7 is centered
</div>
</div>
<h3>
With margin-left: auto
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card" style="width: 200px">
1
</div>
<div class="card" style="width: 200px">
2
</div>
<div class="card" style="width: 200px">
3
</div>
<div class="card" style="width: 200px">
4
</div>
<div class="card" style="width: 200px">
5
</div>
<div class="card" style="width: 200px">
6
</div>
<div class="card ml-auto" style="width: 200px">
7 is too far to the right
</div>
</div>
It goes from
1 2
3 4
5 6
7 8
For 7 to come under 6 is tricky, but lets say thats not what you meant, and just want to align the 7 to left side.
Let's start removing all these style=width, If you ever want to edit the width of div you would need to edit every single div, dumping it into the CSS is much more efficient.
<div class="card">
4
</div>
This is the adjusted CSS
.flex-wrap {
flex-wrap: wrap;
}
.justify-content-around {
justify-content: space-between;
display: flex;
}
.card {
border: 1px solid rgba(0, 0, 0, 0.125);
width: 200px;
}
If you want it aligned on the right then you can use JS but its difficult, since you use justify it might conflict.
The following solution works, if the element and the parent width are constant, i. e. you know, when there are 1 or 2 or 3 columns:
.d-flex {
display: flex
}
.flex-wrap {
flex-wrap: wrap
}
.justify-content-around {
justify-content: space-around
}
.card {
width: 200px
}
.ml-auto {
margin-left: auto
}
.d-none {
display: none
}
.border {
border: 1px solid rgba(0, 0, 0, .125);
}
#media (min-width:500px) {
.d-lg-flex {
display: flex
}
}
#media (min-width:700px) {
.d-xl-flex {
display: flex
}
}
<h3>
Centered
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card border">
1
</div>
<div class="card border">
2
</div>
<div class="card border">
3
</div>
<div class="card border">
4
</div>
<div class="card border">
5
</div>
<div class="card border">
6
</div>
<div class="card border">
7 is centered
</div>
</div>
<h3>
With margin-left: auto
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card border">
1
</div>
<div class="card border">
2
</div>
<div class="card border">
3
</div>
<div class="card border">
4
</div>
<div class="card border">
5
</div>
<div class="card border">
6
</div>
<div class="card border ml-auto">
7 is too far to the right
</div>
</div>
<h3>
Correct position
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card border">
1
</div>
<div class="card border">
2
</div>
<div class="card border">
3
</div>
<div class="card border">
4
</div>
<div class="card border">
5
</div>
<div class="card border">
6
</div>
<div class="card d-none d-lg-flex"></div>
<div class="card d-none d-xl-flex"></div>
<div class="card border">
7 is now at correct position
</div>
</div>
Instead of min-width:500px and min-width:700px in the media queries, use the bootstrap ones: min-width:992px and min-width:1200px. I just needed the smaller values for the snippet. Or simply use <div class="data-box d-none d-lg-flex"></div> and <div class="data-box d-none d-xl-flex"></div> for the placeholder-divs.
While other answers here are better, You should be tricky and smart,
you can create another element ,say div 8,now
Change
<div class="card" style="width: 200px">8</div> to
<div class="space" style="width: 200px"></div>
Place this div before div 7
What have we done?
We have removed all content inside that div(removed 8 from it)
We have changed class card to space, this removes the border property we apply in css(We can even remove the class instead of changing)
.card {
border: 1px solid rgba(0, 0, 0, .125);/*removed to our element 8*/
}
Your code
Note: I have added just 1 line of code,in html
.d-flex {
display: flex
}
.flex-wrap {
flex-wrap: wrap
}
.justify-content-around {
justify-content: space-around
}
.card {
border: 1px solid rgba(0, 0, 0, .125)
}
<h3>
Without margin-left: auto
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card" style="width: 200px">
1
</div>
<div class="card" style="width: 200px">
2
</div>
<div class="card" style="width: 200px">
3
</div>
<div class="card" style="width: 200px">
4
</div>
<div class="card" style="width: 200px">
5
</div>
<div class="card" style="width: 200px">
6
</div>
<div class="space" style="width: 200px"></div><!--I HAVE ADDED ONLY THIS LINE-->
<div class="card" style="width: 200px">
7
</div>
</div>
As of your original question,
"but due to justify-content-around",
You get problem when using margin-left: auto because of, justify-content- around.
The solution is to use justify-content-space-between
Snippet:
.d-flex {
display: flex
}
.flex-wrap {
flex-wrap: wrap
}
.justify-content-around {
justify-content: space-between;
margin: auto;
}
.card {
border: 1px solid rgba(0, 0, 0, .125)
}
.card:last-child{
margin-left: auto
}
<div class="d-flex flex-wrap justify-content-around">
<div class="card" style="width: 200px">
1
</div>
<div class="card" style="width: 200px">
2
</div>
<div class="card" style="width: 200px">
3
</div>
<div class="card" style="width: 200px">
4
</div>
<div class="card" style="width: 200px">
5
</div>
<div class="card" style="width: 200px">
6
</div>
<div class="card" style="width: 200px">
7
</div>
</div>
Note: If you need space-around also,then use margin or fixed width,or even another parent div to make it center!

html flexbox 2 elements vertical and one on the left [duplicate]

This question already has answers here:
Left column and stacked right column using flexbox CSS [duplicate]
(2 answers)
Closed 2 years ago.
I am totally lost with flexbox for css3, and I cannot seem to figure out how to get it correctly working :(.
I want a layout like:
|-----| |----|
------- |----|
|-----| |----|
(Where |----| on the left are 2 divs an on the right its one)
And on mobile I want the right div to below the other 2 divs...
And I cannot seem to figure it out.
It just will not line up correctly, or the 2 divs on the left will not be as large as the one on the right.
I am using bootstrap 4.0 for this... so maybe that is something?
The following code I am currently at:
There is a container div around it
<div id="container">
<div class="d-flex row">
<div class="flex-row flex-fill">
<div class="d-flex flex-column">
<div class="card d-flex flex-fill">
<div class="card-body">
<form>
<div class="form-group">
<label>xxx</label>
<input type="text" class="form-control date" id="birthdatepicker" data-toggle="daterangepicker" data-single-date-picker="true">
</div>
<button type="submit" class="btn btn-primary waves-effect waves-light">{{ __('Submit') }}</button>
</form>
</div>
</div>
<div class="card d-flex flex-fill mb-4 mb-md-0">
<div class="card-body">
<h4 class="card-title">{{ __('Progress') }}</h4>
<div class="progress mb-2">
<div class="progress-bar bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</div>
</div>
</div>
<div class="flex-row col-12 col-md-4 col-lg-2">
<div class="d-flex flex-fill card mb-4 mb-md-0">
<div class="card-body">
<h5>xx</h5>
<p>
xx
</p>
</div>
</div>
</div>
</div>
</div>
here is a simple example of what i think you wish to achive.
.flexbox{
display: flex;
flex-direction: row;
width: 400px;
height: 400px;
}
#media only screen and (max-width: 478px){
.flexbox{
flex-direction: column;
}
}
.left{
width: 50%;
height: 100%;
}
.top-left{
height: 50%;
width: 100%;
position: relative;
background: red;
}
.bottom-left{
height: 50%;
width: 100%;
position: relative;
background: green;
}
.right{
width:50%;
height:100%;
}
.center-right{
width: 100%;
height: 100%;
background: blue;
}
<div class="flexbox">
<div class="left">
<div class="top-left">
</div>
<div class="bottom-left">
</div>
</div>
<div class="right">
<div class="center-right">
</div>
</div>
</div>

Visualization not expected in safari

Hi I would like to share the following code:
<div class="row full-width full-height wrapper-container">
<div class="row full-width" style="flex: 0 0 auto;">...Items here...</div>
<div class="row full-width wrapper-fullfill" style="flex: 1 1 auto; margin-top: 0.5rem;">
<div ng-class="showList" class="row col-xs-12 col-sm-7 col-lg-8 wrapper-container">
<div class="row full-width dropdown-places-type-mobile">
<div class="input-container col-xs-12 no-padding" style="display:inline-block;">
<div class="text-info text-info-menu" type="text" dropdown-menu="placesType" dropdown-model="placeType">Tipo de espacios</div>
<img src='../images/arrow-select-primary.png' class="input-icon-menu" />
</div>
</div>
<div class="row full-width wrapper-fullfill" style="overflow-y:scroll; padding:0;">
<div class="row col-xs-12">
<div ng-repeat="place in places" class="col-xs-12 col-sm-6 col-lg-4">
<div ng-include="'./views/items/place-card.html'">
</div>
</div>
</div>
</div>
</div>
<div ng-class="showMap" class="col-xs-12 col-sm-5 col-lg-4" style="overflow: hidden; padding:0;">
<ui-gmap-google-map ng-if="showMapMobile" center='map.center' zoom='map.zoom' options='map.options'>
<ui-gmap-markers fit="true" models="placeMarkers" coords="'self'" icon="'icon'" options="'options'">
</ui-gmap-markers>
</ui-gmap-google-map>
</div>
</div>
</div>
Here the css for wrapper-container and wrapper-fullfill:
.wrapper-container {
flex-direction: column;
flex-flow: column;
}
.wrapper-fullfill {
flex-grow: 1;
}
I have a flex wrapper-container and inside a wrapper-fullfill class to fullfill al the remaining space until cover all the div with the element.
The problem is that in Chrome and Firefox the behaviour is the expected one, but in Safari the nested wrapper-container is not working as expected.
I would like to know if you could help me to find a solution for that. I am really stuck on this.
Here you can find the full code of the page with the css and the html elements:
http://test.nomadespacios.com/#!/places
Thank you very much in advance.

bootstrap center progressbar on div

I'm trying to use a Bootstrap progress bar as a loading indicator, and I want the progress bar to be a certain width with the whole thing centered in the DIV. But the progress bar doesn't seem to like being centered.
When I do:
<div class="text-center">
<img src="~/Content/Images/loading.gif" style="height:80px;" />
</div>
The image is centered properly. But when I substitute it for a progress bar, it goes to the left:
<div class="text-center">
<div class="progress" style="width:200px;"> <!-- set to certain width -->
<div class="progress-bar progress-bar-striped active" role="progressbar" style="width: 100%;">
<span>
Loading...
</span>
</div>
</div>
</div>
Bootply Demo
I want the progress bar to display centered.
This bit of css worked for me.
.progress { margin-left: auto; margin-right:auto; }
Or, you can just use Bootstrap's center-block class
<div class="text-center">
<div class="progress center-block" style="width:200px;"> <!-- set to certain width -->
<div class="progress-bar progress-bar-striped active" role="progressbar" style="width: 100%;">
<span>
Loading...
</span>
</div>
</div>
</div>
http://www.bootply.com/a0SXqv3g6N
Just want to enhance the Marcelo answer, for those who are new to CSS (like me)
Remember to check the class in which your progress bar is located:
For me the progress bar was in "download > progress" class like:
<div id="download" class="download">
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="main_slider" class="carousel slide banner-main" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<h3>Programming languages 1</h3>
<div class="progress" style="width: 50%">
So in my style.css I have added Marcelo answer, below the download css like this
.download {
padding-top: 90px;
padding-bottom: 90px;
background: #fff;
}
.download .progress { margin-left: auto; margin-right:auto; }
and it worked, so do not be afraid of CSS, keep on taking Panga(challenges) with code ;)

Why doesn't my Bootstrap 3 row fill the parent width?

I'm trying to use Bootstrap 3 to make a grid-based template for a modal (which I'm also using Bootstrap for). The modal appears, and all the content is there ... but the styling is off. It looks like the row classes don't fill their parent containers, even though there's no styling that should make that happen. Here's a screenshot - you can see that neither the row in the header nor the row in the body take the width of their parent. I've tried poking around other SO posts for information, but I can't seem to find anything on why a row wouldn't fill its parent width.
Update:
Here's a JSFiddle. It looks like it actually works on JSFiddle ... which means it's not a problem with the immediate template, so I'm looking into other possible causes. Thanks for the tip, calvin!
HTML
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header ht-modal-header">
<h1>
Bombay Teen Challenge
</h1>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
<address>
1 Chium Village, Ambedkar Road<br/>
Bandra West<br/>
Mumbai 400052
</address>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<abbr>e: </abbr> kkdevaraj#bombayteenchallenge.org<br/>
<abbr>p: </abbr> +91 22 2604 2242
</div>
</div>
</div>
<div class="modal-body ht-modal-body">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="types">
<span class="prevention-label"></span> Prevention, Education, Teen
</div>
<div class="facebook">
<span class="fa fa-facebook-square fa-2x"></span> BombayTeenChallenge
</div>
<div class="twitter">
<span class="fa fa-twitter-square fa-2x"></span> #BombayTC
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="people">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
<label>People: </label>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
Dr. Rama R. Rao<br/>
Monte Hackney
</div>
</div>
</div>
<div class="partners">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
<label>Partners: </label>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
None Available
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
LESS
.prevention-label {
width: 24px;
height: 24px;
line-height: 24px;
display: inline-block;
background-color: #4ECDC4;
}
.ht-modal-header {
a {
&:hover, &:focus {
color: white;
}
color: white;
}
color: white;
background: linear-gradient(#ht-teal, darken(#ht-teal, 5%));
background: -webkit-gradient(#ht-teal, darken(#ht-teal, 5%));
background: -o-linear-gradient(#ht-teal, darken(#ht-teal, 5%));
background: -moz-linear-gradient(#ht-teal, darken(#ht-teal, 5%));
}
If you nest rows in columns you must understand that inside a .col-lg-6 .row the whole thing starts new (at 100%) and for you you to fill it have to use .col-lg-12 inside of it.
This snippet should work for you
<div class="col-sm-6">
<div class="people">
<div class="row">
<div class="col-sm-12">
<label>People: </label>
</div>
<div class="col-sm-12">
Dr. Rama R. Rao<br/>
Monte Hackney
</div>
</div>
</div>
<div class="partners">
<div class="row">
<div class="col-sm-12">
<label>Partners: </label>
</div>
<div class="col-sm-12">
None Available
</div>
</div>
</div>
</div>