Struggling with a clash of styles between the float property and the navigation style in HTML

When I apply the float:left style to my <ul>, why does the nav bar appear very large?

Consider this example:

 <ul class="nav" id="ModuleContainer" runat="server" style="float:left">
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
 </ul>

http://jsfiddle.net/65qggwch/1/

Without the float, the nav bar hides the elements that exceed the display screen (which is the desired result):

 <ul class="nav" id="ModuleContainer" runat="server" style="float:none">
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
   <li>111111----------------------</li>
 </ul>

http://jsfiddle.net/65qggwch/

The only issue is that without float:left, the elements appear on two lines instead of one as shown in the second example.

Answer №1

If you want to achieve your desired layout, consider using flex elements:

/* Establish a container to organize its children in a row */
.containerModule {
    display: flex; 
}

/* Ensure the arrow elements adjust to the content */
.sxprova,
.dxprova {
    flex: 0; 
}

/* Allow the nav container to occupy the available space */
.containerModule > div {
    flex: 1; 
}

See an example at http://jsfiddle.net/tzi/tnhwuqh1/

Keep in mind the compatibility of flexbox support: IE 10+ and multiple vendor prefixes may be required!

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

Modifying the div based on the color it is positioned in front of

I am attempting to create a sticky, transparent div that changes its color based on the background behind it. I have both dark and light colored divs, and I want the sticky div to adjust its text color accordingly (white on dark backgrounds, black on light ...

Issue with nav-pill not functioning properly on localhost server set up with XAMPP

<!-- Customized Navigation Pills --> <ul class="nav nav-pills" role="tablist"> <li class="nav-item"> <a class="nav-link active" data-toggle="pill" href="#home">My Home</a> </li> <li class="nav-item ...

Struggling with the grid layout in percentage and feeling perplexed

As I delve into the world of grid systems, I find myself grappling to comprehend it fully. The complexities can sometimes leave me feeling inadequate in my understanding. From what I gather, a 12-column grid system without any margins means that the 12th ...

"Customize the dimensions and scroll behavior of a division

I've been struggling to make a single-page site full-width, and I can't seem to get it right. My goal is to create sections that are: Full width Background image full width The height of the div should be at least the same as the image, adjust ...

Basic node.js server that responds with HTML and CSS

I have successfully created a basic http server to send an HTML file as a response. However, I'm struggling with how to also send a CSS file so that the client can view the HTML page styled with CSS in their browser. Here is my current code: var htt ...

Issue regarding the sidebar's top alignment

Having trouble with the positioning of this sidebar. It seems to be hanging slightly over the top edge instead of aligning perfectly with it. Here's how it looks: enter image description here. CSS CODE: https://pastebin.com/RUmsRkYw HTML CODE: https ...

Difficulties arise when attempting to display an input within a Bootstrap modal

Upon clicking an icon, I aim to display a bootstrap modal prompting the user to input text and a date. I have adapted code from W3Schools to create the necessary form. Unfortunately, when the button is clicked, only the labels and text area are shown, not ...

How come when you add ({}+{}) it equals to "[object Object][object Object]"?

I ran the following code: {}+{} = NaN; ({}+{}) = "[object Object][object Object]"; What is the reason behind the difference in result when adding ()? ...

Are desktop values taking precedence over the mobile media query?

Currently, I am facing an issue with aligning icons (images) under each title on a page that lists various classes. The icon needs to be centered below the title on both desktop and mobile versions of the site. However, I have encountered a problem where u ...

Using Python to interact with a website's Dropdown menu and trigger the submission

Looking to extract a value from a dropdown menu on a specific website using Python. The target website URL is: <select id="ctl00_ContentPlaceHolder1_drpWORK_PLACE" class="CDropDownList160PX" name="ctl00$ContentPlaceHolder1$drpWORK_PLACE"> ... </ ...

Create two div elements containing responsive images using HTML and CSS

Can someone assist me in creating responsive DIVs with images inside? Currently, the second div is appearing below the first one, and I'm struggling to make them scale based on mobile and tablet screen sizes. Here is the code snippet: .new_ba ...

Eliminated the right margin for desktop display

I'm looking to have a menu on the right side of my page. It looks good on mobile view with the menu aligned to the left and white space on the right. However, on desktop view, I want the menu to be aligned to the right with white space on the left. Ho ...

Is Inline Styling the Key to Effective MVC Client-Side Validation?

Having some trouble with my form's client-side validation. I'm using data annotations and models, but the default display is not visually appealing. I've tried applying CSS, but getting tooltip style errors has been a challenge. What I real ...

What is the best way to add the current date to a database?

code: <?php session_start(); if(isset($_POST['enq'])) { extract($_POST); $query = mysqli_query($link, "SELECT * FROM enquires2 WHERE email = '".$email. "'"); if(mysqli_num_rows($query) > 0) { echo '<script&g ...

Creating a volume shadow effect with CSS is a great way to add

Can anyone help me achieve a shadow effect like the one shown in this image example? I've attempted to use the after pseudo element, radius, and clip, but haven't been able to get the desired result. https://i.sstatic.net/pqUtb.png .page{ w ...

What is the method for ensuring a p element is only as wide as necessary when it wraps within a parent div with a specified hardcoded width?

Is there a way to adjust the width of the p-element in my example below based on the text inside without affecting the normal line break behavior, using only CSS if possible? It appears to be ignoring wrapping and is too wide: https://i.stack.imgur.com ...

Seeking assistance with changing the pages

Looking for assistance with troubleshooting my function. All variables are accounted for. var swith = document.getElementById("sub"); var one = document.getElementById("rule"); var two = document.getElementById("cool"); var three = document.getElementByI ...

The <form> element is giving me headaches in my JavaScript code

Trying to troubleshoot why my HTML pages render twice when I add a form with JavaScript. It seems like the page displays once with the script and again without it. Below is the basic HTML code: <form action="test.php" method="post"> <div class=" ...

Is there a way to retrieve information from an external URL in JSON format and display it using JavaScript on a separate HTML webpage?

I'm trying to display the value TotalPostNotificationCount from a JSON file in an external HTML using either JavaScript or PHP. The JSON data is as follows: { "DayPostCount": 1, "TotalPostNotificationCount": 7381 } This data can be found at t ...

Adjust the position of an image to move it closer to the top using CSS

I have a fiddle where I am trying to adjust the position of an image (keyboard) to match a specific design. https://i.sstatic.net/flqCH.png In my fiddle, the keyboard image is slightly lower than the desired position shown in the design. I am looking for ...