Quantcast
Channel: CSSタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8945

CSS :not()をレスポンシブ適用時に使ってみた

$
0
0

はじめに

タイトルについて記事にしました。
この記事で得る内容は以下の通りです。

・ CSSの基礎知識が増える
・ CSS擬似クラス :not()について

以下参考
CSS の :not() の使いかた
[CSS]否定疑似クラス「:not」の便利な使い方と使う時の注意点

CSS :not()とは

CSSの否定擬似クラスで、指定した要素以外にスタイルを適用する

スクリーンショット 2020-12-13 10.42.04.png

コンテンツを画像の様な並びにしたくて、FlexBoxで並び順を変えようと試みましたが調整できず
container-profile-right.responsiveというクラスを新しく作って、普段はdisplay: none;
隠してスマホサイトで表示するイメージです

index.haml
.container-profile#ABOUT.container-profile__right.responsive← スマホで表示
    %p.top About Me
    .header-line.container-profile__left.container-profile__right← :not(.responsive)を当てて
    %p.top About Me ← ここと
    .header-line← ここを隠す
    %p hoge
    %p.bottom 199X年生まれ 世紀末生まれ
index.scss
@mediascreenand(max-width:768px){// 中略.container-profile{padding:2rem;display:flex;flex-direction:column;&__right.responsive{display:block;p.top{font-size:3rem;}.header-line{width:20%;margin:2remauto3rem;}}&__right:not(.responsive){// &__rightの.responsiveを除きスタイルを適用するtext-align:center;font-size:2rem;padding:3rem0;line-height:55px;p.bottom{padding-bottom:2rem;}p.top,.header-line{display:none;}}}}

クラス名を変えるなりすれば簡単でしょうが、:not()をあえて使ってみました


Viewing all articles
Browse latest Browse all 8945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>