What is the best way to make sure my navigation menu adapts to changes in my div size

Just curious, how can I make my navigation menu adjust its width to match the div box? Any help would be appreciated!

If you'd like to see an example, here's a jsfiddle link: http://jsfiddle.net/AtM2Q/

Below is the code snippet:

<html>
<head>
<style>

ul#navmenu, ul.sub1, ul.sub2 {
list-style-type: none;
font-size: 9pt;
}
ul#navmenu li {
min-width: 203px;
max-width: 285px;
width: 100%;
text-align: center;
position: relative;
margin-right: 0px;
display:inline-block;
}
   #navmenu ul {
display: inline-block;
list-style-type: none;
white-space:nowrap;
}
#page1 {
text-align: center;
}
ul#navmenu a {
text-decoration: none;
display: block;
width: 100%;
min-width: 203px;
max-width: 285px;
height: 30px;
line-height: 25px;
background-color: #2E2E2E;
border: 1px solid #777777;
border-top: 2px solid #777777;
color: white;
font-family: Arial, sans-serif;
font-weight: bold;
font-face: Arial;
float: left;
text-align: center;
white-space: nowrap;

}
ul#navmenu .sub1 a {
margin-top: 0px;
}
ul#navmenu .sub2 a {
margin-left: 0px;
}
ul#navmenu li:hover > a {
background-color: grey;
}
ul#navmenu li:hover a:hover {
background-color: red;
}
ul#navmenu ul.sub1 {
display: none;
position: absolute;
top: 30px;
left: 0px;
}
ul#navmenu ul.sub2 {
display: none;
position: absolute;
top: 0px;
left: 126px;
}
ul#navmenu li:hover .sub1 {
display: block;
}
ul#navmenu .sub1 li:hover .sub2 {
display: block;
}
.darrow {
font-size: 8pt;
position: absolute;
top: 8px;
right: 1px;
    }
    #navmenu {
display: inline-block;
text-align: center;
list-style-type: none;
margin: 0px auto;
padding: 0px;
position: relative;
white-space: nowrap;

    }
    .rarrow {
font-size: 8pt;
position: absolute;
top: 6px;
right: 0px;
    }
    ul#navmenu {
width:100% !important;
    }
    #page1 .link1 {
color: grey;
border-top: 2px solid red;
    }
    #page2 .link2 {
color: grey;
border-top: 2px solid red;
    }
    #page3 .link3 {
color: grey;
border-top: 2px solid red;
    }
    .container {
width: 100%;
min-width: 1024px;
max-width: 1440px;
height: 1000px;
margin: 0px auto;


}
#box2 {
height: 1000px;
 width: 100%;
min-width: 1024px;
max-width: 1440px;
height: 1000px;
background-color: yellow;
float: left;
margin: 0px auto;
}
#boxinbox1 {
width: 100%;
height: 200px;
background-color: #E51837;
}
</style>
</head>
<body bgcolor="#E51837">

    <div id="box2">
        <div id="page1">
            <div id="boxinbox1">weiuhgqiogq</div>
            <ul id="navmenu">
                <li><a href="dropdown1.html" class="link1">Home</a>
                </li>
                <li><a href="dropdown2.html" class="link2">hyperlink 2</a><font color="white">
<span class="darrow">&#9660;</font>
                    </span>
                    <ul class="sub1">
                        <li><a href="#">hyperlink 2.1</a>
                        </li>
                        <li><a href="#">hyperlink 2.2</a>
                        </li>
                        <li><a href="#">hyperlink 2.3</a>
                        </li>
                    </ul>
                </li>
                <li><a href="#">hyperlink 3</a>
                </li>
                <li><a href="#">hyperlink 4</a><span class="darrow"><font color="white">&#9660;               

 </font></span> 
                    <ul class="sub1">
                        <li><a href="#">hyperlink 4.1</a>
                        </li>
                        <li><a href="#">hyperlink 4.2</a>
                        </li>
                        <li><a href="#">hyperlink 4.3</a><span class="rarrow">
<font color="white">&#9654;</font></span>

                            <ul class="sub2">
                                <li><a href="#">hyperlink 4.3.1</a>
                                </li>
                                <li><a href="#">hyperlink 4.3.2</a>
                                </li>
                                <li>
<a href="dropdown3.html" class="link3">hyperlink 4.3.3</a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li><a href="#">hyperlink 5</a>
                </li>
            </ul>
        </div>
    </div>
    </div>
</body>

</html>

__________________________________________________________________________oamgogeponrbapoenbepoanbaepobneaporibnmaeorpbinmepobaeponbaepornbwponbwrpoBNWpornbwropUNBWORPBWPOrbwoprBWOI[rbjw[J[owigjw[oiGJWr[ogj[worgijw[rPGJ

Answer №1

It seems like what you're saying is that you need to set the width of ul#navmenu li in percentages.

With 5 main navigation points currently in place, consider using the following CSS:

ul#navmenu li {
    width: 19%;
    text-align: center;
    position: relative;
    margin-right: 0px;
    display:inline-block;
}

However, my suggestion would be to utilize Twitter-Bootstrap for better results...

Answer №2

Here is the solution

    ul#navmenu a {
text-decoration: none;
display: block;
width: 50%;   
max-width: 285px;
height: 30px;
line-height: 25px;
background-color: #2E2E2E;
border: 1px solid #777777;
border-top: 2px solid #777777;
color: white;
font-family: Arial, sans-serif;
font-weight: bold;
font-face: Arial;
float: left;
text-align: center;
white-space: nowrap;

}

It is advisable to remove min-width as it is unnecessary and set the width size to 50% instead of 100%, as it was covering the entire div. Additionally,

     ul#navmenu li {
border:1px solid white;
max-width: 285px;
width: 50%;
text-align: center;
position: relative;
margin-right: 0px;
display:inline-block;
 }

This CSS code is used to specify the width and border for "li". Apply this code and you will see the desired outcome. I tested it on your fiddle and it worked perfectly.

Feel free to reach out if you need further assistance.

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

Error: The request to /api/auth/login in Postman failed unexpectedly

As I am working on developing an app using node.js and express, I encountered an error while making post requests in Postman. Cannot POST /api/auth/login%0A Below are the details of my app's structure along with the files involved: app.js const ex ...

If other options fail, Else If may not be a suitable choice

This is the process: switching from Issue: x==0||1 to x==0||x==1 etc. This code runs from an .html file <body> <div class="" id="pimg1"> </body><script> var x=new Date().getMonth(); if (x == 0||x == 5||x == 2){docu ...

Getting the location of a mouse click and adding tags (marks) on an image: a simple guide

Is there a way to incorporate images with tagged marks similar to Facebook's image tagging feature? How can I retrieve the X and Y coordinates of tags on the image itself (not the screen) and display them in a responsive manner? ...

Prevent users from selecting an option depending on a specific criteria

I need help with disabling select options based on specific time instances. For example, I want the user to provide specifications by 6:00 am in order to use the system at 10:00 am, ensuring there is a 4-hour gap between the two times. So, after 6:00 am, t ...

Issues with image sizing on mobile devices

After finalizing my header design, I encountered an issue with the mobile version of the website. The images in the header are not responsive and do not adapt well to different screen sizes. I need assistance converting the header design into functional co ...

Ways to incorporate services into functions within Angularjs

I'm struggling to grasp the concept of dependency injection in AngularJS. Currently, I am attempting to inject $interpolate and $eval into my controller. However, after consulting the documentation, I realized that my lack of foundational knowledge i ...

Looking to adjust the background-image size of a table cell (td) upon clicking a specific

I have a website where I would like to display logos of different games with links attached to them. I have managed to adjust the size of the image on hover, but now I am looking for a way to keep the size bigger after clicking on the link. Is there a simp ...

Trouble with Bootstrap accordion staying open even after a different one is chosen

Looking for assistance! I am encountering an issue with using jQuery on Bootstrap. The accordion feature is not functioning correctly as it fails to collapse when another section is selected. https://i.stack.imgur.com/uiZPh.png The problem arises when th ...

Give a radio button some class

<input id="radio1" type="radio" name="rgroup" value="1" > <label for="radio1"><span><span></span></span>1</label> <input id="radio2" type="radio" name="rgroup" value="2" > <label for="radio2"><span ...

Strategies for Updating Backgrounds on Individual WordPress Pages

I am looking to revamp a WordPress blog with 5 different pages, each requiring a unique background image. Is there a method to achieve this without altering the background element, but instead changing the background image of the #main element in my CSS? ...

How to center align text in the media-body using Bootstrap 4 Beta

Struggling to vertically align the text in media-body to the middle when using the new Bootstrap 4 beta version. Tried an approach mentioned in this solution, but it didn't work with the latest version of Bootstrap. Attempted using text-center and a ...

Data not getting transmitted to Rails controller via AJAX request

My development setup includes Rails 5.2.4, coffee-rails 4.2, jquery-rails 4.4.0, and jquery-ui-rails 6.0.1. I've successfully implemented functionality that allows users to drag around and resize divs on a web page. However, I now need to save the ne ...

Tips for displaying a refresh indicator while making an ajax call for refreshing data:

I have successfully implemented jQuery code that refreshes a specific div every 10 seconds without reloading the entire page. However, during this refresh process, the user does not visually perceive any changes happening in the browser. While there are n ...

Header logo not showing up on webpage

While working on a website template for a friend, I encountered an issue when uploading the site. The logo image was displaying perfectly fine on my local drive, but once uploaded, it showed as a broken image icon on the live website. Here is the code sni ...

What could be causing only certain portions of my CSS to be applied?

I've been struggling to get rid of the gray border around the SIGN UP button in the tbody section. I've tried applying classes (along with the ID) and using pseudo classes like :4th-child {border:none}, but nothing seems to work. The only solutio ...

What is the best way to extract the first heading tags from a post and showcase the outcome?

Can someone help me with changing the_title() function to a heading tag that I manually input in posts? I have created a post loop list using table code but I am stuck at this point... Desired Title Format: <h3 style="text-align: center;">Title Here ...

The keyframe spinner fails to function properly on Firefox and results in blurry text

I am facing an issue with a keyframe spinner that rotates an image on the y-axis. It works perfectly in Chrome but fails to function in Firefox. I have tried changing the HTML tags to div or span class/id, but nothing seems to work. Interestingly, other ke ...

Notify the user with a Jqgrid alert when they attempt to select multiple checkboxes

When editing rows, I wanted to avoid multiple selections. In order to achieve this, I need to check the condition if(count>1) and display an alert message. I am struggling to figure out how to retrieve the count of selected checkboxes in jqGrid. var m ...

Unable to generate a navigation panel using HTML/CSS and jQuery

I recently completed the basic courses in HTML/CSS, JavaScript, jQuery, and PHP on Codecademy. I'm currently working on creating a website using HTML/CSS and jQuery in Codecademy's codebits. However, I'm facing some issues with my navigation ...

Increase the size of the textarea when it is clicked on and revert back to its original size when it

My question revolves around a text area that I am trying to manipulate through jQuery. The desired functionality is to increase the height of the text area whenever someone clicks on it, and decrease the height when clicking anywhere else on the screen. & ...