What is the process for creating an HTML button that appears with a blue background and white text when linked?

Here is the code snippet without the link:

<!DOCTYPE html>
    <html>
    <head>
    <style>
    .button {
      display: inline-block;
      border-radius: 12px;
      background-color: #33ccff;
      border: none;
      color: #FFFFFF;
      text-align: center;
      font-size: 22px;
      padding: 20px;
      width: 195px;
      transition: all 0.5s;
      cursor: pointer;
      margin: 3px;
    }
    
    .button span {
      cursor: pointer;
      display: inline-block;
      position: relative;
      transition: 0.5s;
    }
    
    .button span:after {
      content: '\00bb';
      position: absolute;
      opacity: 0;
      top: 0;
      right: -20px;
      transition: 0.5s;
    }
    
    .button:hover span {
      padding-right: 25px;
    }
    
    .button:hover span:after {
      opacity: 1;
      right: 0;
    
    
    }
    </style>
    </head>
    <body>
    
    <button class="button" ><span>DOWNLOAD </span></button>
    
    </body>
    </html>

This is how it appears before adding the link:

I attempted to include a link in the button, but it caused issues such as resizing the button, changing its background color to gray, and the text color to black. Additionally, clicking on the button did not redirect me to the desired website.

I came across a post on Stack Overflow about adding URL links to buttons using CSS and HTML. However, I am unsure of what the .ui-state-highlight class signifies or where to incorporate it.

Can someone guide me on how to correctly add a hyperlink to the button code above so that when clicked, it directs me to another webpage? Thank you!

Answer №1

Check out this plunker:

.button {
  display: inline-block;
  border-radius: 12px;
  background-color: #33ccff;
  border: none;
  color: #FFFFFF;
  text-align: center;
  font-size: 22px;
  padding: 20px;
  width: 195px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 3px;
}

.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}

.button span:after {
  content: '\00bb';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
}

.button:hover span {
  padding-right: 25px;
}

.button:hover span:after {
  opacity: 1;
  right: 0;
}
<!DOCTYPE html>
<html>
<body>

<a href="https://stackoverflow.com" class="button" ><span>DOWNLOAD </span></a>

</body>
</html>

I made some changes to the code and replaced the button element with an a element, also adding the href attribute.

Answer №2

In most cases, utilizing a link tag would be more suitable. Buttons are typically reserved for actions like submitting a form.

You can maintain your css styles by simply converting the button to resemble this:

<a class="button" href="yourwebsitehere.com">DOWNLOAD</a>

Answer №3

<!DOCTYPE html>
    <html>
    <head>
    <style>
    .button {
      display: inline-block;
      border-radius: 12px;
      background-color: #33ccff;
      border: none;
      color: #FFFFFF;
      text-align: center;
      font-size: 22px;
      padding: 20px;
      width: 195px;
      transition: all 0.5s;
      cursor: pointer;
      margin: 3px;
    }
    
    .button span {
      cursor: pointer;
      display: inline-block;
      position: relative;
      transition: 0.5s;
    }
    
    .button span:after {
      content: '\00bb';
      position: absolute;
      opacity: 0;
      top: 0;
      right: -20px;
      transition: 0.5s;
    }
    
    .button:hover span {
      padding-right: 25px;
    }
    
    .button:hover span:after {
      opacity: 1;
      right: 0;
    
    
    }
    </style>
    </head>
    <body>
    
    <button class="button" onclick="changeSite()"><span>DOWNLOAD </span></button>
    <script>
    function changeSite()
    {
      var siteName;
      siteName="https://www.google.com/";
      window.location.href=siteName;
    }
    </script>
    
    </body>
    </html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Streamlined method for extracting information from div elements sourced from a webpage

Hey there! I have a total of 100 elements across 40 files, which equals to 4000 elements in total. My goal is to extract the src and href from each element and compile them into an array for easy database submission. <a class="market_listing_row_link ...

Combining both responsive and nonresponsive code on a single webpage

The project I am currently working on is a massive website that we cannot tackle all at once. As a result, we are developing it in phases. The challenge we are facing is transitioning from a 1990s table-based structure to a modern Bootstrap-divs responsive ...

Presenting XML data on a webpage using AJAX technology

I am currently working on setting up a web radio station with a program that allows streaming (jazler) to send xml files via ftp to a web server to automatically update information such as the current song playing and previous songs. The code for NowOnAir ...

The command `python3 manage.py findstatic` is unable to locate the static file

