gpt4 book ai didi

html - 如何给几个按钮不同的样式,使它们分别为 "behave"

转载 作者:行者123 更新时间:2023-11-28 17:22:26 25 4
gpt4 key购买 nike

body {
background: url(http://i.imgur.com/LMYkPk3.jpg) no-repeat center center fixed;
background-size: cover;
}

button {
display:inline-block;
margin: 0 10px 0 0;
padding: 5px 20px;
font-size: 15px;
font-family: cursive;
line-height: 1.8;
appearance: none;
box-shadow: none;
border-radius: 20px;
}

button:focus {
outline: none;
}

section.flat button {
color: #fff;
background-color: transparent;
text-shadow: -1px 1px #417cb8;
border: none;
}

section.flat button:hover,
section.flat button.hover {
background-color: transparent;
border: 2px solid orange;
}

section.flat button:active,
section.flat button.active {
background-color: mintcream;
text-shadow: -1px 1px #193047;
color: black;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css" type="text/css"/>
<title></title>
</head>
<body>
<div id="line"></div>

<section class="flat">
<button>button</button>
<button>another</button> <!-- works fine if just one button ... but as soon as there more they all "selects" when hovered over one (change of depth ...) -->

</section>






</body>

</html>

我的问题:我的页面上有两个按钮,它们的行为似乎相同。但是当我将鼠标悬停在其中一个上时,它们都会改变它们的行为(深度)。我怎样才能避免这种情况?

最佳答案

你只需要为不同的按钮添加不同的id,使它们可以单独区分。然后使用这两个 ID 进行单独的样式设置。我已经修改了您的代码,这里是工作代码 --

<body>
<div id="line"></div>

<section class="flat">
<button id = "btn1">button</button>
<button id="btn2">another</button>

</section>
</body>
<!--the css-->
button {
display:inline-block;
margin: 0 10px 0 0;
padding: 5px 20px;
font-size: 15px;
font-family: cursive;
line-height: 1.8;
appearance: none;
box-shadow: none;
border-radius: 20px;
}

button:focus
{
outline: none;
}
#btn1 {
background-color: #f0f0f8;
}



section.flat button:hover,
section.flat button.hover {
background-color: transparent;
border: 2px solid orange;
}

#btn1:active,
section.flat button.active {
background-color: mintcream;
text-shadow: -1px 1px #193047;
color: black;
}

我对您的 CSS 做了一些修改,只是为了展示它是如何工作的。正如您在下面的 fiddle 中看到的,两个按钮都有不同的 backgroung-color。干杯!

Working JSfiddle

关于html - 如何给几个按钮不同的样式,使它们分别为 "behave",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41746973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com