1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

vue-carouselでページネーション部分のスタイルを変更する

Posted at

vue-carouselはVueアプリケーションでカルーセルを実現するためのライブラリです。

問題

カルーセルのpaginetionのmargin-topが広すぎるので狭くしたいと考えました。
image.png

先人の記事を検索してみるとDev toolsでクラスを特定してそれをセレクタにしてスタイルを適用すれば良いとのこと。
それに倣ってDev toolsで対象部分のクラスを特定してstyleタグの中で以下のように記載しましたが、反映されません。

image.png

.VueCarousel-dot-container{
  margin-top: 0px;
}

Dev toolsで適用されているスタイルを確認するとセレクタがelement.styleと、タグ内にベタ書きされており、そちらが優先されているようです。

image.png

ソースを見てみる

本家リポジトリのコードを見てみます。
該当部分はPagination.vueですね。styleがバインドされているようです。
image.png
dotContainerStyleを見てみます。ありました!margin-topです。どうやらcarousel.paginationPaddingによって動的に設定されるようです。
image.png

carouselはPagination.vueにinjectされており、Carousel.vueを指しています。
image.png

Carousel.vueでpaginationPaddingを探します。Propsの中にありました!
image.png

つまりpaginationPadding propsに対して数値を与えて上げるとその2倍の数値がVueCarousel-dot-containerのmargin-topになるんですね。

<carousel :paginationPadding="5">
  <slide v-for="imageUrl in imageUrls" :key="imageUrl">
    <img :src="imageUrl" class="w-full h-full">
  </slide>
</carousel>

image.png

まとめ

paddingとmarginが連動するなんて考えもしなかったでござる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?