【发布时间】:2017-11-02 02:43:59
【问题描述】:
我正在制作一系列按钮来练习 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
Sass 文件
=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 单词的元素等。所以这适用于第一行按钮,但神秘的是相同的代码不适用于第二行。我不确定为什么会这样,所以我尝试做类似button.btn[class*="-fall"] 的事情,但也没有用,所以我尝试做类似button[class*="-fall"] 的事情,这个解决方案确实有效,[class*="-fall"] 也是如此。我现在真正困惑的是为什么第一次和第二次尝试像button.btn ~ [class*="-fall"]
和button.btn[class*="-fall"] 在其他人工作时不工作?
如果我遗漏了什么,你们能帮我吗?我误解了这些选择器的用法吗?我怎样才能解决这个问题?
【问题讨论】:
-
您笔中的代码与此处的代码不匹配。我假设这里的代码是正确的,因为 ~ 组合符不会出现在您的笔中。
-
@BoltClock 哦,对不起,我只是在摆弄,哈哈,我想弄清楚!
-
这就是我不喜欢 CodePen 的原因。
标签: html css sass css-selectors pug