繁体   English   中英

CSS中0到100%的5星排名“宽度”%仅适用于20/40/60/80/100但不是例如70%

[英]The 5 star ranking “width” % from 0 - 100% in CSS only works with the 20/40/60/80/100 but not for example 70%

我有个问题。 我使用胡子代码来触发内容。 现在我在网站上有一个5星评价评级,但是为了触发内容而不进入代码,我用胡子代码制作了叠加层。 一切都很好。 但是,例如,如果在源代码中评级是4.5星,它就不会填满星星。 但是在源代码中,类被更改为bcrating4.5

这是我的代码:

    <span class="rating bcrating{{rating}}"></span>

rating类是网站的原始代码。
bcrating是CSS代码中的下面的类。
小胡子{{rating}}是触发器代码。

<p id="hiddenrating" hidden>{{rating}}</p>{{#recommendations}}                                        

  <ul class="box-content box-related" id="viewed-product-list">
    <li class="item" style="width:16.57%">
      <div class="item-info grid_2 alpha">         {{#image}}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
        <a class="product-image" href="{{URL}}" title="{{name}}">
          <img src="{{image}}" alt="{{name}}" style="width:50%">
        </a>    {{/image}}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
        <div class="product-details">
          <a href="{{URL}}" title="{{name}}">
            <span class="product-name">{{name}}</span>
            <div class="price leden">
              <span class="old_price">
                <strong>{{old_price}}</strong>
              </span>
              <span class="new_price">
                <strong>{{new_price}}</strong>
              </span>
            </div>
          </a>
          <div class="product-review-block">
            <span class="fivestar">
              <span class="rating-box">
                <a class="nobr" href="{{URL}}#customer-reviews-tab">
                </a>
                <span class="rating bcrating{{rating}}"></span>
              </span>
            </span>
          </div>
        </div>
      </div>
    </li>
  </ul>{{/recommendations}}

CSS:

.bcrating0 {
    width:0%;
}
.bcrating1 {
    width:20%;
}
.bcrating2 {
    width:40%;
}
.bcrating3 {
    width:60%;
}
.bcrating4 {
    width:80%;
}
.bcrating5 {
    width:100%;
}

如果{{rating}}传递的值为“4.5”,则HTML中该.rating元素的类名为bcrating4.5 HTML可以将句点作为有效类名的一部分。

在CSS中,您只有类.bcrating4.bcrating5 什么都不匹配。

您需要定义一个类.bcrating4\\.5 ,其中句点字符被转义,使其成为CSS中与HTML匹配的有效选择器。

这是一个方便的角色转义工具: https//mothereff.in/css-escapes

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM