活动按钮不起作用

时间:2017-06-01 20:45:49

标签: html css

我希望这些按钮在单击时保持活动状态但无法使其工作,并且“currentButton”在页面加载时默认处于活动状态。我能够看到以下样式:当我点击任一按钮时激活,但点击后它不会保持活动状态。

2个按钮的HTML:

<div class="w3-center invButtons">
    <button class="w3-button currentButton">Current</button>
    <button class="w3-button pastButton">Past</button>
</div>

CSS:

.w3-button{
    border: 2px solid #555555;
    background-color: white;
    color: black;
    padding: 4px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
    width: 130px;
    border-radius: 8px;
}

.invButtons {
    padding-bottom: 16px;
    margin: 30px 10px;
}

.w3-button:hover {
    color:#000!important;
    background-color: gray!important;
}

.w3-button:active {
    color:yellow!important;
    background-color: yellow!important;
}

1 个答案:

答案 0 :(得分:1)

:active psuedo类仅在与按钮交互时应用(即&#34;活动&#34;)。就像:hover psuedo类只在鼠标悬停在元素上时才应用。

如果要将样式应用于元素以表示它是组中的活动/选定/使用中元素,则需要在单击后添加某种.active类和那个班的风格。

将该类添加到要开始激活的html中的按钮标记。

相关问题