Unexpected issue with hover button size causing malfunction

While designing my website, I encountered an issue with the interactive rollover button. When hovered over, the width of the button increases significantly. I tried adjusting the width in the stylesheet, but it did not change the outcome. I still want to retain the functionality of the button.

Sincerely, Validix.

body {
    background-color: rgb(10, 10, 10);
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Announcment bar */
.alert {
    padding: 20px;
    background-color: #2a7a85;
    color: white;
}

.closebtn {
    margin-left: 15px;
    color: white;
    font-weight: bold;
    float: right;
    font-size: 22px;
    line-height: 20px;
    cursor: pointer;
    transition: 0.3s;
}

.closebtn:hover {
    color: black;
}

body {
    margin: 0;
}
/* Navigation bar */
ul.topnav {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: rgb(248, 248, 248);
}

ul.topnav li {
    float: left;
}

ul.topnav li a {
    display: block;
    color: black;
    text-align: center;
    font-weight: bold;
    padding: 25px 32px;
    text-decoration: none;
}

ul.topnav li a:hover:not(.active) {
    background-color: rgb(55, 81, 165);
}

ul.topnav li a.active {
    background-color: #0cc0d8;
}

ul.topnav li.right {
    float: right;
}

@media screen and (max-width: 600px) {
    ul.topnav li.right,
    ul.topnav li {
        float: none;
    }
}

/* Services Section on product page */
.services {
    background: rgb(10, 10, 10);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.services h1 {
    background-color: #77ff7e;
    background-image: linear-gradient(
        to right,
        #00eeff 0%,
        #0df1de 0%,
        #0ad3f7 21%,
        #2b86db 52%,
        #23a6da 78%,
        #06afda 100%
    );
    background-size: 100%;

    -webkit-text-fill-color: transparent;
    -moz-text-fill-color: transparent;
    margin-bottom: 5rem;
    font-size: 2.5rem;
}

.services__container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}

.services__card {
    margin: 1rem;
    height: 525px;
    width: 400px;
    border-radius: 4px;
    background-image: linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0) 0%,
            rgba(17, 17, 17, 0.6) 100%
        ),
        url('img/bus.PNG');
    background-size: cover;
    position: relative;
    color: #fff;
}

.services__card:before {
    opacity: 0.2;
}

services__card:nth-child(2) {
    background-image: linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0) 0%,
            rgba(17, 17, 17, 0.9) 100%
        ),
        url('img/bus.PNG');
}

services__card h2 {
    position: absolute;
    top: 350px;
    left: 30px;
}

services__card p {
    position: absolute;
    top: 400px;
    left: 30px;
}

services__card button {
    color: #fff;
    padding: 10px 20px;
    border: none;
    outline: none;
    border-radius: 4px;
    background: #19b6bb;
    position: absolute;
    top: 440px;
    left: 30px;
    font-size: 1rem;
}

services__card button:hover {
    cursor: pointer;
}

services__card:hover {
    transform: scale(1.075);
    transition: 0.2s ease-in;
    cursor: pointer;
}

@media screen and (max-width: 960px) {
    .services {
        height: 1600px;
    }

    .services h1 {
        font-size: 2rem;
        margin-top: 12rem;
    }
}

@media screen and (max-width: 480px) {
    .services {
        height: 1400px;
    }

    .services h1 {
        font-size: 1.2rem;
    }

    .services__card {
        width: 300px;
    }
}

/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
    .text {
        font-size: 11px;
    }
}

/* "not needed*/

