【问题标题】:Unordered List doesnt inline无序列表不内联
【发布时间】:2016-05-19 02:41:28
【问题描述】:
我有这个带有图像的无序列表,它只在我想要横向显示时垂直显示。
这就是现在的样子。
我尝试了几十个 display:inline 或 float:left 的代码,但似乎没有任何效果。
我希望列表是横向的:
这是 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>
【问题讨论】:
标签:
html
css
image
twitter-bootstrap
html-lists
【解决方案1】:
您必须更改一些 CSS。喜欢:
- 删除
.imggallery 宽度。
- 将
#list 设置为display:block
- 从图片中删除
.img-responsive。
只需阅读 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>
【解决方案2】:
首先,您不需要在ul 上设置inline。
您的lis 包含块元素,因此将它们设置为内联并没有任何意义。相反,请将它们设置为 inline-block。
最后,.imggallery 上的 width 太窄而无法并排显示,因此请将其删除。
结果:
.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>
【解决方案3】:
试试这个更新的 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;
}