我正在做一系列的按鈕用CSS來練習,這是我與CSS選擇器的意外行爲
https://codepen.io/buoyantair/pen/JNgqXG?editors=1100
現在有一些奇怪的事情在CSS發生如此,還是讓我剛把這裏的代碼
帕格腳本
header.row
.col
h1 Hover Buttons
p A small variation of buttions I made.
p Made by <a href="https://codepen.io/buoyantair">@buoyantair</a>
.row
button.btn Hello
button.btn-ghost World
button.btn-pill Cat
.row
button.btn-fall Kitty
button.btn-hang World
button.btn-wobble Cat
薩斯文件
=flex($direction, $position)
display: flex
flex-flow: $direction
justify-content: $position
=size($width, $height)
width: $width
height: $height
$color-theme: #DD403A
$btn-width: 100px
$btn-height: 50px
body
+size(100%, 100vh)
background: #3E363F
+flex(column wrap, space-around)
color: #FFF
font-family: 'Bubbler One', sans-serif
font-size: 1.5em
a,a:visited, a:active
text-decoration: none
color: inherit
header
h1
margin-bottom: 0
p
margin-top: 0
.row
+flex(row wrap, space-around)
.col
+flex(column wrap, center)
button.btn
border: none
+size($btn-width, $btn-height)
background: $color-theme
border-radius: 5px
margin: auto
color: inherit
font-family: inherit
font-size: inherit
transition: all 0.25s
border-bottom: 0px solid $color-theme
button.btn:hover
background: darken($color-theme, 10%)
border-bottom: 5px solid darken($color-theme, 20%)
cursor: pointer
button.btn:focus
outline: none
button.btn ~ [class*="-ghost"]
border: 0px solid $color-theme
+size($btn-width, $btn-height)
background: $color-theme
border-radius: 5px
margin: auto
color: inherit
font-family: inherit
font-size: inherit
transition: all 0.25s
border-bottom: 0px solid $color-theme
button.btn ~ [class*="-ghost"]:hover
background: transparent
border: 2px solid $color-theme
cursor: pointer
color: $color-theme
button.btn ~ [class*="-ghost"]:focus
outline: none
button.btn ~ [class*="-pill"]
border: 0px solid $color-theme
+size($btn-width, $btn-height)
background: $color-theme
border-radius: 25px
margin: auto
color: inherit
font-family: inherit
font-size: inherit
transition: all 0.25s
border-bottom: 0px solid $color-theme
button.btn ~ [class*="-pill"]:hover
cursor: pointer
+size($btn-width * 1.5, $btn-height)
overflow: hidden
position: relative
&:before
content: ''
display: block
@extend [class*="-pill"]
background: lighten($color-theme, 10%)
position: absolute
top: 0
left: 100%
animation: pill 1s
button.btn ~ [class*="-pill"]:focus
outline: none
button.btn ~ [class*="-fall"]
border: 0px solid $color-theme
+size($btn-width, $btn-height)
background: $color-theme
border-radius: 25px
margin: auto
color: inherit
font-family: inherit
font-size: inherit
transition: all 0.25s
border-bottom: 0px solid $color-theme
button.btn ~ [class*="-fall"]:hover
cursor: pointer
+size($btn-width * 1.5, $btn-height)
overflow: hidden
position: relative
&:before
content: ''
display: block
@extend [class*="-fall"]
background: lighten($color-theme, 10%)
position: absolute
top: 0
left: 100%
animation: pill 1s
button.btn ~ [class*="-fall"]:focus
outline: none
// Animations
@keyframes pill
0%
left: 100%
100%
left: -100%
有幾件事情是奇怪,比如我用的那種button.btn ~ [class*="-fall"]
選擇器的選擇與-fall
字在他們的類等等。因此,對於按鈕的第一行工作,但鬼使神差的是同樣的代碼沒有按」元素t爲第二排工作。我不知道爲什麼發生這種情況,所以我試圖做這樣的事情,button.btn[class*="-fall"]
也沒有工作,所以我試圖做一些像button[class*="-fall"]
這種解決方案實際上工作,[class*="-fall"]
也是如此。我現在很困惑的是,爲什麼第一次和第二次嘗試,如button.btn ~ [class*="-fall"]
和button.btn[class*="-fall"]
不工作,而其他人是?
如果我錯過了什麼,你們可以幫我嗎?我誤解了這些選擇器的用法嗎?我怎樣才能解決這個問題?
筆中的代碼與此處的代碼不匹配。我假設這裏的代碼是正確的,因爲〜combinator不會出現在你的筆的任何地方。 – BoltClock
@BoltClock哦,對不起,我只是在擺弄,哈哈,我想弄明白! – buoyantair
這就是爲什麼我不是CodePen的粉絲。 – BoltClock