.textcontainer2 {
    font-size: 2.5vh;
    color: whitesmoke;

    /* buttons */
}
.main__btn {
    font-size: 1rem;
    background-image: linear-gradient(to top, #008cff 0%, #0e0bec 100%);
    padding: 14px 32px;
    border: none;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    transition: all 0.35s;
    outline: none;
}

main__btn a {
    position: relative;
    z-index: 2;
    color: #fff;
    text-decoration: none;
}

main__btn:after {
    position: absolute;
    content: '';
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: #4837ff;
    transition: all 0.35s;
    border-radius: 4px;
}

main__btn:hover {
    color: #fff;
}

main__btn:hover:after {
    width: 100%;


}

h1 {
    font-size: 60px;
    margin: 0;
    padding: 0;
    font-family: 'Courier New', Courier, monospace;
    color: blue;
    word-wrap: break-word;
    text-align: center;
}

container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

btn-centering {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

text {
    width: 100%;
}
<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="icon" href="img/icon.png" />

        <link rel="stylesheet" href="styles.css" />
    </head>
    <body>
        <div class="container">
            <div class="alert">
                <span
                    class="closebtn"
                    onclick="this.parentElement.style.display='none';"
                    >&times;</span
                >
                <center>
                    <strong>DEALS NOW ON!</strong> Upto 30% discounts this
                    christmas
                </center>
            </div>

            <ul class="topnav">
                <li><img src="img/logo.png" /></li>
                <li><a class="active" href="index.html">Home</a></li>
                <li><a href="Products.html">Products</a></li>
                <li><a href="#contact">Contact Us</a></li>
                <li class="right"><a href="#about">About Us</a></li>
            </ul>

            <div class="btn-centering">
                <div class="text"><h1>Kipplo.co.uk</h1></div>
                <button class="main__btn">
                    <a href="#">More Information</a>
                </button>
            </div>
        </div>
    </body>
</html>

Answer №1

//Greetings! It's been brought to my attention that the relative positioning setting is missing for the button (main__btn)

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>    body {
        background-color: rgb(10, 10, 10);
    }

    html,
    body {
        max-width: 100%;
        overflow-x: hidden;
    }

    /* Announcment bar */
    .alert {
        padding: 20px;
        background-color: #2a7a85;
        color: white;
    }

    .closebtn {
        margin-left: 15px;
        color: white;
        font-weight: bold;
        float: right;
        font-size: 22px;
        line-height: 20px;
        cursor: pointer;
        transition: 0.3s;
    }

    .closebtn:hover {
        color: black;
    }

    body {
        margin: 0;
    }
    /* Navigation bar */
    ul.topnav {
        list-style-type: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: rgb(248, 248, 248);
    }

    ul.topnav li {
        float: left;
    }

    ul.topnav li a {
        display: block;
        color: black;
        text-align: center;
        font-weight: bold;
        padding: 25px 32px;
        text-decoration: none;
    }

    ul.topnav li a:hover:not(.active) {
        background-color: rgb(55, 81, 165);
    }

    ul.topnav li a.active {
        background-color: #0cc0d8;
    }

    ul.topnav li.right {
        float: right;
    }

    @media screen and (max-width: 600px) {
        ul.topnav li.right,
        ul.topnav li {
            float: none;
    <!DOCTYPE html>
    <html>
        <head>
            <meta name="viewport" content="width=device-width, initial-scale=1.0" />
            <link rel="icon" href="img/icon.png" />

            <link rel="stylesheet" href="styles.css" />
        </head>
        <body>
            <div class="container">
                <div class="alert">
                    <span
                        class="closebtn"
                        onclick="this.parentElement.style.display='none';"
                        >&times;</span
                    >
                    <center>
                        <strong>DEALS NOW ON!</strong> Upto 30% discounts this
                        christmas
                    </center>
                </div>

                <ul class="topnav">
                    <li><img src="img/logo.png" /></li>
                    <li><a class="active" href="index.html">Home</a></li>
                    <li><a href="Products.html">Products</a></li>
                    <li><a href="#contact">Contact Us</a></li>
                    <li class="right"><a href="#about">About Us</a></li>
                </ul>

                <div class="btn-centering">
                    <div class="text"><h1>Kipplo.co.uk</h1></div>
                    <button class="main__btn">
                        <a href="#">More Information</a>
                    </button>
                </div>
            </div>
        </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

Modify the innerHTML to adjust font size when a button is clicked in Ionic 5, or eliminate any unnecessary spaces

I have been experimenting with changing the font size of a variable in .html when the variable contains whitespace. In my .ts page, I use the following code to remove the whitespace: this.contents = this.sanitizer.bypassSecurityTrustHtml(this.product[&apos ...

Designing a webpage visitor tracker using the innerHTML attribute

I'm currently working on a webpage that tracks the number of times it gets loaded and displays this count to users. I am using localhost MAMP for testing. Check out the code snippet below: <html> <head> <title>Test Page</titl ...

Guide on setting the style attribute in HTML within double quotes (as a String)

I have a straightforward question. I am attempting to include a style attribute in an HTML code that is in string format. I am passing the HTML code as a string through a method, and later I need to apply CSS to it based on certain conditions. I attempted ...

Adaptable layout - featuring 2 cards side by side for smaller screens

I am currently designing a webpage that showcases a row of cards, each featuring an image and a title. At the moment, I am utilizing the Bootstrap grid system to display 4 cards per row on larger screens (col-md-2), but my goal is to modify this layout t ...

Unable to select selectbox in the bottom section of Safari browser

There seems to be an issue with the selectbox being unselectable at the lower part in Safari. It's difficult to pinpoint the exact problem in the code. You can see the issue on the country selectbox by visiting this website: <span> <sp ...

Progress Circles on Canvas in FireFox

Currently, I am experimenting with this codepen demo that utilizes canvas to generate progress circles: The functionality functions perfectly in Chrome and Safari; however, it only displays black circles in FireFox. My knowledge of canvas is limited, so I ...

Changing the placement of navbar components in Bootstrap 4 based on screen size

Through the use of Bootstrap 4, I have successfully created a navbar that collapses into a button when the screen size decreases. However, I am facing an issue where one item (the icon image) gets centered while the rest of the items are aligned to the lef ...

Issue with !important keyword taking precedence not resolved

While working on a navigation bar button, I encountered a specificity conflict with the opacity property. I attempted to use the !important override but it doesn't seem to be taking effect. Any insights into why this might be happening? Here is the H ...

Centering images of varying sizes on Bootstrap cards

My task involves incorporating a list of organization logos and links inside cards using HTML code. However, every time I add a logo, the card size changes in accordance with the logo's size, and the image is not centered within the card. I attempte ...

Adjust the dimensions of the Twitter Bootstrap Modal to match the maximum resolution of the user's screen

When the "Launch demo modal" button is clicked: I would like the modal to adjust its width and height based on the user's screen resolution, maximizing the available space. Additionally, I want the modal to appear in the top left corner of the docume ...

Issue with displaying jQuery class names accurately

I am implementing jquery.scrollablecombo.js for a dropdown menu using jQuery. However, when I include it in my HTML code, the class attribute is displayed as "classname" instead of "class." See the example below: <div classname="searchBar cb_selectMain ...

SVG Opacity Transitions seem to ignore the constraints of CSS rules and bounce chaotically beyond their designated boundaries

I'm currently working on implementing a hover effect for an SVG rect embedded in HTML. The transition I've set up is not smooth, and the opacity values seem to be inconsistent during the animation. My browser of choice is Firefox. The rect I&apo ...

"Syncing Ajax requests with JSON in synchronous mode is not functioning properly when async is

The problem I am facing is with synchronous ajax: var result = false; $.ajax({ async: false, url: url, dataType: "json", success: function(data) { ...

Delaying UI interactivity until the document is fully loaded

I'm currently developing a web application that must be compatible with Internet Explorer 8 (yes, you read it right, compatible with the HELL). The issue I'm facing is with uploading a file which is later processed by PHP code and then refreshes ...

What is the best way to ensure that less2css compiles all files after saving just one less file?

In my project, I have a style.less file that imports "page.less". Whenever there is a change made to page.less, I find myself having to go back to the style.less file and save it in order for less2css to compile and apply the changes. If not, the changes ...

Embed Zoom Video Without Any Cropping

Attempting to integrate the iPhone Simulator from into our website. Successfully set up a form for users to input their URL, which will then be displayed on a mobile browser via the simulator. However, the size of the embedded simulator is too large for ...

The PDF format is experiencing compatibility issues when used with the CSS property for page breaks after:

My PDF with CSS page breaks is not functioning properly, as the pages are not breaking as intended. Removing position:absolute solves the issue but leaves space after each page. I suspect it may be a CSS problem, but I'm unsure. If the issue lies wit ...

Issues with font rendering on Firefox

I have embedded the Opensans font in my website. It appears correctly in Chrome, however, in Firefox it seems blurred and not displaying properly. @font-face { font-family: 'opensans'; src: url('../fonts/OpenSans-Regular.eot'); ...

Older versions of Internet Explorer, specifically IE 8 and below, are causing issues with iframe

I am currently working on a website that includes an embedded Vimeo video. The majority of our target audience uses IE8 or older, and interestingly enough, most of them have their browsers zoomed to 125% view. Unfortunately, while everything else on the si ...

Subsequent line in hta/html

I have been attempting to achieve the following output: Line 1 Line 2 Line 3 My attempts so far have included: <p>Line 1 Line 2 Line 3</p> Unfortunately, this results in: Line 1 Line 2 Line 3 I also tried the following method: <p>L ...