I have some HTML code that includes some css and I want the button to actually have a use like a hyperlink I press it and it takes me to a certain file or web address I have tried using actual hyperlinks inside the field but it looked ugly and I could only press on the hyperlink, I tried adding a HTML default hyperlink button but it cannot be colored.
Here's the code:
<html>
<body style="background-color:rgb(48, 45, 45)">
<font color="white">
<font color="#4CAF50">
<head>
<style>
.button {
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button1 {background-color: #4CAF50;}
.button2 {background-color: #008CBA;}
</style>
</head>
<body>
<button >Green</button>
<button >Blue</button>
</body>
CodePudding user response:
Use an onclick
element:
<button onclick="goToStackOverflow()">Click Me</button>
<script>
function goToStackOverflow() {
document.location.href = "https://stackoverflow.com";
}
</script>
Or you could style an <a>
element to look like a button
a {
color: white;
background-color: orange;
text-decoration: none;
padding: 10px 15px;
border-radius: 8px;
cursor: pointer;
}
a:hover {
opacity: 0.8;
}
a:active {
opacity: 0.6;
}
<a href="https://stackoverflow.com">Click Me</a>
CodePudding user response:
For linking to a file specifically, you can also use the <a> tag mentioned above but with a relative URL as apposed to an absolute one (AKA, without 'https://www.' included).
For example, if you placed the file in an inner directory off your base directory, you could use the following snippet:
<a href="inner/file.html" >File</a>