【发布时间】:2020-02-12 12:11:17
【问题描述】:
我做了一个刷卡器,里面有两张卡。在移动设备上,视口中只有一张卡片。第二张卡片在右侧被截断。当我向左滑动时,第二张卡片出现在视口中,第一张卡片在左侧被截断。
所有这些都运行良好。唯一不起作用的是第二张卡片在视口中时右侧的距离。我在第二张卡片上尝试了边距,在父元素上进行了填充。似乎没有任何效果。我希望卡片从视口的最右边出现。但是当它完全在那里时,它应该与边缘有一段距离,就像左边一样。
body {
margin: 0;
border: 1px solid gray;
}
.carousel {
display: flex;
overflow-x: scroll;
scroll-snap-type: x mandatory;
padding: 1rem;
max-width: 100vw;
}
.carousel .wahl-box {
background-color: #5a3982;
border-radius: 2px;
transition: transform .3s, box-shadow .3s, width .3s, flex-basis .3s;
scroll-snap-align: center;
min-width: calc(100vw - 6rem);
margin: 1rem .5rem;
display: block;
}
.carousel .wahl-box.active {
box-shadow: 0 1px 16px 0 rgba(76, 137, 130, 0.62);
transform: scale(1.1, 1.1);
margin: 1rem;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<form action="" class="carousel">
<label class="d-block p-4 wahl-box text-white text-center " for="wahl_rente">
<h2>Card 1</h2>
<input class="d-none" type="radio" name="leistungswahl" id="wahl_rente" value="RENTE">
</label>
<label class="d-block p-4 wahl-box text-white text-center " for="wahl_kapital">
<h2>Card 2</h2>
<input class="d-none" type="radio" name="leistungswahl" id="wahl_kapital" value="KAPITAL">
</label>
</form>
【问题讨论】: