Modify the hover dimensions within the CSS of a Bootstrap framework

I am trying to customize the hover effect size on my navigation bar in Bootstrap 4. I want to reduce the background size of the menu links when hovered over. I attempted a method from this source: How do i change the width of the hover in bs4 , but it did not work for me.

Below is my HTML code:

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>Cuppela</title>
    <script src="https://www.cuppela.com/cuppela/js/jquery.min.js" type="text/javascript"></script>
    <script src="https://www.cuppela.com/cuppela/js/bootstrap.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="https://www.cuppela.com/cuppela/css/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="css/test.css" type="text/css">

</head>
<body>
    <div id="nav-menu">
        <nav id="main-nav" class="navbar navbar-expand-md fixed-top">
            <div class="container">
                <ul class="nav navbar-nav mx-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="#">Home</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Shop</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">About</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Contact</a>
                    </li>
                </ul>
            </div>
        </nav>
        </div>
<div class="container-fluid" id="top-main"> 

    <div id="top_text">
        <h1>Cuppela Made With Sugar</h1>
        <p>Delicious Homemade Cakes</p>
    </div>
    
    </div>
</div>

<div>
    <h2>Test</h2>
</div>
</body>
</html>

Here is my CSS style code:

body{
    margin: 0px;
}

li a:hover {
    background-color: #ff9900;
    border-radius: 10px;
}

li a{
    color: white !important;
}

#top-main{
    background-image: url(../images/cake_six_two.jpg);
    height: 100vh;
}

#nav-menu{
    font-size: x-large;
    position: relative;
}

#top_text{
    color: white;
    text-align: center;
    position: relative;
    top: 50%;
    left: 50%;
    /* bring your own prefixes */
    transform: translate(-50%, -50%);
}

h1{
    font-size: 500%;
}

p{
    font-size: x-large;
}

h2{
    text-align: center;
}

Edit: Additional clarification has been included.

Answer №1

If you are looking to adjust the background size of menu links when hovering over them, you can make changes to the padding of the .nav-link class. Adjusting the padding or removing it entirely will affect the appearance. Here is an example:

https://i.sstatic.net/MAjrU.png

Removing all padding may create a slightly different visual effect with more orange background appearing above the links than below. This is a common behavior in CSS due to padding. To address this, consider adding the following code: padding: 0 0 .2rem. This setting means there will be no padding on the top, right, and left sides, while there will be 0.2rem of padding at the bottom of the element.

The final result will look something like this: https://i.sstatic.net/LB6y8.png

Answer №2

Your request is a bit unclear, but if you're looking to adjust the font size, just use the CSS rule font-size: 12px, or whatever value suits your needs. For changing the width of anchor tags, consider reducing the padding within the following selector:

.navbar .navbar-nav .nav-item .nav-link { padding: 5px // or adjust as needed, even setting it to 0 }

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

Guide for displaying SQL data in an HTML table

I am currently working on transferring my SQL data to an HTML format. The code I have so far is not functioning as expected. I attempted to include HTML within my PHP code, and now I am considering if it would be better to do it the other way around (emb ...

Having trouble with Tailwind custom background image not displaying correctly when the website is live

When working on my CRA project, I encountered an issue with background images not appearing in the production environment. Despite adding custom background images by modifying the theme.backgroundImage section of my tailwind.config.js file, the images only ...

Creating a HTML element that functions as a text input using a div

I am encountering an issue with using a div as text input where the cursor flashes at the beginning of the string on a second attempt to edit the field. However, during the initial attempt, it does allow me to type from left to right. Another problem I am ...

unable to toggle collapse functionality of bootstrap 3 navbar

My navbar was recently modified, but now the toggle button is not responding when clicked. Here is the code I am using. Can someone help me find the mistake? CODE: <body> <div class="navbar-wrapper"> <div class="container"> ...

The new additional formatting features I added to Bootstrap are causing issues with my layout

Originally, my code featured an image positioned on the right-hand side before I separated each H1 element into separate sections. Click here to see a picture of the page before the edit After separating the elements into divs, the image now sits on the t ...

What is the best way to align elements within a row/column layout in Angular Material when working with divs?

To set up two div blocks in a row, I'm utilizing the code below: <div layout="column" layout-gt-xs="row" layout-align="center center" id="row"> <div id="a">a</div> <div id="b">b</div> </div> The CSS for this ...

Use jQuery to switch the class of the designated DIV in the showcasing slider

Check out this jQuery slider example where I have two Divs - DIV ONE and DIV TWO. Can you help me figure out how to: 1) Automatically change the class of DIV ONE from "test" to "testc" when Slide 1 is displayed by the slider. 2) Automatically update DIV ...