I have been struggling to incorporate static files into my project, but the CSS is not loading. I tried using findstatic but Django is unable to locate any static directory: https://i.sstatic.net/jRgzx.png https://i.sstatic.net/7VG0x.png In a different pr ...

What is a solution to prevent style.css from being recognized as the Jekyll Page?

Currently, I am utilizing an expression {% assign mypages = site.pages | sort: "order" %} {% for page in mypages %} {% unless page.exclude %} <a href="{{page.url|absolute_url}}"> {{ page.shortname }} <span class="rate">{% include indexmod.h ...

Creating aesthetically pleasing and uniform rows of responsive Bootstrap 4 cards with consistent heights

I'm a beginner in the world of design and Bootstrap, so please be patient with me. My goal is to create a series of cards that have equal height and width (responsive, not fixed) in each row. In other words, I want all the cards to be as tall and wid ...

In order to maintain a custom tooltip in an open state until it is hovered over, while also controlling its

When hovering over the first column of the table, a tooltip will appear. Within each material tooltip, I would like to include a button at the bottom right after the JSON data. When this button is clicked, it should open an Angular Material dialog. <ng ...

Stop the Enter key from functioning as a mouse click

Whenever an element is focused on and a mouse click action can be triggered, I've observed that the Enter key functions as if you're clicking the mouse left button. This behavior is causing conflicts in other parts of my code, so I need to find a ...

Interactive Bootstrap Card with Popover Effect on Mouse Hover

Let's say I have a Button that contains the popover data toggle: <button type="button" class="btn btn-primary" data-toggle="popover" title="User Info">Popover with Title</button> Here is the JS code ...

unable to apply background to entire section

After using HTML5 and jquery to create a section, I attempted to set an image as the background. However, the image is not filling the entire section, leaving a 2px space around all sides inside the section. Below is the code I used: <div id="container ...

Align list items in the center horizontally regardless of the width

I have created this container element: export const Container = styled.section<ContainerProps>` display: flex; justify-content: center; `; The current setup is vertically centering three list items within the container. However, I am now looking ...

Ensure that the form is validated using ngDialog openConfirm before it can be closed

I am facing an issue with a button that triggers the opening of an ngDialog.openConfirm. In this dialog, there is a form containing a textarea that must have a minimum of 20 characters. Below is a simplified version of the code: someFunction() { let ...

Incorporating Google fonts into email designs

I am struggling to get Google fonts to display properly in my newsletter emails. Here is the code snippet I have been using: $html=" <html> <style> @import url(http://fonts.googleapis.com/css?family=Lato|Simonetta); </style> <body& ...

Issue with nested tabs functionality within a pill tab panel in Bootstrap not functioning as expected

I'm facing a challenge with integrating tabs into a vertical pill tab panel in Bootstrap 4. Below is a brief code snippet: <html> <head> <link href="bootstrap.min.css" rel="stylesheet"> </head> <body> <script ...

Tips for preserving a string in angularJS or Java (and implementing it in an iframe)

My plan involves utilizing a Java web service to fetch the HTML content from a specific URL using Jsoup, and then returning it as a string to the requesting party, which could be an Angular or JS script. I am keen on preserving this content somewhere and l ...

Guide for displaying information as a grid or table format using Angular 4

I am tasked with handling data from an external microservice that is not always in a standard format. The data is dynamic and can include table data, along with metadata information above the grid. My challenge is to render or identify the table data, disp ...

Tips for positioning the navbar to avoid covering the logo:

I am experiencing difficulty in aligning my navbar. When I resize the window, the navbar overlaps with the logo... Here is the Fiddle Here is the code: <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation" style="background: rgba(0,0, ...

Increase the height of a component when viewed on mobile devices

https://jsfiddle.net/7v0dyfo3/ This is the concept I am attempting to implement for a listing, albeit without proper styling. While it looks good on most screens, the issue arises with its resizing behavior. I aim for the episode-box div to adapt its heig ...

I currently have some code for a toggle button and a collapse feature, but I'm struggling to integrate the two

I need assistance with implementing a toggle animation I found here: https://codepen.io/7harrypotterrr/pen/OrBwPY. I'm unsure how to apply it to my code and replace the current toggle button that is in use here: https://codepen.io/7harrypotterrr/pen/e ...

Instructions on integrating iframe into Slides on material-auto-rotating-carousel

Looking to swap out the carousel slide image with a loom video. Any ideas on how to replace the media img with an iframe in material-auto-rotating-carousel? const AutoRotatingCarouselModal = ({ handleOpen, setHandleOpen, isMobile }) => { return ( ...