How can I extend this menu to be full width? What modifications are required to achieve this?

I am hoping to expand this to full width! While the code isn't too complex, I'm still fairly new to HTML and CSS.

/*Adjusting the parent <li>’s CSS position property to ‘relative’.*/

ul {
list-style: none;
padding: 0;
margin: 0;
background: #1bc2a2;
}
ul li {
display: block;
position: relative;
float: left;
background: #1bc2a2;
}

/*CSS for hiding the sub menus.*/
li ul {
display:none;
}
ul li a {
display: block;
padding: 1em;
text-decoration: none;
white-space: nowrap;
color: #fff;
}
ul li a:hover {
background: #2c3e50;
}

/*Showing the dropdown menu on hover. */
li:hover > ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
}
li:hover a {
background: #1bc2a2;
}
li:hover li a:hover {
background: #2c3e50;
}
.main.navigation li ul li {
border-top: 0;
}

/*Positioning second level dropdown menus to the right of the first level dropdown menu. */

ul ul ul {
left: 100%;
top: 0;
}
<!DOCTYPE html>
<html lang="hu-hu">
<head>
<meta charset="UTF-8>
<title>cigand.menu.nested.list</title>
<link rel="stylesheet"
  type="text/css"
        href="cigand.hu.menu.1.css" />
  
</head>
<body>
<div id="main-navigation">
<ul>
<li><a>Városunk</a>
<ul>
...
... (The rest of the HTML content)
...
</ul>
    </div>
</body>
</html>
/*So I would like to make it full width!*/
So I want to extend this to be full width! Even though it's not very complex, I'm still learning about HTML and CSS. It seems like my post is mostly comprised of code. Should I provide more details??

Answer №1

Utilize the flex CSS property for full-width alignment.

/*To make the parent <li>’s span across the whole width, apply these styles.*/
ul {
  list-style: none;
  padding: 0;
  margin: 0;
  background: #1bc2a2;
  width: 100%;
  display: inline-flex;
}

ul li {
  flex: auto;
  position: relative;
  float: left;
  background: #1bc2a2;
}


/*To hide the submenus.*/

li ul {
  display: none;
}

ul li a {
  display: block;
  padding: 1em;
  text-decoration: none;
  white-space: nowrap;
  color: #fff;
}

ul li a:hover {
  background: #2c3e50;
}


/*Display dropdown menu on hover.*/

li:hover > ul {
  display: block;
  position: absolute;
}

li:hover li {
  float: none;
}

li:hover a {
  background: #1bc2a2;
}

li:hover li a:hover {
  background: #2c3e50;
}

.main.navigation li ul li {
  border-top: 0;
}


/*Show second-level dropdown menus to the right of the first level.

*/

ul ul ul {
  left: 100%;
  top: 0;
}
<!DOCTYPE html>
<html lang="hu-hu">

<head>
  <meta charset="UTF-8>
  <title>cigand.menu.nested.list</title>
  <link rel="stylesheet" type="text/css" href="cigand.hu.menu.1.css" />

</head>

<body>
  <div id="main-navigation">
    <ul>
      <li><a>Our City</a>
        <ul>
          <li><a>Welcome</a></li>
          <li><a>Geography</a></li>
          <li><a>History</a></li>
          <li><a>Heraldry</a></li>
        </ul>
      </li>
      <li><a>Local Government</a>
        <ul>
          <li><a>Mayor's Office</a>
            <ul>
              <li><a>Mayor</a></li>
              <li><a>Deputy Mayor</a></li>
              <li><a>Secretary</a></li>
              <li><a>Secretariat</a></li>
              <li><a>Authority and Administrative Department</a></li>
              <li><a>Urban Planning and Development Department</a></li>
              <li><a>Financial Department</a></li>
              <li><a>Downloadable Documents</a></li>
              <li><a>Applications</a>
                <ul>
                  <li><a>EU</a></li>
                  <li><a>ÁROP</a></li>
                  <li><a>TIOP-1.2.3</a></li>
                  <li><a>KEOP-6.1.0/A/11.</a></li>
                  <li><a>KEOP-6.2.0/A/11-2011-0121</a></li>
                  <li><a>KEOP-6.2.0/A/11-2011-0124</a></li>
                  <li><a>KEOP-4.2.0/A/11-2011-0626</a></li>
                  <li><a>EOP-5.5.0/K/14-2014-0031</a></li>
                  <li><a>ÁROP-1.A.3-2014-2014-0116</a></li>
                  <li><a>KEOP-5.7.0/15-2015-0275</a></li>
                  <li><a>KÖFOP-1.2.1-VEKOP-16-2016-00280</a></li>
                </ul>
              </li>
            </ul>
          </li>
          <li><a>Representative Assembly</a>
            <ul>
              <li><a>Representatives</a></li>
              <li><a>Decisions, Regulations</a></li>
              <li><a>Draft Regulations</a></li>
              <li><a>Assembly Meetings</a></li>
            </ul>
          </li>
          <li><a>NRD</a></li>
          <li><a>Phone Numbers</a></li>
        </ul>
      </li>
      ... (Continues) ...
      
      <li><a>Home</a>
      </li>
    </ul>
  </div>
</body>

</html>

Answer №2

To ensure proper alignment of your floated list items, include the following CSS code for clearfix.

#main-navigation{
  width: 100%;
}
#main-navigation ul:before,
#main-navigation ul:after{
 content: '';
 display:table;
 clear: both;
}

For further reference, you can view this fiddle: https://jsfiddle.net/8przfade/

Answer №3

When styling your UL in CSS, remember to include: overflow: hidden;

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

JQuery can successfully select and unselect elements within simple HTML structures, but when it comes to PHP loops

Upon clicking 'select all', all the checkboxes are checked and disabled. When I uncheck 'select all', the checkboxes return to being unchecked and enabled. I attempted to accomplish the same task by retrieving data from a database usin ...

The Bootstrap Tooltip seems to be glued in place

Utilizing jQuery, I am dynamically generating a div that includes add and close buttons. Bootstrap tooltips are applied to these buttons for additional functionality. However, a problem arises where the tooltip for the first add button remains visible even ...

The waveform's bottom appears distorted when using Bootstrap

I'm currently experimenting with creating a header wave in Bootstrap CSS using SVG shape. However, I encountered an issue when implementing bootstrap into the HTML code - my design resembles the second image instead of the desired look of the first on ...

Tips for transmitting div id through Ajax without using a form

I'm attempting to capture the ID of the clicked element and pass it to a PHP page without using a form. Although everything seems to be working fine, I'm facing an issue where no data is being sent to the PHP page. Despite checking the code in t ...

Can we incorporate the radix-ui/colors variables into a CSS module file?

For my personal project, I am incorporating Radix components alongside radix-ui/colors. However, when attempting to import color variables into the CSS Module, I encountered an error. It seems that using the :root selector in the _app file is necessary, as ...

Creating a visually dynamic stack of images using javascript, jquery, and HTML

I'm interested in creating a unique image viewer using javascript/jQuery/HTML that combines elements of a book page flip and iTunes coverflow, optimized for mobile device browsers. I've been searching for tutorials to help kickstart this project, ...

Countdown Archive for Running Woocommerce Auction

Looking to incorporate a live countdown timer on my archive page/sliders for auction endings. Currently, I am using PHP only, but it's not live as the page needs refreshing. So, I believe JavaScript would be the best solution. The code in my function ...

How to disable an anchor tag based on a condition using ng-class?

I have a displayed table that includes a column called count which has an <a> tag with a href to a page. I want to show a link for all rows where count > 0 and disable it when count=0. I attempted to use AngularJS - ng-disabled not working for An ...

Transferring dropdown Form data using PHP

I have encountered an issue with a form that I created. The form includes various input fields, one of which is a dropdown menu. When the form is submitted, all the information from the form is sent to a designated email address. However, I have noticed ...

The CORS policy has blocked access to the XMLHttpRequest at 'http://github/..file.json' due to its origin being 'null'

Recently, I attempted to request a JSON file hosted on GitHub (for example: ). What made my situation different from this question is that I was using pure javascript without jQuery to make the AJAX call. Here's the snippet from my index.js file: fu ...

What is the best way to transfer data from app.post to app.get when navigating between multiple pages?

Within my app.js file, I am encountering a challenge as I aim to transfer the username inputted in a form on the login page over to the game page. Despite having successfully retrieved the data using req.body.username within app.post('/login'), I ...

Could LXML potentially determine the value of a class in HTML?

For instance, consider the following scenario: <button class="oW_lN oF4XW sqdOP yWX7d _8A5w5 ">MyTextIsHere</button> The "MyTextIsHere" part of the code can contain only two specific values: "Yes" and "No". Is it feasible to determine wh ...

What is the method for utilizing the data-etc attribute value of an element for CSS property values?

Is it possible to use multiple data attributes in a single CSS style? I have created the following CSS, trying to utilize both data-letters and data-color, but it is not working as expected. The data-color attribute should dictate the background color, w ...

The sidebar is misaligned, not following the left alignment set by Bootstrap

While experimenting with Bootstrap, I encountered an issue where an element in the sidebar remains at the bottom instead of aligning to the right as intended. https://i.sstatic.net/LdoS8.jpg I attempted to float it to the right, but its position didn&apo ...

What is the best method to activate a button only when the appropriate radio buttons have been chosen?

Just dipping my toes into the world of javascript. I've created a form with a set of "Yes/No" radio buttons, and I attempted to create a function that will disable the "Submit Form" button if any of the following conditions are met: If one or more r ...

Setting up an image DIV for a dynamic overlay effect

Here is a JSFiddle that works correctly with fixed height and width: http://jsfiddle.net/69td39ha/2/. The animation activates correctly when hovered over. I attempted to adapt the above example to be responsive without fixed dimensions. However, I'm ...

Solving the CSS Trick: Responsive Data Table (featuring inline editing) Display Glitch

In my quest to create a responsive table with inline editing, I turned to Chris's guide at CSS-Tricks (check it out here). To see how it all comes together, take a look at this Plunker demo. On mobile screens, the responsiveness is on point. https: ...

What steps can I take to alter this situation?

I am working on creating an API Code. Here is the code I have written: When we run the code, it displays as follows: website <?php include('simple_html_dom.php'); $url = 'https://www.g2g.com/wow-us/gold-2299-19249?&server=30805&a ...

Tips for merging two JavaScript/jQuery functions within a custom WordPress plugin

As I dive into the world of JavaScript and jQuery, I admit that I am still a beginner. Currently, I have set up a donation form on WordPress using a plugin that includes an html list. The first three options are fixed amounts (5 euro, 10 euro, 15 euro), w ...

Using jQuery to specifically extract the second value from a comma-separated list stored in a hidden input

I'm working with these input fields: <input class="things" type="hidden" value="FirstItem,SecondItem"/> <input class="things" type="hidden" value="FirstItem,SecondItem"/> Is there a way to extract only the second values from these input ...