我有这个带有图像的无序列表,它只能在我需要的时候垂直显示。
现在的样子。
我已尝试过几十个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>
答案 0 :(得分: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>
答案 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;
}