无序列表不内联

时间:2016-05-18 14:52:02

标签: html css image twitter-bootstrap html-lists

我有这个带有图像的无序列表,它只能在我需要的时候垂直显示。

现在的样子。

我已尝试过几十个display:inlinefloat:left的代码,但似乎没有任何效果。

enter image description here

我希望列表是横向的:

这是HTML:

.gallery-section {
  width: 100%;
  height: 500px;
  padding:10px;
  color: #fff;
  margin: 50px auto 0 auto;
  background-color: rebeccapurple;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  background-size: cover;
  -o-background-size: cover;
  text-align: center;
}

#galtitle {
  font-size: 500%;
}

.imggallery {
  height: 200px;
  width: 200px;
}

#list {
  list-style-type: none;
  display: inline;
}

ul#list li  {
  display: inline;

}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<section id="gallery" class="no-padding content-section">
  <div class="gallery-section">
    <div class="container">
      <div class="col-lg-8 col-lg-offset-2">
        <h1 id="galtitle">Gallery</h1>
        <div class="imggallery">
          <ul id="list">
            <li>
              <img src="img/michael61.jpg" class="img-responsive">
              <p>Visit flyer gallery</p>
            </li>
            <li>
              <img src="img/michael61.jpg" class="img-responsive">
              <p>Visit flyer gallery</p>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</section>

3 个答案:

答案 0 :(得分:1)

你必须改变一些CSS。像:

  1. 删除.imggallery宽度。
  2. #list设为display:block
  3. 从图片中删除.img-responsive
  4. 请阅读css,如果不清楚,请问..

    .gallery-section {
      width: 100%;
      height: 500px;
      padding:10px;
      color: #fff;
      margin: 50px auto 0 auto;
      background-color: rebeccapurple;
      -webkit-background-size: cover;
      -moz-background-size: cover;
      background-size: cover;
      -o-background-size: cover;
      text-align: center;
    }
    
    #galtitle {
      font-size: 500%;
    }
    
    .imggallery {
      height: 200px;
      /*width: 200px;*/
    }
    
    #list {
      list-style-type: none;
      display: block;
    }
    
    ul#list li  {
      display: inline;
    
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
    <section id="gallery" class="no-padding content-section">
      <div class="gallery-section">
        <div class="container">
          <div class="col-lg-8 col-lg-offset-2">
            <h1 id="galtitle">Gallery</h1>
            <div class="imggallery">
              <ul id="list">
                <li>
                  <img src="img/michael61.jpg">
                  <span>Visit flyer gallery</span>
                </li>
                <li>
                  <img src="img/michael61.jpg">
                  <span>Visit flyer gallery</span>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </section>

答案 1 :(得分:1)

首先,您无需在inline上设置ul

您的li包含块元素,因此将它们设置为内联并不合理。而是将它们设置为inline-block

最后,width上的.imggallery太窄而无法并排展示,所以请删除它。

结果:

.gallery-section {
  width: 100%;
  height: 500px;
  padding:10px;
  color: #fff;
  margin: 50px auto 0 auto;
  background-color: rebeccapurple;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  background-size: cover;
  -o-background-size: cover;
  text-align: center;
}

#galtitle {
  font-size: 500%;
}

.imggallery {
  height: 200px;
  /* width: 200px; */
}

#list {
  list-style-type: none;
  /* display: inline; */
}

ul#list li  {
  /* display: inline; */
  display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<section id="gallery" class="no-padding content-section">
  <div class="gallery-section">
    <div class="container">
      <div class="col-lg-8 col-lg-offset-2">
        <h1 id="galtitle">Gallery</h1>
        <div class="imggallery">
          <ul id="list">
            <li>
              <img src="img/michael61.jpg" class="img-responsive">
              <p>Visit flyer gallery</p>
            </li>
            <li>
              <img src="img/michael61.jpg" class="img-responsive">
              <p>Visit flyer gallery</p>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</section>

答案 2 :(得分:0)

试试这个更新的css

.gallery-section {
  width: 100%;
  height: 500px;
  padding:10px;
  color: #fff;
  margin: 50px auto 0 auto;
  background-color: rebeccapurple;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  background-size: cover;
  -o-background-size: cover;
  text-align: center;

}

#galtitle {
  font-size: 500%;
}

.imggallery {
  height: 200px;
  margin: auto;
}

#list {
  list-style-type: none;
  display: table;
  margin: auto;
}

ul#list li  {
  display: inline-block;
  margin: 30px;
}