css - 如何创建水平滚动的卡片轮播?

标签 css

我在创建这个时遇到了困难。调整屏幕大小时,卡片会自动换行。我试图将溢出设置为隐藏,但这没有帮助

Scrolling Cards

这是我目前所拥有的:

.showcase-section{
  height:40vh;
  text-align:center;
  padding:2rem;
}
.showcase__carousel--container{
  padding:2rem;
  height:30rem;
  width:65%;
  margin-left:auto;
  margin-right:auto;

}
.showcase__carousel--content{
  overflow:hidden;
}
.showcase__carousel--item{
  height:15rem;
  width:12rem;
  background-color:whitesmoke;
  border-radius:5px;
  box-shadow:0 0 3px rgba(0,0,0,.5);
  margin-left:2rem;
  margin-right:2rem;
  display:inline-block;
}
<section class="showcase-section">
<h2 style="font-size:3rem;">Showcase</h2>
<div class="showcase__carousel--container">
  <i class="fa fa-chevron-left" style="font-size:10rem; display:inline-block; float:left;"></i>
  <div class="showcase__carousel--content">
    <div class="showcase__carousel--item">
    ..
    </div>
    <div class="showcase__carousel--item">
    ..
    </div>
    <div class="showcase__carousel--item">
    ..
    </div>
    <div class="showcase__carousel--item">
    ..
    </div>

  <i class="fa fa-chevron-right" style="font-size:10rem; display:inline-block; float:right;"></i>
  </div>
  </div>
</section>

最佳答案

您可以在 css 中使用 FlexBox。 .showcase__carousel--content 的以下代码将阻止将内容附加到换行符。

您可以测试 dynamic nature here

.showcase__carousel--content {
    display: flex;
    flex-flow: row nowrap;
}

.showcase-section{
  height:40vh;
  text-align:center;
  padding:1rem;
}
.showcase__carousel--container{
  padding:1rem;
  height:30rem;
  width:65%;
  margin-left:auto;
  margin-right:auto;

}
.showcase__carousel--content{
  overflow:hidden;
  display: flex;
  flex-flow: row nowrap;
  justify-content: center;
  align-items: center;
}
.showcase__carousel--item{
  height:12rem;
  flex: 0 0 12rem;
  background-color:whitesmoke;
  border-radius:5px;
  box-shadow:0 0 3px rgba(0,0,0,.5);
  margin:0 1rem;
  display:inline-block;
}
<section class="showcase-section">
<h2 style="font-size:3rem;">Showcase</h2>
<div class="showcase__carousel--container">
  <i class="fa fa-chevron-left" style="font-size:10rem; display:inline-block; float:left;"></i>
  <div class="showcase__carousel--content">
    <div class="showcase__carousel--item">
    ..
    </div>
    <div class="showcase__carousel--item">
    ..
    </div>
    <div class="showcase__carousel--item">
    ..
    </div>
    <div class="showcase__carousel--item">
    ..
    </div>

  <i class="fa fa-chevron-right" style="font-size:10rem; display:inline-block; float:right;"></i>
  </div>
  </div>
</section>

关于css - 如何创建水平滚动的卡片轮播?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52602445/

相关文章:

html - 如何在 CSS 蒙版内添加阴影?

html - 关于 css hover 的问题

css - Bootstrap 3 - 展开时的导航栏颜色

css - 带有溢出 y 的滚动 snap css 属性导致页面滚动

jquery - 想在悬停时显示 Font Awesome

javascript - jquery 汉堡菜单有什么问题?

css - webkit 下的字母间距 - 任何解决方法?

css - 我需要一个 div 坐在另一个 div 的 Angular 落,在另一个 div 之上

通过 setAttribute 设置类时的 JavaScript 奇怪行为

html - CSS 三 Angular 形与 unicode 的浏览器渲染/定位差异