如何从右到左呈现进度元素?

How to render a progress element from right to left?

我有一个从左到右显示的进度条。我需要制作另一个相同样式的进度,但将从右到左显示。

这是我的风格定义:

progress, progress[role] {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    background-size: auto;
    height: 50px;
    width: 100%;
    padding-top: 10px;
}
 progress[value]::-webkit-progress-bar {
     background-color: grey;
     border-radius: 2px;
     box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
 }
 progress[value]::-webkit-progress-value {
    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);
    border-radius: 2px; 
    background-size: 35px 20px, 100% 100%, 100% 100%; 
}

.valuebar {
    position: relative;
}
.valuebar h3 {
    color: #fff;
    left: 1em;
    line-height: 1;
    position: absolute;
}

我使用了来自网络的示例,该示例使用 ::-webkit-progress-value

如何让它从右向左渲染?

通常,当它们的 direction 属性从 ltr(默认值)更改为 rtl(代表从右到左)时,许多元素会翻转它们的水平渲染(与从右到左的语言兼容,例如阿拉伯语或希伯来语)。

<progress>元素没有什么不同。只需给 CSS 一些东西(例如特殊的 class)并设置它的 direction: rtl;.

这是一个基于您 post 编写的代码的小片段。

/* this is the important bit */
progress.rtl {
  direction: rtl;
}
progress,
progress[role] {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background-size: auto;
  height: 50px;
  width: 100%;
  padding-top: 10px;
}
progress[value]::-webkit-progress-bar {
  background-color: grey;
  border-radius: 2px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
}
progress[value]::-webkit-progress-value {
  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);
  border-radius: 2px;
  background-size: 35px 20px, 100% 100%, 100% 100%;
}
.valuebar {
  position: relative;
}
.valuebar h3 {
  color: #fff;
  left: 1em;
  line-height: 1;
  position: absolute;
}
<progress value="59" max="100">59%</progress>
<br />
<progress class="rtl" value="59" max="100">59%</progress>

我不知道你的标记是什么,因为你没有 post 它,但你可能需要调整 .valuebar 定位。

这里有一个 code pen 你可以玩玩。