When trying to make a navigation header using <button>
tags instead of <a>
tags, I noticed that the id for a normal button and the id for an active button (the button for the page that is selected) cannot be defined in the same file. I define all my CSS code in a file that is linked to my HTML/PHP documents and had to instead define my active button ID in a <style>
tag in the <head>
section of my code. Thus, I wonder is there a way to define my normal buttons and active button in the same CSS file; preferably because I don't want a huge <style>
section in my HTML files?
Non-working code:
Styles.css
#NavBtn {
background-color: deepskyblue;
-moz-border-radius: 28px;
-webkit-border-radius: 28px;
border-radius: 28px;
border: 2px solid deepskyblue;
display: inline-block;
cursor: pointer;
color: white;
font-family: Arial;
font-size: 17px;
padding: 16px 31px;
text-decoration: none;
text-shadow: 0px 1px 0px gray;
}
#NavBtn:hover {
background-color: deepskyblue;
}
#NavBtn:active {
position: relative;
top: 1px;
border: 2px solid black;
}
#NavBtnActive {
background-color: deepskyblue;
-moz-border-radius: 28px;
-webkit-border-radius: 28px;
border-radius: 28px;
border: 2px solid yellow;
display: inline-block;
cursor: pointer;
color: white;
font-family: Arial;
font-size: 17px;
padding: 16px 31px;
text-decoration: none;
text-shadow: 0px 1px 0px gray;
}
#NavBtnActive:hover {
background-color: deepskyblue;
}
#NavBtnActive:active {
position: relative;
top: 1px;
border: 2px solid black;
}
Home.html
<head>
<link rel="stylesheet" type="text/css" href="Design.css">
</head>
<body>
<button id="NavBtnActive">Home</button>
<button id="NavBtn">Test</button>
</body>
This code outputs the desired button format for all buttons with id="NavBtn"
but outputs the standard html button format for the active button with id="NavBtnActive"
My inefficient solution:
Styles.css
#NavBtn {
background-color: deepskyblue;
-moz-border-radius: 28px;
-webkit-border-radius: 28px;
border-radius: 28px;
border: 2px solid deepskyblue;
display: inline-block;
cursor: pointer;
color: white;
font-family: Arial;
font-size: 17px;
padding: 16px 31px;
text-decoration: none;
text-shadow: 0px 1px 0px gray;
}
#NavBtn:hover {
background-color: deepskyblue;
}
#NavBtn:active {
position: relative;
top: 1px;
border: 2px solid black;
}
Home.html
<head>
<link rel="stylesheet" type="text/css" href="Design.css">
<style>
#NavBtnActive {
background-color: deepskyblue;
-moz-border-radius: 28px;
-webkit-border-radius: 28px;
border-radius: 28px;
border: 2px solid yellow;
display: inline-block;
cursor: pointer;
color: white;
font-family: Arial;
font-size: 17px;
padding: 16px 31px;
text-decoration: none;
text-shadow: 0px 1px 0px gray;
}
#NavBtnActive:hover {
background-color: deepskyblue;
}
#NavBtnActive:active {
position: relative;
top: 1px;
border: 2px solid black;
}
</style>
</head>
<body>
<button id="NavBtnActive">Home</button>
<button id="NavBtn">Test</button>
</body>
Revised code based on feedback but still doesn't work:
Styles.css
.navBtn {
background-color: deepskyblue;
-moz-border-radius: 28px;
-webkit-border-radius: 28px;
border-radius: 28px;
border: 2px solid deepskyblue;
display: inline-block;
cursor: pointer;
color: white;
font-family: Arial;
font-size: 17px;
padding: 16px 31px;
text-decoration: none;
text-shadow: 0px 1px 0px gray;
}
.navBtn:hover {
background-color: deepskyblue;
}
.navBtn:active {
position: relative;
top: 1px;
border: 2px solid black;
}
.navBtn.active {
border: 2px solid yellow;
}
Home.html
<head>
<link rel="stylesheet" type="text/css" href="Styles.css">
</head
<body>
<button class="navBtn active">Home</button>
<button class="navBtn">Test</button>
</body