最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why did the swiper-wrapper get ended up so big? - Stack Overflow

programmeradmin0浏览0评论

I use swiper.js.
Below, there is the actual demo site.


Problem

There is a mystery gap below..


This turned out to be probably due to swiper-wrapper or swiper-slide,
but why did this happen?

How to this fit the element? (How can I fix this space?)


Demo site

Real site is here

JSFiddle (fullscreen)
JSFiddle

Could you please give me a hand?


Add: Current status

▼ If I change the width or height of the browser, it will be ended up covered with the next slide.


▲ When I checked with the developer tool of Chrome, it turned out that the height of the contents part is very large. (It may be easy to understand if you look at the bottom of gif.)

How can I eliminate the extra height at the bottom of the contents?

I use swiper.js.
Below, there is the actual demo site.


Problem

There is a mystery gap below..


This turned out to be probably due to swiper-wrapper or swiper-slide,
but why did this happen?

How to this fit the element? (How can I fix this space?)


Demo site

Real site is here

JSFiddle (fullscreen)
JSFiddle

Could you please give me a hand?


Add: Current status

▼ If I change the width or height of the browser, it will be ended up covered with the next slide.


▲ When I checked with the developer tool of Chrome, it turned out that the height of the contents part is very large. (It may be easy to understand if you look at the bottom of gif.)

How can I eliminate the extra height at the bottom of the contents?

Share Improve this question edited Apr 1, 2019 at 3:59 POP asked Mar 31, 2019 at 10:13 POPPOP 6712 gold badges8 silver badges20 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 2

There are 2 things to do here:

1. Correct width and height of .wrap and #content

You give them specified diemensions (width and height with percent and calc()). But then you expend those values by using padding and border. Both, padding and border by default expand diemensions of a block element. Add box-sizing: border-box; to them both, and then they will have width and height you set - the padding and border (! but nor margin) will be put inside them.

2. Add max-height: 100%; to .swiper-container

height: auto; means that element will get height of the content that is inside of it.

If you set height (or max-height) with a value (pixels, percent .. whatever) it will refer to the parent.

You could also add overflow: hidden; instead of max-height to #content - overall effect would be the same - but it makes more sense to limit the height of .swiper-container.

.wrap {
  box-sizing: border-box;
}
#content {
  box-sizing: border-box;
}
.swiper-container {
  max-height: 100%;
}

Working JSFiddle

I used max-content on swiper slide and that works for me

.swiper-slide {
  height: -webkit-max-content!important;
  height: -moz-max-content!important;
  height: max-content!important;
}
发布评论

评论列表(0)

  1. 暂无评论