Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
  <body>
    <div class="header">
      <a href=""
        ><h1>rank<i class="fas fa-medal"></i>the_dogs</h1></a
      >
      <button class="vote-button">Vote</button>
      <h1><i class="fas fa-dog dogIcon1"></i></h1>
      <h1><i class="fas fa-dog dogIcon2"></i></h1>
      <h1><i class="fas fa-dog dogIcon3"></i></h1>
      <h1><i class="fas fa-trophy"></i></h1>
    </div>
    <div class="container">
      <div class="dogs-container"></div>
    </div>

    <div class="footer">
      <small>powered_by </small><br />
      <a href="https://dog.ceo/dog-api/"
        ><small class="dog-api">Dog API </small
        ><img src="https://dog.ceo/img/dog-api-logo.svg" alt="Dog API Logo"
      /></a>
    </div>

    <script
      src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"
      integrity="sha512-bZS47S7sPOxkjU/4Bt0zrhEtWx0y0CRkhEp8IckzK+ltifIIE9EMIMTuT/mEzoIMewUINruDBIR/jJnbguonqQ=="
      crossorigin="anonymous"
    ></script>
    <script src="script.js"></script>
  </body>
</html>

              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Poppins:wght@200;400&display=swap");

:root {
  --primary-color: #22254b;
  --secondary-color: #373b69;
  --red: #7c0000;
}

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

body {
  font-family: "Poppins";
  height: 100vh;
  color: white;
  background-color: var(--primary-color);
}

a {
  text-decoration: none;
  color: white;
}

/***********HEADER***********/
.header {
  background-color: var(--secondary-color);
  position: fixed;
  height: 110px;
  width: 100%;
  top: 0;
  padding: 20px;
  margin-bottom: 3%;
}

.header h1,
.header .fa-medal {
  font-size: 200%;
  letter-spacing: 4px;
  display: inline;
}

.header .fa-medal {
  color: var(--red);
}

.header .fa-dog,
.header .fa-trophy {
  font-size: 150%;
  position: absolute;
  top: 31px;
}

.header .fa-trophy {
  right: 20px;
  color: var(--red);
}

.header .fa-dog.dogIcon1 {
  right: 98px;
  top: 15px;
}

.header .fa-dog.dogIcon2 {
  right: 176px;
  top: 46px;
}

.header .fa-dog.dogIcon3 {
  right: 254px;
}

.vote-button {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 250%;
  letter-spacing: 5px;
  font-family: inherit;
  font-weight: bold;
  background-color: #ffd700;
  color: var(--primary-color);
  cursor: pointer;
  padding: 10px 60px;
  outline: none;
  border-radius: 50px;
  /* box-shadow: 5px 5px 15px (0, 0, 0, 0.2); */
}

.vote-button:hover {
  background-color: #ffe658;
}

.vote-button:focus {
  outline: none;
}

/***********FOOTER***********/
.footer {
  background-color: var(--secondary-color);
  position: fixed;
  height: 55px;
  width: 100%;
  bottom: 0;
  margin-top: 3%;
  text-align: center;
}

.footer small {
  font-size: 12px;
}

.footer img {
  width: 20px;
  height: 20px;
}

.dog-api {
  font-weight: bold;
}

/***********MAIN CONTAINER***********/
.container {
  position: absolute;
  height: calc(100% - 165px - 6%);
  top: calc(110px + 3%);
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* **********DOG PICTURE CONTAINER***********/
.dogs-container {
  max-width: 1060px;
  max-height:800px;
  height: 100%;
  display: grid;
  grid-gap: 5px;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: 32.5% 32.5% 32.5%;
  grid-template-areas:
    "dog0 dog1 dog-big dog-big"
    "dog2 dog3 dog-big dog-big"
    "dog4 dog5 dog6 dog7";
}

.dogs-container .dog img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: middle;
  cursor: pointer;
  border: 5px solid var(--primary-color);
  opacity: 0.75;
  transform: scale(1);
  animation: load 1s ease-in-out;
  border-radius: 10px;
  border: solid 5px var(--secondary-color);
}

@keyframes load {
  0% {
    transform: scale(0.5);
  }
  100% {
    transform: scale(1);
  }
}

.dogs-container .dog.dog-small img {
    max-height: 250px;
  max-width: 250px;
}


.dogs-container .dog img:hover {
  border: solid 5px var(--red);
  opacity: 1;
}

.dogs-container .dog.active img {
  border: solid 5px gold;
  opacity: 1;
}

.dog0 {
  grid-area: dog0;
}

.dog1 {
  grid-area: dog1;
}

.dog2 {
  grid-area: dog2;
}

.dog3 {
  grid-area: dog3;
}

.dog4 {
  grid-area: dog4;
}

.dog5 {
  grid-area: dog5;
}

.dog6 {
  grid-area: dog6;
}

.dog7 {
  grid-area: dog7;
}

.dog-big {
  grid-area: dog-big;
}

@media (max-width: 960px) {
  .fa-trophy,
  .dogIcon1,
  .dogIcon3,
  .dogIcon2 {
    display: none;
  }
  .vote-button {
    left: 84vw;
  }
}

@media (max-width: 384px) {
  .header {
    height: 55px;
  }

  .header h1,
  .header .fa-medal {
    font-size: 100%;
    letter-spacing: 2px;
    display: inline-block;
    text-align: center;
  }
}

              
            
!

JS

              
                const dogsContainer = document.querySelector('.dogs-container')
const voteButton = document.querySelector('.vote-button')

const URL = 'https://dog.ceo/api/breeds/image/random'
const dogCount = 8;

fetchWinningDog();
async function fetchWinningDog() {
    if (!document.querySelector('.dog-big')){
        response = await axios.get(URL);
        const {message: fetchedDog } = response.data

        const bigDogCard = document.createElement('div')
        bigDogCard.classList.add('dog', 'dog-big')
        bigDogCard.innerHTML = `<img src='${fetchedDog}' alt='Big Dog' />`
        dogsContainer.appendChild(bigDogCard)

    } else {
        const allDogs = document.querySelectorAll('.dog')
        let favoriteDog = ''
        allDogs.forEach(dog => {
            if(dog.classList.contains('active')){
                favoriteDog = dog
                dogsContainer.innerHTML = ''
                const bigDogCard = document.createElement('div')
                bigDogCard.classList.add('dog', 'dog-big', 'active')
                bigDogCard.innerHTML = `<img src='${favoriteDog.firstElementChild.src}' alt='Big Dog' />`
                
                dogsContainer.appendChild(bigDogCard)
                fetchSmallDogs()
            }
        })
        console.log('use the old active one')
    }
}

fetchSmallDogs();
async function fetchSmallDogs() {
    response = await axios.get(URL + '/' + dogCount);
    const {message: fetchedDogs } = response.data

    fetchedDogs.forEach((dog, index) => {
        const dogCard = document.createElement('div')
        dogCard.classList.add('dog', 'small-dog', `dog${index}`)
        dogCard.innerHTML = `<img src='${dog}' alt=Dog ${index} />`
        dogsContainer.appendChild(dogCard)
    })
}

dogsContainer.addEventListener('click', e => {
    if(e.target.parentElement.classList.contains('dog')){
        if(e.target.parentElement.classList.contains('active')){
            e.target.parentElement.classList.remove('active')
        }else {
            removeActive();
            e.target.parentElement.classList.add('active')
        }
    }
})

function removeActive() {
    const allDogs = document.querySelectorAll('.dog')
    allDogs.forEach(dog => {
        dog.classList.remove('active')
    })
}

voteButton.addEventListener('click', () => fetchWinningDog())

              
            
!
999px

Console