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



我有一个从左到右显示的进度条。我需要做另一个相同风格的进步,但会从右到左显示。

以下是我的风格定义:

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一些可以坚持的东西(比如一个特殊的类(,并设置它的direction: rtl;

下面是一个基于您发布的代码的小片段。

/* 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>

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

这是一支你可以玩的电笔。

最新更新