Let's create PullDown Menu by HTML + CSS

# PullDown Menu by HTML + CSS

This is [demo](https://wizardly-hamilton-398288.netlify.com/)

This is all [Source Code](https://github.com/obscure723/PullDownMenuByCSS)

### 1. Prepare folder and files
First, please prepare project for pulldown practice.

```
├ assets /
│       ├ css /
│          ├ reset.css
│          ├ style.css
│
├ index.html
```

<img width="252" alt="スクリーンショット 2019-08-12 13.10.05.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/475289/4c65b361-2a50-36e4-8c7e-969245c864e2.png">

### 2. Prepare add HTML and reset css code.

<details><summary>index.html</summary><div>


```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="./assets/css/reset.css">
  <link rel="stylesheet" href="./assets/css/style.css">
</head>
<body>
  <header>
    <nav>
      <ul class="menu">
        <li><a href="#">Nav1</a></li>

        <li><a href="#">Nav2</a>
          <ul>
            <li><a href="#">Nav2-1</a></li>
            <li><a href="#">Nav2-2</a></li>
          </ul>
        </li>

        <li><a href="#">Nav3</a>
          <ul>
            <li><a href="#">Nav3-1</a></li>
            <li><a href="#">Nav3-2</a></li>
            <li><a href="#">Nav3-3</a></li>
          </ul>
        </li>
        <li><a href="#">Nav4</a></li>
      </ul>
    </nav>
  </header>
</body>
</html>
```

</div></details>

<details><summary>reset.css</summary><div>


```css
/*
html5doctor.com Reset Stylesheet
v1.6.1
Last Updated: 2010-09-17
Author: Richard Clark - http://richclarkdesign.com
Twitter: @rich_clark
*/

html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code,
del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var,
b, i,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure,
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
margin:0;
padding:0;
border:0;
outline:0;
font-size:100%;
vertical-align:baseline;
background:transparent;
}

body {
line-height:1;
}

article,aside,details,figcaption,figure,
footer,header,hgroup,menu,nav,section {
display:block;
}

nav,ul {
list-style:none;
}

blockquote, q {
quotes:none;
}

blockquote:before, blockquote:after,
q:before, q:after {
content:'';
content:none;
}

a {
margin:0;
padding:0;
font-size:100%;
vertical-align:baseline;
background:transparent;
}

/ change colours to suit your needs /
ins {
background-color:#ff9;
color:#000;
text-decoration:none;
}

/ change colours to suit your needs /
mark {
background-color:#ff9;
color:#000;
font-style:italic;
font-weight:bold;
}

del {
text-decoration: line-through;
}

abbr[title], dfn[title] {
border-bottom:1px dotted;
cursor:help;
}

table {
border-collapse:collapse;
border-spacing:0;
}

/* change border colour to suit your needs
*/
hr {
display:block;
height:1px;
border:0;
border-top:1px solid #cccccc;
margin:1em 0;
padding:0;
}

input, select {
vertical-align:middle;
}

```

</div></details>

If you put these code, the site looks like this.

<img width="231" alt="スクリーンショット 2019-08-12 13.16.59.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/475289/b2c469c2-e6a3-6ddf-14ee-4fd32e1d10ae.png">


### 3. Let's add CSS code.

```css:&nbsp;style.css
.menu {
  width: 750px;
  margin: 0 auto;
  padding: 0;
  display: flex;
}
```

<img width="586" alt="スクリーンショット 2019-08-12 13.31.04.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/475289/adebea54-b792-f69a-bd10-3dc8c8c95bf1.png">

### 4. Make li design.

```css:&nbsp;style.css
.menu {
  width: 750px;
  margin: 0 auto;
  padding: 0;
  display: flex;
}

/* add design */
.menu li {
  width: 150px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: aqua;
  border: 1px solid #eee;
  box-sizing: border-box;
  cursor: pointer;
  position: relative;
}
```

<img width="647" alt="スクリーンショット 2019-08-12 13.36.24.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/475289/3578a89f-2fa5-b97a-20c6-e927e051b6c3.png">

### 5. Change anchor tag design.

```css:&nbsp;style.css
.menu {
  width: 750px;
  margin: 0 auto;
  padding: 0;
  display: flex;
}

/* add design */

.menu li {
  width: 150px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: aqua;
  border: 1px solid #eee;
  box-sizing: border-box;
  cursor: pointer;
  position: relative;
}

/* change anchor tag design */
.menu li a {
  display: block;
  width: 100%;
  text-decoration: none;
  color: #222;
}

```

<img width="647" alt="スクリーンショット 2019-08-12 13.40.45.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/475289/6cb8b440-0722-27c5-b8b6-a71b1b304edc.png">

### 6. Hide children navs.

```css:&nbsp;style.css
.menu {
  width: 750px;
  margin: 0 auto;
  padding: 0;
  display: flex;
}

/* add design */

.menu li {
  width: 150px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: aqua;
  border: 1px solid #eee;
  box-sizing: border-box;
  cursor: pointer;
  position: relative;
}

/* change anchor tag design */
.menu li a {
  display: block;
  width: 100%;
  text-decoration: none;
  color: #222;
}

.menu li ul li {
  overflow: hidden;
  height: 0;
  border: 1px solid white;
}
```

<img width="647" alt="スクリーンショット 2019-08-12 13.45.18.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/475289/ec5d70eb-162c-5dd4-acbf-e0259ec021ab.png">

### 7. When focus on li, display children navs.

```css:&nbsp;style.css
.menu {
  width: 750px;
  margin: 0 auto;
  padding: 0;
  display: flex;
}

/* add design */

.menu li {
  width: 150px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: aqua;
  border: 1px solid #eee;
  box-sizing: border-box;
  cursor: pointer;
  position: relative;
}

/* change anchor tag design */
.menu li a {
  display: block;
  width: 100%;
  text-decoration: none;
  color: #222;
}

.menu li ul li {
  overflow: hidden;
  height: 0;
  border: 1px solid white;
}

/* display children navs */
.menu li:hover > ul > li {
  overflow: visible;
  height: 40px;
}
```

![aaa.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/475289/56cf55b1-3b60-866c-1641-80e17d55e3bb.gif)

### 7. Add transition.

```css:&nbsp;style.css
.menu li {
  width: 150px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: aqua;
  border: 1px solid #eee;
  box-sizing: border-box;
  cursor: pointer;
  position: relative;

  /* add transition */
  transition: 0.2s;
}

```

![aaa.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/475289/fac3206d-5add-bf3a-1adf-f3924da3eeb9.gif)