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

Warning: Potential Infinite Loop when using Vue JS Category Filter

I developed a program that filters events based on their program and type. The program is working correctly, however, an error message stating "You may have an infinite update loop in a component render function" keeps popping up. I suspect that the issue ...

Loading all the content and scripts from one page into another

Are you looking for a seamless way to view and book our scuba diving programmes without having to navigate away from the main page? If so, we understand your desire for convenience. Instead of redirecting you to separate pages when you click on buttons li ...

What is the best way to retrieve the innerHTML content of an anchor tag with Cheerio?

Looking to extract data from an HTML page, a simplified example is provided below. Upon running the code, I anticipate the output to be [ "foo", "baz", "quux", ] but instead encounter an error message stating "TypeError: anch ...

What methods can I use to prevent floated child divs from wrapping?

I'm currently working on creating a carousel-like feature where users can select radio buttons within various div elements. The concept involves having approximately 20 divs, each 150px wide, containing radio buttons. I want to prevent these 20 divs f ...

merging the central pair of columns in the bottom row

I am having trouble combining the middle two columns in the third row of my table code. The columns remain separate and do not merge as intended. Can anyone help me identify what is causing this issue in my code? table { border: 1px solid #999; } td ...

Ways to display a different div when clicking on a div?

Good afternoon, I've noticed that this question has been asked numerous times before, but none of the solutions provided seem to work for my specific issue. My problem involves a div with the class .title3. I want another div with the class .Content ...

Struggling to achieve proper alignment for a series of div tags

I have implemented a code block to read in an image pixel by pixel and display it as a series of div tags arranged in a table-like fashion. The code is mostly inspired by a comment on PHP.net (http://www.php.net/manual/en/function.imagecolorat.php). This i ...

What are effective ways to eliminate script tags from a webpage?

I have implemented tags on my website that users can use to interact with the site. My goal is to figure out how to make the browser only read text from a specific file I write, without any HTML. This should be restricted to certain sections of my websit ...

Which specific HTML element triggers the initiation of ajax in Jquery?

I have a situation where various HTML elements trigger ajax requests when clicked. My goal is to determine which specific element was clicked inside the ajaxComplete event. Although I attempted to use event.target, it only returns the entire document inst ...

Getting the list items separated from the unordered list in Selenium

My current task involves navigating a list and selecting the correct text entry. The list contains only 2 items: <ul> <li><span>first</span></li> <li><span>second</span></li> </ul> However, ...

Error: when trying to refresh TABLE DATA, an issue occurred with a stale element reference where the element is not connected to the

Apologies in advance for my poor grasp of the English language. I am working on a project where I need to continuously fetch row data from a table using driver.refresh() The first iteration works fine, and the data is retrieved for each row. However, when ...

Enter text into a field on a different webpage and verify if the output matches the expected result

Possible Duplicate: Exploring ways to bypass the same-origin policy I'm facing a scenario where I have a form on my website that requires validation of a number. The validation process involves checking this number against another website where e ...

Text in d3.js vanishing while undergoing rotation

I have been struggling for hours with what seems like a simple problem and haven't made any progress. I'm hoping to receive some valuable advice from the brilliant minds on stackoverflow. You can view my demo at I attempted to use jsfiddle to s ...

"Exploring Bootstrap 3: How to Work with Grids and Organ

Check out my custom HTML code: <div class="container"> <div class="row"> <div class="col-sm-3"> <img src="http://placehold.it/274x175"> </div> <div class="col-sm-3"> <img src="http://placeh ...

Adding a PDF generated from an HTML div to an email using Java

I am looking for a solution to convert the contents of an HTML div tag into a PDF file while preserving its associated CSS. This is essential as I will be using Java on the back-end to send emails, and I need to attach the PDF with the CSS intact when send ...

Styling your Vuetify V-data-table with CSS

Struggling to add extra spacing between table rows, despite inspecting the page and verifying that my styles are not being overridden. Have read other Vuetify posts on applying CSS but still no luck. Any suggestions for why I can't style my table as d ...

Version 1 of Vue.js is not compatible with Ajax-loaded HTML files

Currently, I am encountering a minor issue with loading content through ajax requests. I am in the process of developing a web application where everything is located on one page without any reloading. To achieve this, I have split the content into separa ...

Using AngularJS, you can display repeated elements in a single textarea by utilizing

--> I want to be able to input data into a textarea using just one textarea element. --> The reason for this is so that when the data in MySQL is updated, I can type new data in the textarea while still keeping the existing data. I have tried using ng-re ...

PHP failing to insert data

I'm facing an issue where my PHP code is not inserting any data. I have a form that displays values, but the update code doesn't seem to be working. Can someone please help me with this problem? Here is the PHP code snippet: if (isset($_POST[&ap ...

Are You Able to Develop a Floating Window That Stays Persistent in JavaScript?

Looking to create a persistent floating window in a NextJS 14 app. This window needs to remain on top, even when navigating between browser windows. Want it to stay visible even when the browser window is minimized, like a Picture-In-Picture feature. Mos ...