Css3使用2个类选择一个元素

时间:2016-10-18 01:02:28

标签: css css3 styles zurb-foundation stylesheet

我尝试使用2个类选择一个元素,但由于某种原因它不起作用!

我正在尝试选择大3,因为我想改变宽度。

无论如何我写的css代码:

.plans.large-3  {
    width: 30% !important;
}

整个代码!

 <section>
        <div class="row">
            <div class="large-12 medium-12 small-12 columns plans">
                <div class="large-12 medium-12 small-12 columns plans_title">
                    <h5>Price</h5>
                    <h2>Your Plan</h2>
                    <i class="fa fa-bar-chart" aria-hidden="true"></i>
                </div>

                <div class="large-3 medium-4 small-4 columns plans_price">
                    <h5>Test</h5>
                    <h5>5 Days</h5>
                    <h1>Free</h1
                </div>
            </div>
        </div>
    </section>

2 个答案:

答案 0 :(得分:3)

像这样:

.plans > .large-3 {
  width: 30% !important;
  border: 1px solid red;
}
<section>
  <div class="row">
    <div class="large-12 medium-12 small-12 columns plans">
      <div class="large-12 medium-12 small-12 columns plans_title">
        <h5>Price</h5>
        <h2>Your Plan</h2>
        <i class="fa fa-bar-chart" aria-hidden="true"></i>
      </div>

      <div class="large-3 medium-4 small-4 columns plans_price">
        <h5>Test</h5>
        <h5>5 Days</h5>
        <h1>Free</h1
                </div>
            </div>
        </div>
    </section>

它将选择类large-3的元素,这些元素是具有类.plans的元素的直接后代。有关详细信息,请参阅MDN上的child selectors

答案 1 :(得分:1)

如果你想要css同时影响计划和大3,那么分隔2的逗号就可以了。

&#13;
&#13;
.plans .large-3 {
  width: 30% !important;
  background-color: #CCC;
}
&#13;
<section>
  <div class="row">
    <div class="large-12 medium-12 small-12 columns plans">
      <div class="large-12 medium-12 small-12 columns plans_title">
        <h5>Price</h5>
        <h2>Your Plan</h2>
        <i class="fa fa-bar-chart" aria-hidden="true"></i>
      </div>

      <div class="large-3 medium-4 small-4 columns plans_price">
        <h5>Test</h5>
        <h5>5 Days</h5>
        <h1>Free</h1
      </div>
    </div>
  </div>
      <!-- ****************** not in plans class ******************** -->
       <div class="large-3 medium-4 small-4 columns plans_price">
        <h5>Test</h5>
        <h5>5 Days</h5>
        <h1>Free</h1
      </div>
     <!-- ****************** not in plans class ******************** -->
      
</section>
&#13;
&#13;
&#13;