0

During creating horizontal menu in CSS why there is used overflow: hidden to make this menu visible?

type here

I Would like to know why should we use overflow:hidden same as in example below:

www.w3schools.com/css/tryit.asp?filename=trycss_float5

1
  • Please provide enough code so others can better understand or reproduce the problem. Commented Nov 24, 2023 at 18:48

1 Answer 1

1

The <li> elements inside the <ul> have the style

float: left;

When an element is given any float styles, they are no longer in the document's normal flow. When you set overflow as hidden, you are creating a block formatting context. This contains all the floated elements, preventing the container from collapsing.

If you remove the overflow:hidden style, you'll see that the other <li> elements are gone until you hover over them. By using overflow:hidden, you make sure that the parent container expands to contain its floated children. Removing the style means that the parent container (<ul>) does not contain the floated children anymore, due to which they become invisible. Hovering over them just triggers the :hover styles.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.