鍍金池/ 問答/HTML5  HTML/ 仿餓了么項(xiàng)目,goods中cartcontrol-wrapper的絕對(duì)定位出現(xiàn)問

仿餓了么項(xiàng)目,goods中cartcontrol-wrapper的絕對(duì)定位出現(xiàn)問題,只能相對(duì)定位

goods中把cartcontrol-wrapper的位置設(shè)為absolute只能出現(xiàn)在最下方,而且顯示不出來。只能相對(duì)定位,這是什么原因?。?br>clipboard.pngclipboard.png
html代碼

              <div class="content">
                <h2 class="name">{{food.name}}</h2>
                <p class="desc">{{food.description}}</p>
                <div class="extra">
                  <span class="count">月售{{food.sellCount}}份</span>
                  <span>好評(píng)率{{food.rating}}%</span>
                </div>
                <div class="price">
                  <span class="now">¥{{food.price}}</span>
                  <span class="old" v-show="food.oldPrice">¥{{food.oldPrice}}</span>
                </div>
                <div class="cartcontrol-wrapper">
                  <cartcontrol @add="addFood" :food="food"></cartcontrol>
                </div>
              </div>

css代碼

          .price
            font-weight: 700
            line-height: 24px
            .now
              maigin-right: 8px
              font-size: 14px
              color: rgb(240,20,20)
            .old
              text-decoration: line-throught
              font-size: 10px
              color: rgb(147,153,159)
          .cartcontrol-wrapper
            /*position:absolute*/
            position:relative
            right: 0
            bottom:12px
回答
編輯回答
咕嚕嚕

絕對(duì)定位的參照物是就近的postion為非static的父級(jí)元素。
出現(xiàn)問題是因?yàn)閐iv.content沒有設(shè)置position,你想相對(duì)于它絕對(duì)定位,那么把div.content的position設(shè)置為relative即可。

2017年3月29日 08:37