gpt4 book ai didi

javascript - 使用 Edge 和 Safari 浏览器在网格内溢出

转载 作者:行者123 更新时间:2023-11-30 10:58:58 24 4
gpt4 key购买 nike

This Swiper Fiddle适用于 Firefox 和 Chrome。显然我的网格布局与 Edge 和 Safari 打破了这一点(没有 display: grid 这个 fiddle 将适用于 Safari 和 Edge)。但是,我不想用 flexbox 替换网格。

如何在使用 display: grid 时在 Edge 和 Safari 中使它正常工作?

var swiper = new Swiper('.swiper-container', {
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
});
body {
background: grey;
}
.grid {
display: grid;
grid-template-columns: 8fr 4fr;
grid-gap: 2rem;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
min-height: 80px;
text-align: center;
background: red;
display: flex;
justify-content: center;
align-items: center;
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Swiper demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">

<!-- Link Swiper's CSS -->
<link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.css">
<link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.min.css">

<script src="https://unpkg.com/swiper/js/swiper.js"></script>
<script src="https://unpkg.com/swiper/js/swiper.min.js"></script>



</head>

<body>
<!-- Swiper -->
<div class="grid">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
<div class="swiper-slide">Slide 4</div>
<div class="swiper-slide">Slide 5</div>
<div class="swiper-slide">Slide 6</div>
<div class="swiper-slide">Slide 7</div>
<div class="swiper-slide">Slide 8</div>
<div class="swiper-slide">Slide 9</div>
<div class="swiper-slide">Slide 10</div>
</div>
<!-- Add Arrows -->
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
<aside>
<div>
<p>
Vivamus placerat lacus vel vehicula scelerisque, dui enim adipiscing lacus sit amet sagittis, libero enim vitae mi. In neque magna posuere, euismod ac tincidunt tempor est. Ut suscipit nisi eu purus. Proin ut pede mauris eget ipsum. Integer vel quam nunc commodo consequat. Integer ac eros eu tellus dignissim viverra. Maecenas erat aliquam erat volutpat. Ut venenatis ipsum quis turpis. Integer cursus scelerisque lorem. Sed nec mauris id quam blandit consequat. Cras nibh mi hendrerit vitae, dapibus et aliquam et magna. Nulla vitae elit. Mauris consectetuer odio vitae augue.
</p>
</div>
</aside>
</div>
</body>
</html>

最佳答案

这似乎是使用灵活单位 (fr) 的问题,Safari 无法正确计算宽度。此问题的解决方法是使用 minmax() 定义网格列,例如 grid-template-columns: minmax(0, 8fr) 4fr;

关于javascript - 使用 Edge 和 Safari 浏览器在网格内溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58725174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com