How I Created a Pokedex with CSS
Tags: css, html, pokemon, pokedex
Published: 2020-10-25 10:09:23

#### A small CSS & HTML Drawing poject

1. [Planing](#planning)
2. [Start Coding](#start-coding) 
3. [Adding curved lines](#adding-curved-lines) 
4. [Adding some Javascript](#adding-some-javascript) 

###[See it on Codepen](https://codepen.io/oryamne/pen/vYKXbgZ?editors=1100)

### Planning

Found a sample image to mock on google.

![Alt text of image](https://kamaleshjicse.files.wordpress.com/2018/11/pokedex-kamalesh.gif)

Then arranged the basic layout.(using draw.io)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/p13we0hdc2yv29ilfdsq.jpg)
I used a grid for the main structure and most of the sections in the grid as a flex-box.
I also colored parts I thought would share the same properties so I could try to reuse some classes.

### Start Coding

I started to write the left panel, everything got pretty good as planned, up to the navigation button.
I couldn't remove the border of the top rectangle in the middle.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/u67od56y2fxsrp7v9yi7.png)

So, I google it.
I found a way to make it work by adding borders with the same color as the button background and position them so they cover the original border.

HTML

```html
<div class="nav-button">
    <div class="nav-center-circle"></div>
    <div class="nav-button-vertical"></div>
    <div class="nav-button-horizontal">
        <div class="border-top"></div>
        <div class="border-bottom"></div>
    </div>
</div>
```

CSS

```css
.border-top {
  border-top: 3.5px solid var(--main-buttons-color);
  position: absolute;
  top: -3px;
  left: 20px;
  right: 19.5px;
}
.border-bottom {
  border-top: 3.5px solid var(--main-buttons-color);
  position: absolute;
  top: 11px;
  left: 20px;
  right: 19.5px;
}
```

Finally it looks like that:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pmea1pu3bohobrnwyzqh.png)

### Adding curved lines

At first I tried to use the same method with the borders, but it didn't work as planned (mainly because of the positioning).
I found out about SVG drawing and it turned out to be a good solution.

```html
<svg height="100" width="225" class="left-svg">
    <polyline
     points="0,75 70,75 90,38 224,38"
     style="fill: none; stroke: black; stroke-width: 3"
     />
</svg>
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0o3qd9qav6o75cbb5azt.png)

For the right panel I used the same technique.

For cutting the right panel border I used pseudo element:

```css
#right-panel {
  background-color: var(--main-bg-color);
  box-sizing: border-box;
  position: relative;
  height: 100%;
  width: 50%;
  display: grid;
  grid-template-rows: 24% repeat(4, 19%);
  border-bottom: solid black 3px;
  border-bottom-right-radius: 10px;
}
#right-panel::before {
  content: '';
  position: absolute;
  left: -3px;
  bottom: 0;
  width: 100%;
  height: 265px;
  border-right: solid black 3px;
  border-bottom-right-radius: 7px;
}
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fkj4g6ujbfm4hxgc7fd2.png)

### Adding some Javascript

The only thing left is to fetch some data and display it on the screens.
For this I used the [pokeapi](https://pokeapi.co/) and some JS
```javascript
const getPokemonData = (pokemon) => {
  fetch(`https://pokeapi.co/api/v2/pokemon/${pokemon}`)
    .then((response) => response.json())
    .then((data) => {
      let id = ('00' + data.id).slice(-3);
      imageScreen.style.backgroundImage = `url('https://assets.pokemon.com/assets/cms2/img/pokedex/full/${id}.png')`;
      nameScreen.innerHTML = data.name;
      typeScreen.innerHTML = data.types[0].type.name;
      idScreen.innerHTML = `#${data.id}`;
      aboutScreen.innerHTML = `Height: ${data.height * 10}cm Weight: ${
        data.weight / 10
      }kg`;
      inputField.value = '';
    });
};
```

The full Code is on [Codepen](https://codepen.io/oryamne/pen/vYKXbgZ?editors=1100)

Thanks for reading and I hope you liked it.