Firefox在一个带有display:table-cell的项目中的绝对位置问题

时间:2012-11-02 17:39:03

标签: html css firefox

我有3个li,我试图水平排列,然后在每个li的内部放置一个跨度。

跨度在Chrome中正确定位,但远远超出了Firefox的界限。

http://jsfiddle.net/brendan_rice/mPnCh/1/

有人可以帮忙吗?

<div id="blank-slate-steps">
   <ul>
      <li class="first">
         <h3><em>Step 1</em>Create Something</h3>
         <p>Once you have created Something Else you can Create Final Thing</p>
         <span></span>
      </li>
      <li class="second">
         <h3><em>Step 2</em>Create Something Else</h3>
         <p>Once you have created Something Else you can Create Final Thing</p>
         <span></span>
      </li>
      <li class="third">
         <h3><em>Step 3</em>Create Final Thing</h3>
         <p>Once you have created Something Else you can Create Final Thing</p>
         <span></span>
      </li>
   </ul>
</div>​

CSS

body{
padding-top: 300px;
}
#blank-slate-steps {
    background-color: #E8E8E8;
    bottom: 0;
    font-family: OpenSansCondensedBold,sans-serif;
    text-align: center;
    width: 100%;
}
#blank-slate-steps li {
    display: table-cell;
    max-width: 300px;
    padding: 40px;
    position: relative;
    width: 300px;
}
#blank-slate-steps h3 {
    font-size: 1.6em;
    margin-bottom: 0.6em;
}
#blank-slate-steps h3 em {
    color: #878787;
    float: left;
    font-size: 0.8em;
    font-style: normal;
    margin-bottom: 4px;
    text-transform: uppercase;
    width: 100%;
}
#blank-slate-steps li.second span {
    background: red url("../images/sprite/icons-grey-38.png") no-repeat scroll 0 -56px transparent;
    height: 37px;
    width: 36px;
}
#blank-slate-steps span {
background-color: red;
    display: block;
    height: 20px;
    left: -10px;
    position: absolute;
    top: 50px;
    width: 20px;
}

3 个答案:

答案 0 :(得分:6)

使用position-relative for blank-slate-steps div。

#blank-slate-steps {
    background-color: #E8E8E8;
    bottom: 0;
    font-family: OpenSansCondensedBold,sans-serif;
    text-align: center;
    width: 100%;
    position: relative;
}

答案 1 :(得分:2)

好的,我已经成功了,你可以这样做:fiddle

说明:我做的是,position: relative;使用了#blank-slate-steps,而position: relative;再次使用div并将<li>内容包含在其中< / p>

HTML

<div id="blank-slate-steps">
   <ul>
      <li class="first">
          <div style="position: relative;">
         <h3><em>Step 1</em>Create Something</h3>
         <p>Once you have created Something Else you can Create Final Thing</p>
         <span></span>
          </div>
      </li>
      <li class="second">
          <div style="position: relative;">
         <h3><em>Step 2</em>Create Something Else</h3>
         <p>Once you have created Something Else you can Create Final Thing</p>
         <span></span>
           </div>
      </li>
      <li class="third">
          <div style="position: relative;">
         <h3><em>Step 3</em>Create Final Thing</h3>
         <p>Once you have created Something Else you can Create Final Thing</p>
         <span></span>
          </div>
      </li>
   </ul>
</div>

CSS

body{
    padding-top: 300px;
}
#blank-slate-steps {
    background-color: #E8E8E8;
    bottom: 0;
    font-family: OpenSansCondensedBold,sans-serif;
    text-align: center;
    width: 100%;
    position: relative;
}
#blank-slate-steps li {
    display: table-cell;
    max-width: 300px;
    padding: 40px;
    width: 300px;
}
#blank-slate-steps h3 {
    font-size: 1.6em;
    margin-bottom: 0.6em;
}
#blank-slate-steps h3 em {
    color: #878787;
    float: left;
    font-size: 0.8em;
    font-style: normal;
    margin-bottom: 4px;
    text-transform: uppercase;
    width: 100%;
}
#blank-slate-steps li.second span {
    background: red url("../images/sprite/icons-grey-38.png") no-repeat scroll 0 -56px transparent;
    height: 37px;
    width: 36px;
}
#blank-slate-steps span {
    background-color: red;
    display: block;
    height: 20px;
    left: -10px;
    position: absolute;
    top: 50px;
    width: 20px;
}

答案 2 :(得分:1)

尝试将你的跨度放在第一位:

<li class="second">
     <span></span>
     <h3><em>Step 2</em>Create Something Else</h3>
     <p>Once you have created Something Else you can Create Final Thing</p>
  </li>

并将范围放在position:relativefloat:left