What steps should I take to ensure my button remains intact and undamaged?

I'm encountering an issue with a CSS-styled button that appears distorted and displayed oddly across multiple lines when it is set as a link. However, if I change the button to an input element, it looks flawless. How can I ensure my link button displays the same as the input button?

For reference, please see this example:

https://jsfiddle.net/tasenudr/

Here's the HTML code snippet:

<div style="width: 200px;">
    <table style="width:80%;">
        <tr>
            <td style=" text-align: left;   vertical-align: middle;">
                <BR>    <a class="btn" target="_parent" href="index.php?ts=fq">Daily&#x00A;Starting from:&#x00A;$15.22</a>

            </td>
            <td style=" width: 4%; text-align: left;    vertical-align: middle; text-align:right;">
                <BR>
                <input type="submit" value="6 Month Plans Starting from: $75.36" style="width:90px; top:50px; height:115px; white-space: normal;" class="btn">
                </submit>
            </td>
        </tr>
    </table>
</div>

And here is the corresponding CSS code:

.btn {

    background: #FFCC02;

    border: none;

    padding: 10px 25px 10px 25px;

    color: #585858;

    border-radius: 4px;

    -moz-border-radius: 4px;

    -webkit-border-radius: 4px;

    text-shadow: 1px 1px 1px #FFE477;

    font-weight: bold;

    box-shadow: 1px 1px 1px #3D3D3D;

    -webkit-box-shadow:1px 1px 1px #3D3D3D;

    -moz-box-shadow:1px 1px 1px #3D3D3D;

}

.btn:hover {

    color: #333;

    background-color: #EBEBEB;

}

The button on the left appears distorted, while the one on the right maintains its perfect appearance.

Answer №1

Did you know that a button is actually considered an inline element?

To make it behave like a block element, simply apply either display: block; or display: inline-block;

Answer №2

To prevent the text inside a .btn element from being mangled by its native inline display, consider adding display: block to your CSS rule.

You can view an example of this solution in action at: https://jsfiddle.net/tasenudr/1/

.btn {
    background: #FFCC02;
    display: block;
    border: none;
    padding: 10px 25px 10px 25px;
    color: #585858;
    border-radius: 4px;
    -moz-border-radius: 4px;
    -webkit-border-radius: 4px;
    text-shadow: 1px 1px 1px #FFE477;
    font-weight: bold;
    box-shadow: 1px 1px 1px #3D3D3D;
    -webkit-box-shadow: 1px 1px 1px #3D3D3D;
    -moz-box-shadow: 1px 1px 1px #3D3D3D;
}

Answer №3

In order for this to function correctly, you must define the .btn as either display: inline-block or display: block.

Check out the updated demo here:
https://jsfiddle.net/rybostef/8/

.btn{
    display: inline-block;
    min-width: 250px;
    text-align:center;
}

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

Unable to remove the white space appearing below and after a div in HTML

I have been working on creating a website. You can find my JSFiddle here. On my JSFiddle, you might notice a white gap above the black image labeled INSURANCE, and another white gap below it. I've tried various solutions but haven't been able to ...

Adjusting the height in AngularJS based on the number of items in a table

I've developed a straightforward AngularJS application with multiple tables on one page. In order to add scrolling functionality, I initially used a basic CSS code snippet like: tbody { overflow: auto; } I also experimented with the https://github. ...

Google Map in Bootstrap FullScreen Mode Not Mobile-Friendly

Could you please take a look at the provided link and advise me on why the map is not responding correctly? I am also facing issues with the positioning of the map on the page, so any guidance on adjusting it appropriately would be greatly appreciated. Be ...

What is the best method to style a div using CSS to replicate the functionality of this image tag?

