Adding vibrant color to buttons and eliminating underlines from anchor elements inside

Need help creating a button with the entire area in red color, and the href text should only display "OCR" without hyperlink formatting. Button images have been included as well.

.block0 {
  display: block;
  width: 100%;
  border: none;
  background-color: red;
  padding: 5px 15px;
  font-size: 16px;
  cursor: pointer;
  text-align: center;
}
<td><button><a href="/update_ocr/{{ row.0 }}" class="block{{row.3}}" value="{{row.3}}">OCR</a></button></td>

Answer №1

Avoid combining anchors with buttons as it contradicts the purpose and violates HTML standards.

Instead, style your anchors to look like buttons and remove any text decorations.

.anchor-btn {
  display: block;
  background-color: blue;
  padding: 8px 12px;
  font-size: 18px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  border-radius: 6px;
  border: 1px solid #999;
  transition: all 0.4s;
}

.anchor-btn.orange {
  background-color: orange;
}

.anchor-btn:hover {
background-color: darkblue;
}

.anchor-btn.orange:hover {
  background-color: darkorange;
}

td {
  padding: 6px;
}
<table>
  <tr>
    <td><a href="/update_info/{{ row.0 }}" class="anchor-btn block{{row.3}}" value="{{row.3}}">Info</a></td>
    <td><a href="/update_info/{{ row.0 }}" class="anchor-btn orange block{{row.3}}" value="{{row.3}}">Info</a></td>
    <td><a href="/update_info/{{ row.0 }}" class="anchor-btn block{{row.3}}" value="{{row.3}}">Info</a></td>
  </tr>
</table>

Answer №2

It seems like you are mistakenly applying the background-color to your link instead of the button. This is causing only the link to have the background color, not the entire button.

Keep in mind that structuring your code in this way is not recommended. It's best to make your link resemble a button or use an onClick event handler on the button to properly redirect users. Avoid nesting a link inside a button as it can negatively impact accessibility for screen readers and may result in poor website/application scores.

Here is a suggested solution:

function onClick() {
  window.location.href = "#";
}
.link {
  text-decoration: none;
  background-color: red;
  padding: 5px 15px;
  font-size: 16px;
  cursor: pointer;
  text-align: center;
}

.btn {
  border: none;
  background-color: red;
  padding: 5px 15px;
  font-size: 16px;
  cursor: pointer;
  text-align: center;
}
<td><a href="#" class="link">OCR</a></td>
  
<td><button class="btn" onClick="onClick">OCR</button></td>

For resolving your issue, consider adopting the following approach:

.block0 {
  border: none;
  background-color: red;
  padding: 5px 15px;
  font-size: 16px;
  cursor: pointer;
  text-align: center;
}

.link0 {
  text-decoration: none;
}
<td><button class="block0"><a href="/update_ocr/{{ row.0 }}" class="link0" value="{{row.3}}">OCR</a></button></td>

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

A guide to filling an irregular shape (such as a star) based on a percentage using CSS in a React project

I am currently working on developing a React component that showcases a rating percentage using a star icon with two different shades. For example, if the input rating is 79%, I want to display a star with 79% of it in gold color and the remaining 21% in ...

The arrangement of elements in an inline-block is determined by the width of the section

I have been attempting to replicate the layout shown in the image for quite some time. The elements (.element) are aligned vertically but they are not centered, instead they stick to the left side. My current code is as follows: HTML: <div id="_tec ...

Guide to integrating a static page with personalized CSS and JavaScript resources within a Rails project

