javascript - Divide elements width depending on amount of elements -


"Divide the width of elements based on the amount of elements" as the title "I need a progress bar where I I can add element and the progress bar divided by me is based on the elements.

Enter image details here

It is now fixed value (33%, 33% and 34%) and I want to know how many elements they use I

Like I have 4 elements in my list, I divide it evenly with 4 Want to Is there any easy way to do this? Probably using CSS? I have no problem with javascript, but im just saying that this is something i have missed :)

Edit: I created 3 div and gave them all different classes

  & lt; Section class = "progress-part-list" & gt; & Lt; div class = "progress-part-left" & gt; & Lt; / Div & gt; & Lt; Div class = "progress-part-right" & gt; & Lt; / Div & gt; & Lt; Div class = "progress-part-middle" & gt; & Lt; / Div & gt; & Lt; / Section & gt;   

This is in my CSS with its fixed values:

 . Progress-part-mid {height: 100%; Width: 34%; Background color: # 52ff00; Opacity: 0.9; Display area; Swim left; }. Progress-piece-left {height: 100%; Width: 33%; Background color: red; Opacity: 0.9; Display area; Border-top-left-radius: 50px; Border-bottom-left-radius: 50px; Float: left}. Progress-piece-right {height: 100%; Width: 33%; Background color: yellow; Opacity: 0.9; Display area; Border-top right-radius: 50px; Border bottom right-radius: 50px; float right; }    

Are you looking for something like that?

You want to select all the elements, and want to use it to assess the percentage.

No matter how many elements you incorporate in your container, just make sure that they all have the same class as "progress" Remember, you have more than one class on the element So that you can & lt; div class = "progress progress-before"> or and

.

To do this work, jquery:

  // Get all the parts of the progress bar. Var Bars = $ ('. Bar'); // Apply percent calculation and width with each. Bars.each (function () {$ (this). CSS ('width', (100 / bars.length) + '%');});    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -