Vaelor
Vaelor

Reputation: 69

Custom color for a indeterminate <progress>-tag without a value

I would like to style a so called 'indeterminate'-progressbar. (A <progress>-tag without a value)

  <progress max="100"></progress>

See that codepen I found on the net as an example (not mine):

http://codepen.io/anon/pen/mEWqer

The difference should be obvious. The Default bar without any style has movement in it. What I would like to do, style that indeterminate progressbar so that it keeps 'moving' like the above.

Any means of styling always result in a 'completly' filled bar, without the moving part.

Am I doing something wrong, is that expected or a bug? Since I am not very good with css, I am a bit at a loss here. The internet - as far as I found information - only talks about styling normal progressbars.

Edit: Now I am even more confused. It seems to work in Edge.. (the dots seem to be the default 'progressbar' for edge). So, a bug? See the attached image from edge.

example from edge

Edit 2: All of the proposed answers are for a determinate progressbar. Looking at the codepen I provided (the 'Default'-bar), it should be clear that I mean an indeterminate progressbar.

Upvotes: 1

Views: 3271

Answers (4)

AlexisWbr
AlexisWbr

Reputation: 451

Seems like a bug to me... When you try to apply some styles on it, Chrome seems to define the progress bar like defined, whenever it exists a value inside your tag or not. I tried with Chrome Canary too, but same thing append.

It could be a good idea to think, "go to hell you moving item, I will erase you with my own style". But apparently,

Animations don't seem to work anymore on the pseudo elements within a progress element, in Blink. At the time this was published, they did. Brian LePore reported this to me and pointed me toward this thread discussing it and created a reduced test case.

-

Maybe it's the same with the that @keyframes defined outside of the Shadow DOM can't get accessed by an element inside. From the timing it might have changed in Chromium 39/40?

https://css-tricks.com/html5-progress-element/#article-header-id-5

So I tried but yes, animations does not work anymore...

*,
*:before,
*:after {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

html {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 100%;
  background: #333;
}

#page-wrapper {
  width: 640px;
  background: #FFFFFF;
  padding: 1em;
  margin: 1em auto;
  border-top: 5px solid #69c773;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

h1 {
  margin-top: 0;
}

progress {
  width: 100%;
}

.styled progress {
  /* Reset the default appearance */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 100%;
  height: 15px;
  /* Firefox */
  border: none;
  background: #EEE;
  border-radius: 3px;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2) inset;
}

/* lest apply somes styles on it */
.styled progress:not([value])::-webkit-progress-bar {
  background: blue;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2) inset;
  border-radius: 3px;
  background-image:
	   -webkit-linear-gradient(-45deg, 
	                           transparent 33%, rgba(0, 0, 0, .1) 33%, 
	                           rgba(0,0, 0, .1) 66%, transparent 66%),
	   -webkit-linear-gradient(top, 
	                           rgba(255, 255, 255, .25), 
	                           rgba(0, 0, 0, .25)),
	   -webkit-linear-gradient(left, #09c, #f44);
  -webkit-animation: animate-stripes 5s linear infinite;
          animation: animate-stripes 5s linear infinite;
}

/* this seems to does not work anymore */
@-webkit-keyframes animate-stripes {
   100% { background-position: -100px 0px; }
}
@keyframes animate-stripes {
   100% { background-position: -100px 0px; }
}

.styled progress::-webkit-progress-value {
  background-color: blue;
  border-radius: 3px;
}

.styled progress::-moz-progress-bar {
  background-color: blue;
  border-radius: 3px;
}
<div id="page-wrapper">
  <p>Default</p>
  <p>
    <progress max="100"></progress>
  </p>

  <p>Styled defined</p>
  it does not move:
  <p class="styled">
    <progress max="100" value="50"></progress>
  </p>
  <p>Styled defined</p>
  this should move:
  <p class="styled">
    <progress max="100"></progress>
  </p>

Upvotes: 1

Well, dunno if this is what are you looking up but check it out, with this custom progress bar you can style it and set the width of it (it's responsive).

CSS

* {
        /* This will make all your elements have their real size (incluiding with padding) */
        box-sizing: content-box;
    }

    .pro-bar-container {
        background: #ccc;
        border: 2px solid blue;
        height: 1em;
        overflow: hidden;
        width: 100%;
    }

    .pro-bar {
        background: royalblue;
        height: inherit;
    }

    .pro-bar-width{
        /* Here is where you specify the width of ur progress-bar */
        width: 80%;
    }

    .pro-bar-candy {
        animation: progress .6s linear infinite;
        /* Don't touch this */
        background: linear-gradient(
            -45deg,
            rgba(255, 255, 255, 0.25) 25%,
            transparent 25%,
            transparent 50%,
            rgba(255, 255, 255, 0.25) 50%,
            rgba(255, 255, 255, 0.25) 75%,
            transparent 75%,
            transparent);
        /* Don't touch this */
        background-repeat: repeat-x;
        /* The size of the bars must match the background-position in the @keyframes */
        background-size: 2em 2em;
        height: inherit;
        width: 100%;
    }

    @keyframes progress {
        to { background-position: 2em 0; }
    }

HTML

<div class="pro-bar-container">
    <div class="pro-bar pro-bar-width" data-pro-bar-percent="100">
        <div class="pro-bar-candy"></div>
    </div>
</div>

https://jsfiddle.net/Alejandrom3/r5yLgjr0/

Upvotes: 0

Nikhil Ghuse
Nikhil Ghuse

Reputation: 1288

HTML

 <p style="width:60%" data-value="60">CSS3</p>
    <progress max="100" value="60" class="css3">
        <!-- Browsers that support HTML5 progress element will ignore the html inside `progress` element. Whereas older browsers will ignore the `progress` element and instead render the html inside it. -->
        <div class="progress-bar">
            <span style="width: 60%">60%</span>
        </div>
    </progress>

CSS

           HTML  CSS   Result
          Edit on 
        @import url(http://fonts.googleapis.com/css?family=Expletus+Sans);

      /* Basic resets */

  * { 
        margin:0; padding:0; 
        box-sizing: border-box;
     }

  body {
       margin: 50px auto 0;
      max-width: 800px;

     font-family: "Expletus Sans", sans-serif;
   }

    li {

         width: 50%;
         float: left;
        list-style-type: none;

        padding-right: 5.3333333%;
       }

       li:nth-child(even) { margin-bottom: 5em;}

   h2 {
     margin: 0 0 1.5em;
       border-bottom: 1px solid #ccc;

      padding: 0 0 .25em;
    }

      /* Styling an indeterminate progress bar */

   progress:not(value) {
    /* Add your styles here. As part of this walkthrough we will focus only on determinate progress bars. */
     }

    /* Styling the determinate progress element */

   progress[value] {
     /* Get rid of the default appearance */
     appearance: none;

    /* This unfortunately leaves a trail of border behind in Firefox and Opera. We can remove that by setting the border to none. */
border: none;

/* Add dimensions */
 width: 100%; height: 20px;

/* Although firefox doesn't provide any additional pseudo class to style the progress element container, any style applied here works on the container. */
  background-color: whiteSmoke;
  border-radius: 3px;
  box-shadow: 0 2px 3px rgba(0,0,0,.5) inset;

/* Of all IE, only IE10 supports progress element that too partially. It only allows to change the background-color of the progress value using the 'color' attribute. */
color: royalblue;

position: relative;
margin: 0 0 1.5em; 
 }

  /*
      Webkit browsers provide two pseudo classes that can be use to style HTML5 progress element.
 -webkit-progress-bar -> To style the progress element container
   -webkit-progress-value -> To style the progress element value.
  */

  progress[value]::-webkit-progress-bar {
background-color: whiteSmoke;
border-radius: 3px;
box-shadow: 0 2px 3px rgba(0,0,0,.5) inset;
}

progress[value]::-webkit-progress-value {
 position: relative;

background-size: 35px 20px, 100% 100%, 100% 100%;
border-radius:3px;

/* Let's animate this */
animation: animate-stripes 5s linear infinite;
 }

  @keyframes animate-stripes { 100% { background-position: -100px 0; } }

 /* Let's spice up things little bit by using pseudo elements. */

  progress[value]::-webkit-progress-value:after {
/* Only webkit/blink browsers understand pseudo elements on pseudo classes.          A rare phenomenon! */
content: '';
position: absolute;

width:5px; height:5px;
top:7px; right:7px;

background-color: white;
border-radius: 100%;
 }

 /* Firefox provides a single pseudo class to style the progress element value and not for container. -moz-progress-bar */

 progress[value]::-moz-progress-bar {
/* Gradient background with Stripes */
background-image:
   -moz-linear-gradient( 135deg,
                                                 transparent,
                                                 transparent 33%,
                                                 rgba(0,0,0,.1) 33%,
                                                 rgba(0,0,0,.1) 66%,
                                                 transparent 66%),
 -moz-linear-gradient( top,
                                                    rgba(255, 255, 255,  .25),
                                                    rgba(0,0,0,.2)),
 -moz-linear-gradient( left, #09c, #f44);

background-size: 35px 20px, 100% 100%, 100% 100%;
border-radius:3px;

  /* Firefox doesn't support CSS3 keyframe animations on progress element.         Hence, we did not include animate-stripes in this code block */
  }

   /* Fallback technique styles */
   .progress-bar {
background-color: whiteSmoke;
border-radius: 3px;
box-shadow: 0 2px 3px rgba(0,0,0,.5) inset;

/* Dimensions should be similar to the parent progress element. */
width: 100%; height:20px;
 }

    .progress-bar span {
background-color: royalblue;
border-radius: 3px;

display: block;
text-indent: -9999px;
}

p[data-value] { 

    position: relative; 
   }

   /* The percentage will automatically fall in place as soon as we make the width fluid. Now making widths fluid. */

 p[data-value]:after {
content: attr(data-value) '%';
position: absolute; right:0;
} 





  .html5::-webkit-progress-value,
 .python::-webkit-progress-value  {
/* Gradient background with Stripes */
background-image:
 -webkit-linear-gradient( 135deg,
                                                 transparent,
                                                 transparent 33%,
                                                 rgba(0,0,0,.1) 33%,
                                                 rgba(0,0,0,.1) 66%,
                                                 transparent 66%),
   -webkit-linear-gradient( top,
                                                    rgba(255, 255, 255, .25),
                                                    rgba(0,0,0,.2)),
 -webkit-linear-gradient( left, #09c, #f44);
 }

  .css3::-webkit-progress-value,
  .php::-webkit-progress-value 
{
/* Gradient background with Stripes */
background-image:
-webkit-linear-gradient( 135deg,
                                                 transparent,
                                                 transparent 33%,
                                                 rgba(0,0,0,.1) 33%,
                                                 rgba(0,0,0,.1) 66%,
                                                  transparent 66%),
   -webkit-linear-gradient( top,
                                                    rgba(255, 255, 255, .25),
                                                    rgba(0,0,0,.2)),
   -webkit-linear-gradient( left, #09c, #ff0);
   }

 .jquery::-webkit-progress-value,
  .node-js::-webkit-progress-value 
 {
/* Gradient background with Stripes */
background-image:
-webkit-linear-gradient( 135deg,
                                                 transparent,
                                                 transparent 33%,
                                                 rgba(0,0,0,.1) 33%,
                                                 rgba(0,0,0,.1) 66%,
                                                 transparent 66%),
    -webkit-linear-gradient( top,
                                                    rgba(255, 255, 255, .25),
                                                    rgba(0,0,0,.2)),
 -webkit-linear-gradient( left, #09c, #690);
     }

     /* Similarly, for Mozillaa. Unfortunately combining the styles for different browsers will break every other browser. Hence, we need a separate block. */

   .html5::-moz-progress-bar,
   .php::-moz-progress-bar {
       /* Gradient background with Stripes */
    background-image:
    -moz-linear-gradient( 135deg,
                                                 transparent,
                                                 transparent 33%,
                                                 rgba(0,0,0,.1) 33%,
                                                 rgba(0,0,0,.1) 66%,
                                                 transparent 66%),
      -moz-linear-gradient( top,
                                                    rgba(255, 255, 255, .25),
                                                    rgba(0,0,0,.2)),
    -moz-linear-gradient( left, #09c, #f44);
   }

    .css3::-moz-progress-bar,
     .php::-moz-progress-bar {
   {
 /* Gradient background with Stripes */
background-image:
      -moz-linear-gradient( 135deg,
                                                 transparent,
                                                 transparent 33%,
                                                 rgba(0,0,0,.1) 33%,
                                                 rgba(0,0,0,.1) 66%,
                                                 transparent 66%),
      -moz-linear-gradient( top,
                                                    rgba(255, 255, 255, .25),
                                                    rgba(0,0,0,.2)),
      -moz-linear-gradient( left, #09c, #ff0);
  }

   .jquery::-moz-progress-bar,
    .node-js::-moz-progress-bar {
    /* Gradient background with Stripes */
    background-image:
       -moz-linear-gradient( 135deg,
                                                 transparent,
                                                 transparent 33%,
                                                 rgba(0,0,0,.1) 33%,
                                                 rgba(0,0,0,.1) 66%,
                                                 transparent 66%),
     -moz-linear-gradient( top,
                                                    rgba(255, 255, 255, .25),
                                                    rgba(0,0,0,.2)),
     -moz-linear-gradient( left, #09c, #690);
  }

Upvotes: 0

Felix Fong
Felix Fong

Reputation: 985

Hello are you meaning using overflow:hidden style? i hope so

https://jsfiddle.net/moongod101/7c2xde9f/

Upvotes: 0

Related Questions