I have a dilemma with my image tag: <img src="/images/blah.gif" alt="blah" /> Is there a way to make this work using only CSS? I attempted the following, but unfortunately, the image is not showing up. What could be the issue? .blah { backgr ...

Lists are not limited to only <li> elements and elements that support scripts (<script> and <template>)

While testing my webpage's accessibility in Google Chrome Lighthouse, I encountered the following error. I am aware of the significance of properly structured lists in enhancing webpage accessibility. It is perplexing for me to receive this error desp ...

Tips for detecting the existence of a different class within a div/ul through jquery or javascript?

This is how I have my unordered list, or "ul" element, styled. As you can observe, there are two classes defined for the ul <ul class="nav-second-level collapse"> </ul> There might be an additional class added to the same ul like so: <u ...

The process of increasing value through a function in PHP

Looking to create a function that increments a variable when a button is clicked. I have 4 buttons: farm, cave, house, casino The goal is to accumulate the random numbers generated by each button and add them up in the "YOUR GOLD" section. For example, c ...

Certain browsers have difficulty running CSS keyframes animations

As I work on my website, I have integrated a CSS keyframes animation that is triggered by clicking a link connected to a JavaScript function. Here is an excerpt from my CSS file: #banner { background-color: #00BBD2; position: absolute; width: 100%; heigh ...

The dropdown menu vanishes from sight as soon as the cursor moves away from a link

Recently, I encountered an issue while trying to create a dropdown menu using Jquery. The problem arose when attempting to select the second link, as the entire menu would disappear. Additionally, is there a way to ensure that only one dropdown menu is vis ...

Tslint is notifying that JSX elements without any children must be self-closing to prevent errors [Error]

Recently, I encountered an issue while trying to build my solution using the command npm run build. The error message displayed was: JSX elements with no children must be self-closing. I came across a similar problem on Stack Overflow but unfortunately ...

Having trouble positioning the desired image at the bottom of the background using Tailwind CSS

I have been struggling to create a background with a video (z-index -2) and an image overlay (z-index -1). While I have managed to achieve this, I am having trouble getting the image to go all the way to the bottom where the footer is located. I am unsure ...

Tips for creating a responsive Material UI TextField that adjusts to zooming in and out

While working on my initial Material UI project, I encountered a responsiveness issue with TextField and SelectField. During development, the application looked fine at a screen width of 1920px. However, when I attempted to decrease the screen width, I no ...

Modify the transition and design of two progress bars

I'm having an issue with merging two Bootstrap progress bars into one. Initially, the first progress bar appears when the page loads and hides after data is loaded. At the same time, the second progress bar shows up. However, the transition animation ...

How is it possible for this code to function when the object is not explicitly defined within the javascript code?

While using JSLint, I encountered an issue where it stated: 'matte_canvas' is not defined. Although I have not explicitly defined 'matte_canvas' in my javascript code, it does output the canvas element in the console. Below is the code ...

Only displaying sub items upon clicking the parent item in VueJS

I'm in the process of designing a navigation sidebar with main items and corresponding sub-items. I want the sub-item to be visible only when its parent item is clicked, and when a sub-item is clicked, I aim for it to stand out with a different color. ...

Creating an HTML form that triggers a PHP script to send email upon submission via a Google Cloud Server

While running a php script to send an email upon form submission, I encountered an error message. Here are the details of the error: This XML file does not appear to have any style information associated with it. The document tree is shown below. &l ...

Issue with Bootstrap Navbar dropdown causing page refresh instead of menu dropdown activation

<!DOCTYPE html> <html lang="en" dir="ltr" style="style.css"> <!-- All icons were courtesy of FlatIcon : www.flaticon.com and FreePik : www.freepik.com --> <head> <meta charset="utf-8"&g ...

Repetitive Anchor IDs and Web Standards Compliance

Today, I encountered the task of converting outdated attributes on a page to make it more XHTML friendly. This led me to consider the anchor tag and its usage: Initially, I had anchor tags in the form of <a name="someName"></a>. However, upon ...

conceal menu upon click (gradually disappear)

This is a basic HTML/CSS menu. Currently, it is functioning properly for page redirection (href). However, I would like it to hide after being clicked on. I plan to call a function that will initiate an AJAX request upon clicking. Here is the code on JS ...

Bootstrap - extra spacing

Utilizing bootstrap, I have implemented two div elements in my HTML code: <div class="container"> <div class="col-12 circle lg-circle"> <div class="col-12 circle sm-circle"> </div> </div> </div> The corresp ...