Effects for menu with CSS3

Asked

Viewed 931 times

1

I want when I click the #menu button it comes from left to right occupying the entire screen. Can anyone help me do this with css3? At the moment I make the menu go down with javascript slidetoggle, but I want to do with css3

<button class="menu"></button>


        <div id="menu">                     
            <ul>
                <li>Link1</li>
                <li>Link2</li>
                <li>Link3</li>
                <li>Link4</li>
                <li>Link5</li>
            </ul>
        </div>
  • Is that how you want it? -> http://jsfiddle.net/h1twygcx/

  • If you could want with CSS3?

  • @Tiagop. C I suggested an edit removing the Javascript tag, since you’re saying you don’t want Javascript solutions.

  • @Tiagop. C my code is with CSS3 :)

1 answer

2

You can use the technique of having a label attached to a field checkbox to control when the menu will be opened/closed, in that other answer I gave an example and explained a little better.

In your case, just leave the menu in absolute position and keep it "hidden" by setting its position on the left with a negative value, which will make it exit the field of view of what the user is seeing. And when the checkbox is selected, just reset the distance from the menu on the left.

Left p/ right

*{ margin:0; box-sizing: border-box }

nav {
  border: 1px solid #333;
  display: flex;
  flex-flow: column wrap;
  left: -110%; /* para escondê-lo */
  position: absolute;
  transition: left 400ms ease-in;
  width: 100%
}

#menu { display: none }

#menu:checked + nav {
  left: 0 /* para exibi-lo */
}
<label for='menu'>Menu</label>

<input id='menu' type='checkbox'/>

<nav>
  <a href='#!'>Link 1</a>
  <a href='#!'>Link 2</a>
  <a href='#!'>Link 3</a>
  <a href='#!'>Link 4</a>
<nav>

Right p/ left

*{ margin:0; box-sizing: border-box; overflow: hidden }

nav {
  border: 1px solid #333;
  display: flex;
  flex-flow: column wrap;
  right: -100%; /* para escondê-lo */
  position: absolute;
  transition: right 400ms ease-in;
  width: 100%
}

#menu { display: none }

#menu:checked + nav {
  right: 0 /* para exibi-lo */
}
<label for='menu'>Menu</label>

<input id='menu' type='checkbox'/>

<nav>
  <a href='#!'>Link 1</a>
  <a href='#!'>Link 2</a>
  <a href='#!'>Link 3</a>
  <a href='#!'>Link 4</a>
<nav>

  • If I want it to go right to left? : D

  • @Tiagop. C It was already left to right, did you mean "right to left"? I put an example but as the menu was inserted directly in body, used a overflow:hidden not to show horizontal scrollbar.

  • I have a button with a "hamburger" and a button with an "X" How do I make it work right? I mean, when you click on the menu, does X appear and when you click on X, does the hamburger appear again? I already have this with javascript but I wanted to do it with css :D After that I’ll accept your answer, because you’ve helped me a lot

  • @Tiagop. C I don’t know, the code you posted and the description of the question doesn’t say anything about that. Create a new question and explain in detail what you are trying to do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.