Is it possible that setting overflow:hidden can transform it into a block-level element?

Hey there! Iā€™m attempting to create a horizontal navigation bar.

I've set the ul with overflow:hidden and each li with float:left. Below the horizontal nav bar, I have added some paragraphs.

However, when I remove "overflow:hidden", the paragraph shifts right next to my horizontal nav bar. I'm confused as to why this happens. Could someone kindly provide an explanation?

Answer ā„–1

Absolutely not. Avoid using overflow: hidden; in a navbar.

overflow: hidden has the potential to conceal important elements that should remain visible. It's best to steer clear of it unless absolutely necessary, which is not the case here.

Instead, apply clear: left; on the paragraph.

li {
float:left;
padding:10px
}
ul {
float:left;
list-style:none;
background:grey;
width:auto;
}
p { 
clear:left;
float:left;
width:100px
}
<ul>
  <li>LIST</li>
  <li>LIST</li>
  <li>LIST</li>
  <li>LIST</li>
</ul>
<p>
  SOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXT SOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXT SOMETEXTSOMETEXTSOMETEXTSOMETEXT
</p>

Alternatively, you can use float: left; width: 100%; on the <ul> (navigation list).

li {
float: left;
padding: 10px
}

ul {
float: left;
list-style: none;
background: grey;
width: 100%;
}

p {
float: left;
width: 100px
}
<ul>
  <li>LIST</li>
  <li>LIST</li>
  <li>LIST</li>
  <li>LIST</li>
</ul>
<p>
  SOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXT SOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXTSOMETEXT SOMETEXTSOMETEXTSOMETEXTSOMETEXT
</p>

Answer ā„–2

overflow: hidden; is employed to eliminate the need for clearing floats in the li elements. If not used, the paragraph would be positioned directly next to the list due to the left float of the li's.

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

Page rendering issue: Access to page unavailable

I've been attempting to include a link to my privacy policy in the footer using the following code: <a href="/privacypolicy"> Privacy Policy </a> However, when I view the homepage on my local host and try to access the privacy p ...

What are the reasons for not utilizing JSS to load Roboto font in material-ui library?

Why does Material-UI rely on the "typeface-roboto" CSS module to load the Roboto font, even though they typically use JSS for styling components? Does this mix of JSS and CSS contradict their usual approach? ...

Ways to position a div at the center of a page

I've encountered a challenge while creating a mobile website. Within the main div, there are three nested divs. Initially, I aimed for left alignment but now desire to center-align these three divs on the page. Essentially, if the device screen is wid ...

What is preventing the container from occupying the full height?

Currently, I am working on creating a survey form page. I have successfully created a div with the id "container" which holds all the elements on my site. For the code snippet and reference, you can check out this link CODE * { margin: 0; padding ...

Tips for arranging Bootstrap cards in ReactJS so they wrap to a new line after three have been displayed

In my personal portfolio, there is a dedicated page for showcasing various projects using Bootstrap cards. These projects are fetched from a CardData.js file and then mapped to a ProjectCard component. Ideally, I want to display 3 cards per row with consis ...

problem with the picture and wrapper expanding to fill the entire width of the screen

I'm having an issue with the image I added and its hover effect. The image seems to be leaving space on both sides of the screen, even though I've included background-size: cover and width:100% in my code. Could someone please point out where I ...

What is the best way to adjust a component to display varying content based on the scenario?

I am looking for a way to reuse a component on my website that displays messages. The challenge is that in one section, the content consists of only a title and paragraph, while in another section, there are multiple titles and content pieces. I have imple ...

Having trouble designing a button in my ASP.net Class

After creating a new instance, I would like to add an asp button. However, I am facing challenges with assigning a name and id to the button. For example: <asp:Button ID="Button1" runat="server" Text="Button" />. Every time I try to add quotation mar ...

Changing the position of a sprite using jQuery

Looking for assistance in moving the scroll location onClick of another div using jQuery. The image is a sprite. .top-background{ background: url("../images/mainall.jpg") no-repeat scroll 0px 0px transparent; height: 888px; width:1024px; } ...

Unable to set DIV width to 100% and show a scrollbar

I am facing an issue with the width of a DIV element on my webpage. Despite setting it to 100% width, it only takes up the visible window's width and not the full page width, especially when a horizontal scroll bar is displayed. Below is the HTML cod ...

Instructions on how to prompt users to register using a distinctive code

Currently in the process of constructing a website and I'm interested in setting restrictions on the number of users who can sign up for it. https://i.stack.imgur.com/JD2Ct.png In the image provided, there is a database in phpMyAdmin labeled as &apo ...

retrieving data in tabular form from a website

Looking to extract a table from this website by clicking on the "National Data" option. While I could easily download it, my interest lies in learning web scraping techniques. Previously, I utilized Python's Selenium package to automate the process of ...

hierarchical browsing system

Take a look at the image provided below. Currently, I am using multiple unordered lists - specifically 5. However, I would prefer to consolidate them all into a single nested ul. I am encountering two issues: How can I add a border-bottom to the hori ...

Alter the appearance of another div when focused on

Is there a way to change the fill color of the SVG when a user focuses on the input field? I have included the HTML and SCSS for reference, but I'm not sure how to write the CSS code to achieve this effect. <div class="search"> <svg widt ...

Prevent the appearance of a scrollbar on a fixed-position popup element

Whenever I click on a button, a Sidebar opens up and fills the entire screen due to its position being set to fixed. Here's how it looks with TailwindCSS: return ( <div className="fixed z-40 flex left-0 top-0 h-screen w-screen"> ...

Create a layout that includes options with checkboxes and divs styled inline

I'm in the process of setting up a voting poll on a website. The poll needs to be presented as a radio button followed by a <div> that contains all relevant poll details. In this <div>, I want the option text to appear on the left and the ...

Increasing the size of text in CSS with the use of ":hover" and then causing it to return to its original smaller size

Allow me to explain my goal here. I have text displayed on my website that I would like to enlarge when the user hovers over it and then shrink back down when they move their cursor away. The issue I'm facing is that after enlarging the text using t ...

Using Javascript to change CSS in a Polymer application

Coming from a background in angular and react, I am now delving into the world of polymer. I have a polymer class called myClass with the following template. <div id="[[x]]"> Here, 'x' is a property defined in a property getter. stat ...

Internet Explorer 11 is not interested in giving attention to a disabled element

I'm trying to limit text input to only one of two fields. My approach involves checking the value of a field when it loses focus, and then disabling the other field if the initial one is not empty. Below is an example: HTML: <div class="contain ...

What are the steps for printing a webpage in landscape orientation using Firefox and IE11?

@page { size: 11in 8.5in; } This code snippet did not achieve the desired result in Internet Explorer or Firefox. The transform: rotate(270deg); property only worked for the first page. ...