html - 如何编辑两个ID?
问题描述
我在向我的 CSS 添加超过 1 个 ID 时遇到问题。我希望框边框有四个不同的按钮(悬停效果)和三个渐变按钮(例如:播放、图片等)。
这是我的 HTML
<h2><a id="hover-1" href="">Hover Effect 1</a></h2>
<h2><a id="hover-2" href="">Hover Effect 2</a></h2>
<a href="" id="play">Play</a><br/>
<a href="" id="picture">Picture</a><br/>
这是CSS
<style>
/* Gradient*/
body {
padding: 3em;
}
#play {
color: blue;
font: bold 3em/1.5 , sans-serif;
text-decoration: none;
text-transform: uppercase;
-webkit-transition: .2s;
}
#play:hover {
color: hotPink;
}
@media (-webkit-min-device-pixel-ratio:0) {
#play {
background-color: skyBlue;
background-image: -webkit-linear-gradient(left, hotPink 0%, orange 50%, transparent 50%);
background-position: 100% 0;
background-size: 200% 200%;
color: transparent;
-webkit-transition: .1s .2s;
-webkit-background-clip: text;
}
#play:hover {
background-position: 0 0;
color: transparent;
transition: .4s 0;
}
}
/*Box Border*/
html {
box-sizing: border-box
}
*, *:before, *:after {
box-sizing: border-box;
}
body {
width: 80%;
margin: 50px auto;
color:black;
font: 16px/1 'Catamaran', sans-serif;
background: transparent;
}
body:after {
content: '';
display: flex;
clear: both;
}
h2 {
width: 50%;
text-align: center;
height: 44px;
line-height: 24px;
font-weight: 400;
}
@media screen and (max-width: 768px) {
h2 {
width: 100%;
}
h1 {
margin-bottom: 15px;
line-height: 30px;
}
}
a, a > span {
position: relative;
color: inherit;
text-decoration: none;
line-height: 24px;
}
a:before, a:after, a > span:before, a > span:after {
content: '';
position: absolute;
transition: transform .5s ease;
}
#hover-1 {
padding: 10px;
}
#hover-1:before, #hover-1:after {
left: 0;
top: 0;
width: 100%;
height: 100%;
border-style: solid;
border-color: black;
}
#hover-1:before {
border-width: 2px 0 2px 0;
transform: scaleX(0);
}
#hover-1:after {
border-width: 0 2px 0 2px;
transform: scaleY(0);
}
#hover-1:hover:before, #hover-1:hover:after {
transform: scale(1, 1);
}
</style>
我试图将这两个 ID 添加到所有的 css 中,就像这样,
#play, #picture {
color: blue;
font: bold 3em/1.5 , sans-serif;
text-decoration: none;
text-transform: uppercase;
-webkit-transition: .2s;
}
但由于某种原因,这种能力起作用了。如果你能帮忙,谢谢!不要犹豫,问问题!
解决方案
问题是这样的:
@media (-webkit-min-device-pixel-ratio:0) {
#play {
background-color: skyBlue;
background-image: -webkit-linear-gradient(left, hotPink 0%, orange 50%, transparent 50%);
background-position: 100% 0;
background-size: 200% 200%;
color: transparent;
-webkit-transition: .1s .2s;
-webkit-background-clip: text;
}
@media (-webkit-min-device-pixel-ratio:0)
最小比率设置为 0,因此将#play
始终具有此样式。因此,您可以添加#picture
到此样式或删除此样式并添加#picure
到:
#play, #picture {
color: blue;
font: bold 3em/1.5 , sans-serif;
text-decoration: none;
text-transform: uppercase;
-webkit-transition: .2s;
}
完整的 CSS:
/* Gradient*/
body {
padding: 3em;
}
#play, #picture {
color: blue;
font: bold 3em/1.5 , sans-serif;
text-decoration: none;
text-transform: uppercase;
-webkit-transition: .2s;
}
#play:hover {
color: hotPink;
}
@media (-webkit-min-device-pixel-ratio:0) {
#play:hover {
background-position: 0 0;
color: transparent;
transition: .4s 0;
}
}
#picture:hover {
background-position: 0 0;
color: transparent;
transition: .4s 0;
}
}
/*Box Border*/
html {
box-sizing: border-box
}
*, *:before, *:after {
box-sizing: border-box;
}
body {
width: 80%;
margin: 50px auto;
color:black;
font: 16px/1 'Catamaran', sans-serif;
background: transparent;
}
body:after {
content: '';
display: flex;
clear: both;
}
h2 {
width: 50%;
text-align: center;
height: 44px;
line-height: 24px;
font-weight: 400;
}
@media screen and (max-width: 768px) {
h2 {
width: 100%;
}
h1 {
margin-bottom: 15px;
line-height: 30px;
}
}
a, a > span {
position: relative;
color: inherit;
text-decoration: none;
line-height: 24px;
}
a:before, a:after, a > span:before, a > span:after {
content: '';
position: absolute;
transition: transform .5s ease;
}
#hover-1, #hover-2 {
padding: 10px;
}
#hover-1:before, #hover-1:after {
left: 0;
top: 0;
width: 100%;
height: 100%;
border-style: solid;
border-color: black;
}
#hover-1:before {
border-width: 2px 0 2px 0;
transform: scaleX(0);
}
#hover-1:after {
border-width: 0 2px 0 2px;
transform: scaleY(0);
}
#hover-1:hover:before, #hover-1:hover:after {
transform: scale(1, 1);
}
#hover-2:before, #hover-2:after {
left: 0;
top: 0;
width: 100%;
height: 100%;
border-style: solid;
border-color: black;
}
#hover-2:before {
border-width: 2px 0 2px 0;
transform: scaleX(0);
}
#hover-2:after {
border-width: 0 2px 0 2px;
transform: scaleY(0);
}
#hover-2:hover:before, #hover-2:hover:after {
transform: scale(1, 1);
}
编辑:更改 CSS 以供评论
推荐阅读
- bash - 如何遍历路径包含在 BASH 中的目录
- c# - 如何从桌面应用程序视图切换到 Web 视图并再次返回?
- java - Hibernate 扩展实体以使用附加连接进行读取
- sql - 查询执行时间过长
- java - 为什么 hashCode() 函数会产生错误
- java - 将 awssdk s3 v2 与 GCS 和 Minio 网关一起使用时出现 Etag 解码错误
- oracle - 为什么我得到一个 ORA-24247 代码在函数中但不在匿名块中?
- react-native - 如何使用 redux saga 实现 redux 持久化?
- python-3.x - 使用 Machin 方法估计 pi 的准确性问题
- javascript - 如何使已转换为 JSON 的 Excel 文件自动加载到表(DataTables)