html - CSS3:box-shadow 过渡不适用于伪类
问题描述
我在所有浏览器中的 box-shadow 都遇到了一些奇怪的问题。
我想做的事:
当我的输入处于 :focus 时,平滑我的输入上的框阴影。
问题:
下面的代码工作得很好,过渡很顺利:注意我是如何在“默认”状态下省略 box-shadow 的。
#message-main #message {
border: none;
padding: 0.5em 0.75em 0.5em 0.75em;
border-radius: $border-radius-input;
background-color: $background-input;
//box-shadow: 5px 5px 8px #a7a7a7, -5px -5px 8px #f5f5f5;
transition: all 0.3s ease-in-out;
font-size: 1rem;
width: 100%;
min-height: 39px;
resize: vertical;
resize: block;
}
#message-main #message:focus {
box-shadow: inset 5px 5px 8px #a7a7a7, inset -5px -5px 8px #f5f5f5;
}
<div id="message-main">
<label class="label is-required" for="message">Ihre Nachricht</label>
<textarea id="message" class="inputfields required" name="message" rows="10" cols="46" placeholder="Schreiben Sie uns Ihre Nachricht." maxlength="1250" spellcheck="true" required></textarea>
</div>
一旦我为默认状态添加了 box-shadow,过渡就不再平滑但仍在工作。
#message-main #message {
border: none;
padding: 0.5em 0.75em 0.5em 0.75em;
border-radius: $border-radius-input;
background-color: $background-input;
box-shadow: 5px 5px 8px #a7a7a7, -5px -5px 8px #f5f5f5;
transition: all 0.3s ease-in-out;
font-size: 1rem;
width: 100%;
min-height: 39px;
resize: vertical;
resize: block;
}
#message-main #message:focus {
box-shadow: inset 5px 5px 8px #a7a7a7, inset -5px -5px 8px #f5f5f5;
}
<div id="message-main">
<label class="label is-required" for="message">Ihre Nachricht</label>
<textarea id="message" class="inputfields required" name="message" rows="10" cols="46" placeholder="Schreiben Sie uns Ihre Nachricht." maxlength="1250" spellcheck="true" required></textarea>
</div>
我到底在这里想念什么?
解决方案
这是因为在后面的代码片段中,您将 box-shadow 的方向从默认(未指定时)outset
更改为inset
.
运行我的代码片段以更好地理解这一点。还可以阅读这篇关于 box-shadow 过渡性能的精彩文章https://tobiasahlin.com/blog/how-to-animate-box-shadow/
#message-main #message {
border: none;
padding: 0.5em 0.75em 0.5em 0.75em;
border-radius: $border-radius-input;
background-color: $background-input;
box-shadow: inset 0px 0px 0px #a7a7a7, inset 0px 0px 0px #f5f5f5;
transition: all 0.3s ease-in-out;
font-size: 1rem;
width: 100%;
min-height: 39px;
resize: vertical;
resize: block;
}
#message-main #message:focus {
box-shadow: inset 5px 5px 8px #a7a7a7, inset -5px -5px 8px #f5f5f5;
}
<div id="message-main">
<label class="label is-required" for="message">Ihre Nachricht</label>
<textarea id="message" class="inputfields required" name="message" rows="10" cols="46" placeholder="Schreiben Sie uns Ihre Nachricht." maxlength="1250" spellcheck="true" required></textarea>
</div>
推荐阅读
- python - 处理循环异常
- ibm-content-navigator - 在 ContentNavigator 中放置依赖 jar 的推荐方法
- python - 使用随机森林去除 Dataframe 中的 NaN-, Infinite 值
- git - 维护对上游 Git 存储库的子目录的引用
- jekyll - Jekyll - 组装模型
- javascript - 如何从模板中提取车把列表?
- java - jaxb2-maven-plugin 在 Java 8 上失败
- git - 如何 Git Un 暂存所有暂存文件?
- git - 如何使用 perl Git::Repository 模块进行等效的“git push -u origin master”?
- mqtt - mosquitto.conf:带空格的桥接主题名称