我的CSS不会显示:内联;对于我的按钮

时间:2015-12-18 15:00:47

标签: html css

这是我的HTML:

<div class="container">
    <ul>
    <li><a href="http://www.kbb.com/scion/fr-s/2013/" class="button">YES</a></li>
    </ul>
</div>
<div class="2"> 
    <ul>
    <li><a href="http://tinyurl.com/nk4k25r" class="button">NO</a></li>
    </ul>
</div>


<div class="3">
    <ul>
    <li><a href="http://tinyurl.com/pnaj3j2"  class="button">YES</a></li>

</div>
<div class="4">
    <ul>
    <li><a href="http://tinyurl.com/qybshxz" class="button">NO</a></li>
    </ul>
</div>
</div>

这是我的CSS:

.button {
        display: block;
        height: 100px;
        width: 200px;
        background: #ffff00;
        border: 2px solid #00E5EE;
        color: #551A8B;

        text-align: center;
        font: bold 3.2em/100px Impact;

        background: -webkit-linear-gradient(top, #ffff00, #2f5f63);
        background: -moz-linear-gradient(top, #ffff00, #2f5f63);
        background: -o-linear-gradient(top, #ffff00, #2f5f63);
        background: -ms-linear-gradient(top, #ffff00, #2f5f63);
        background: linear-gradient(top, #ffff00, #2f5f63);

        -khtml-border-radius: 50px;
        -moz-border-radius: 50px;
        border-radius: 90px;
        margin: 0px 0px 15px 15px;
    div li {
        display: inline;
        float: center;
    }

我正在努力让我的按钮在页面中心对齐并内联,但每次我尝试使用display: inline;时,我的按钮会变小并保持垂直。

2 个答案:

答案 0 :(得分:3)

.buttondisplay:block;,因此您可以按margin:0 auto;为中心,float属性不具有center值。

&#13;
&#13;
.button {
  display: block;
  height: 100px;
  width: 200px;
  background: #ffff00;
  border: 2px solid #00E5EE;
  color: #551A8B;
  text-align: center;
  font: bold 3.2em/100px Impact;
  background: -webkit-linear-gradient(top, #ffff00, #2f5f63);
  background: -moz-linear-gradient(top, #ffff00, #2f5f63);
  background: -o-linear-gradient(top, #ffff00, #2f5f63);
  background: -ms-linear-gradient(top, #ffff00, #2f5f63);
  background: linear-gradient(top, #ffff00, #2f5f63);
  -khtml-border-radius: 50px;
  -moz-border-radius: 50px;
  border-radius: 90px;
  margin: 0px auto 15px;
}
div li {
  display: block;
}
body {
  text-align: center;
}
div {
  display: inline-block;
}
&#13;
<div class="container">
  <ul>
    <li><a href="http://www.kbb.com/scion/fr-s/2013/" class="button">YES</a>
    </li>
  </ul>
</div>
<div class="2">
  <ul>
    <li><a href="http://tinyurl.com/nk4k25r" class="button">NO</a>
    </li>
  </ul>
</div>


<div class="3">
  <ul>
    <li><a href="http://tinyurl.com/pnaj3j2" class="button">YES</a>
    </li>

</div>
<div class="4">
  <ul>
    <li><a href="http://tinyurl.com/qybshxz" class="button">NO</a>
    </li>
  </ul>
</div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

将您的CSS更改为

.button {
  display: block;
  height: 100px;
  width: 200px;
  background: #ffff00;
  border: 2px solid #00E5EE;
  color: #551A8B;
  text-align: center;
  font: bold 3.2em/100px Impact;
  background: -webkit-linear-gradient(top, #ffff00, #2f5f63);
  background: -moz-linear-gradient(top, #ffff00, #2f5f63);
  background: -o-linear-gradient(top, #ffff00, #2f5f63);
  background: -ms-linear-gradient(top, #ffff00, #2f5f63);
  background: linear-gradient(top, #ffff00, #2f5f63);
  -khtml-border-radius: 50px;
  -moz-border-radius: 50px;
  border-radius: 90px;
  margin: 0px 0px 15px 15px;
}

li {
  list-style: none;
}

div {
  display: inline-block;
}

和HTMl

<div class="container">
  <div>
    <ul>
      <li><a href="http://www.kbb.com/scion/fr-s/2013/" class="button">YES</a></li>
    </ul>
  </div>
  <div class="2">
    <ul>
      <li><a href="http://tinyurl.com/nk4k25r" class="button">NO</a></li>
    </ul>
  </div>


  <div class="3">
    <ul>
      <li><a href="http://tinyurl.com/pnaj3j2" class="button">YES</a></li>
    </ul>

  </div>
  <div class="4">
    <ul>
      <li><a href="http://tinyurl.com/qybshxz" class="button">NO</a></li>
    </ul>
  </div>
</div>