这是fiddle:
我正在尝试在<ol>
列表
这是我的代码:
.scroll {
overflow: auto;
white-space: nowrap;
}
.card {
float: left;
width: 240px;
list-style-type: none;
}
&#13;
<section class="scroll">
<ol>
<li class="card">
<a href="#">
<img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg" />
</a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#">
<img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg" />
</a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#">
<img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg" />
</a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#">
<img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg" />
</a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#">
<img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg" />
</a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
</ol>
</section>
&#13;
我添加了这个,但我不知道我的代码中有什么问题。
overflow: auto;
white-space: nowrap;
答案 0 :(得分:0)
.scroll>ol{ display: flex; }
答案 1 :(得分:0)
删除左边的浮动并替换为display inline-block;
.scroll {
overflow: auto;
white-space: nowrap;
}
.card {
display: inline-block;
width:240px;
list-style-type:none;
}
<section class="scroll">
<ol>
<li class="card">
<a href="#">
<img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg" />
</a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#">
<img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg"/>
</a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#">
<img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg"/>
</a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#">
<img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg"/>
</a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#">
<img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg"/>
</a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
</ol>
</section>
答案 2 :(得分:0)
white-space:nowrap
仅适用于inline
和inline-block
元素。
.scroll {
overflow: auto;
white-space: nowrap;
}
.card {
display:inline-block;
width:240px;
list-style-type:none;
}
<section class="scroll">
<ol>
<li class="card">
<a href="#"><img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg" /></a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#"><img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg" /></a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#"><img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg" /></a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#"><img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg" /></a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
<li class="card">
<a href="#"><img src="https://image.tmdb.org/t/p/w240_and_h266_bestv2/jYohlUVkLPFdnDryZ8V1HZkJzDt.jpg" /></a>
<p class="castname"><a href="#">Aamir Khan</a></p>
</li>
</ol>
</section>
答案 3 :(得分:0)