What is the best way to reset everything back to its original position by clicking anywhere on the screen except for the specified div?

Is there a way to make the entire screen reset to its original state with just one click anywhere on the screen, rather than having to click a specific button? Any assistance on this matter would be greatly appreciated. Thank you! JQUERY CODE $(".readNow ...

When resetting the function, make sure to move the class to the closest sibling element

I am currently utilizing a slider that employs the .prev and .next jQuery functions to toggle the active class, indicating which slide is being displayed. Here is the code responsible for this functionality. It identifies the current sibling with the acti ...

What is the best way to ensure that the scroll inside a container automatically starts at a specific link?

https://codepen.io/jimjamjom/pen/oBoEgz If you check out the codepen link above, you'll see that when a visitor lands on the page, the container defaults to "Section 3," requiring them to scroll up or down to view the other sections. Despite attempt ...

Navigation that remains fixed while scrolling

Can someone help me fix the side navigation of this template to stay fixed when a user scrolls past it for easier navigation? I'm struggling with the code and could use some fresh eyes to look at it. I just can't seem to figure it out on my own, ...

Ways to ensure the footer sticks to the bottom of the page when there is minimal content

Using Bootstrap 3.3.7 I am trying to ensure that my footer always stays at the bottom of the browser window. I prefer not to use a "sticky footer" as I don't want it to cover any part of my content. Currently, when there is enough content on the pa ...

Tips for linking two php form files with identical ids and combining their information in a database:

My system consists of two transactions, namely Registration.php and req.php. The data from both transactions is stored in the "new" table within my database. Registration.php is the initial transaction followed by req.php. These PHP files are forms, each w ...

Ensure this div adapts to different screen sizes

I have attempted using a width of 100%, but unfortunately, it did not result in a responsive design. To illustrate my point, here is the link to what I am striving to achieve in terms of responsiveness: codepen link div { background:url(https://i.stac ...

Struggling to display a function's output on a separate web page within a flask application

After spending close to 10 hours on this, I find myself stuck. My restaurant search app is functioning perfectly when I print the output to the terminal. However, I can't seem to figure out how to display it on a new page. Here's a snippet of my ...

Tips for maintaining an open sub menu while hovering over a link

I'm currently working on a navigation menu using jQuery that includes categories, subcategories, and their subsequent subcategories. However, I am facing some issues with it not functioning as intended. To avoid cluttering this space with excessive HT ...

The elements displayed within an HTML canvas need to adapt to different screen sizes

I am facing an issue with my HTML canvas. Inside each canvas, there are tally boxes that represent the number of votes for different candidates. The problem arises when the number of votes exceeds 100, as some of the tally boxes disappear from the canvas. ...

Having trouble with webpack displaying CSS background images?

I've set up the html boilerplate using webpack. I'm currently encountering an issue where calling an image in my scss file like "background: url('/img/img.png');" isn't working. I've included the webpack file and folder struct ...

Why are the height and width values I specified not matching the values returned?

I am currently learning HTML and JavaScript, specifically diving into the width() and height() methods in JavaScript. Setting the dimensions of div1 to 100px for height and 300px for width, I encountered a discrepancy when running the code. Upon execution ...

What is the best way to display array type schema objects in a single row in react-jsonschema-form?

Looking for help with react-jsonschema-form to customize the display of array components? Here is the code snippet: const schema = { type: "object", properties: { Name: { type: "string", title: "Name", default: "A new Task" }, Title: { typ ...