Currently, I am developing a simple Rails application (using Rails version 4.1) and I am looking to incorporate a static page into it. The static page is structured as follows: | |- index.html |- css folder |-- (various css files) |- js folder |-- (some j ...

Sequential queuing of transitions in CSS3

Is it possible to queue CSS transitions with the same properties? My goal is to translate an element to a specific position (with a transition duration of 0) before translating it again. For example, in this mockup, clicking "move" should move the box 100 ...

Is there a way to shift the page footer and bar down to the very bottom of the screen?

Is it possible to move the footer and footer bar to the very bottom of the page instead of just under the contents? I'm currently using the Sydney theme for WordPress and want the footer to sit across the bottom of the full-screen image. .footer-wid ...

Calculate the total number of vacation days not including holidays and weekend days

Looking for help with a program I've created to calculate total vacation days, excluding weekends and national holidays. Successfully excluded weekends, but struggling with how to ignore national holidays in the calculation. The program is built usin ...

troubles arise when using undeclared functions in javascript

Recently, I've been working on implementing a Javascript CountDown Timer triggered by a button click. The Javascript code is stored in an external file, as well as the CSS for styling the timer. The problem arose when I tried including the Javascript ...

Rails application experiencing issues with Materialize CSS checkbox functionality

I'm having trouble getting checkboxes to display on a form for users to choose workshops. I am using the Materialize CSS gem with Rails. Here is my form: <div class="row"> <% workshops = Workshop.all.order("date") %> <% workshops. ...

What steps can I take to get rid of the 'Optimize CSS Delivery' notification on my website?

Utilizing Google's PageSpeed Insights to analyze my website's speed, I have identified an issue: Your page currently has 11 blocking CSS resources, resulting in slower rendering time. About 5% of the content above-the-fold could be displayed with ...

What is the best way to horizontally scroll and maintain the center alignment of a fixed-width div, especially when it exceeds the width of the browser window?

My current setup is almost perfect, but I am struggling to keep the green rectangle centered on the browser between 835px and 320px width. Any solutions using CSS or JavaScript are welcome. This is my first time posting a question on stackoverflow, so I h ...

jquery allows you to toggle the visibility of content

There are two divs with a button positioned above them. Initially, only one div, the catalogusOrderBox, is visible. When the button named manualButton is clicked, it should display the manualOrderBox div while hiding the catalogusOrderBox div. The text on ...

The unique design of the list extends beyond the boundary line

In my current project, I am utilizing next.js and MUI (material-ui). The component I am working with has the following structure: <Paper> <List> .. </List> </Paper> One issue I am facing is that when the list is scrolled, the ...

When I expand one panel, I want to automatically close any other opened panel to ensure only one section is expanded at a

I'm experiencing an issue with the Bootstrap 4 accordion. Currently, when I open a collapsed section in the accordion, it remains open even when I click on another collapsed section. What I actually want is for the previously opened section to close ...

Tips on eliminating the blue color from a hyperlink within a button

Currently, I am in the process of designing an HTML email template. I have included a green button in the template and now need to eliminate the blue color from the hyperlink within the button. I have exhaustively tried different solutions such as using ! ...

Exploring the depths of complex structures with Selenium to uncover hidden elements

If we look at this particular piece of HTML code: <tr class="highlight"> <td><center><a href="example.code"> Bar </a></center></td> <td><center> Foo </center></td> &l ...

Issue with a "hover" effect on a specific input[type="submit"] button

I'm having trouble getting my CSS styles to apply correctly to the input field. Can anyone help me understand why this is happening? If you'd like to take a look at the code, here are the links to the .html file and the .CSS styles. The goal is ...

unable to utilize the If - Else statement for checking element existence in Javascript

After writing a JavaScript function to create a table in both HTML and JS, I encountered an issue. When I click submit, the table is created, but if I click submit again, it creates another table. I attempted to use if-else statements in the function, but ...

How do I view a wildcard in my ID selector using jQuery?

When I want to initially hide various content scattered around the page, I usually use the following jQuery code: $('#objective_details, #time_estimate_details, #team_members_details, #resources_details').hide(); Is there a method to utilize a ...

Connecting JavaScript and HTML in EclipseWould you like to know how to link

After completing the Rock Paper Scissors exercise on Codecademy, I wanted to transfer it to my Eclipse IDE. The code worked perfectly on the Codecademy platform, so I copied everything and created a .js workspace in Eclipse to paste it there. Now, my ques ...

Ensuring WCAG Accessibility Compliance - mandate the inclusion of at least one input in a fieldset

I'm working on a form where users need to provide at least one contact method from a group of fields, such as home, work, or mobile phone number. How can I ensure this meets the latest WCAG 2.2 standards? <!-- Other fields above and below --> ...