Игра теней / Испытание: зловещие тени [17/17]

Добрый день. Оцените правильность кода пожалуйста:
HTML:

<!DOCTYPE html>
<html lang="ru">
    <head>
        <meta charset="utf-8">
        <title>Испытание: зловещие тени</title>
    </head>
    <body>
        <div class="btn">Поехали!</div>
        <div class="help"></div>
    </body>
</html>

CSS:

html,
body {
    width: 300px;
    margin: 0;
    padding: 0;
    font-size: 18px;
    font-family: "Arial", sans-serif;
    background: #ecf0f1;
}

.btn {
    width: 250px;
    margin: 0 25px;
    margin-top: 100px;
    padding: 20px 0;
    line-height: 20px;
    text-align: center;
    text-transform: uppercase;
    color: white;
    background: #2c3e50;
    cursor: pointer;
    box-shadow:   
                    0  20px  0 -10px #2980b9,
                    0  40px  0 -20px #3498db,
                    0 -20px  0 -10px #c0392b,
                    0 -40px  0 -20px #e74c3c,
              inset 0   5px  0   0   #16a085,
              inset 0  -5px  0   0   #2ecc71;
}

.btn::before {
    content: "";
    position: absolute;
    width: 125px;
    height: 5px;
    top: 100px;
    left: 25px;
    box-shadow: inset 0 5px 0 0 #2ecc71;
}

.btn::after {
    content: "";
    position: absolute;
    width: 125px;
    height: 5px;
    top : 155px;
    left: 25px;
    box-shadow: inset 0 5px 0 0 #16a085;
}
2 лайка

Относительно чего в вашем коде рассчитаны координаты top и left у псевдоэлементов?

1 лайк

относительно окна браузера. я так понял лучше указать относительно .btn, задав данному элементу относительное позиционирование

Куда правильней с точки зрения структуры кода сделать так.
Задаем для баттона относительное позиционирование
.btn {
position:relative;
}
И затем выравнивать темно-зеленые линии
.btn::after {
content: “”;
position: absolute;
width: 125px;
height: 5px;
top:0px;
left:125px;
background-color:#16a085;
}
.btn::before {
content: “”;
position: absolute;
width: 125px;
height: 5px;
top:55px;
left:0px;
background-color:#16a085;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 300px;
  background-color: #ecf0f1;
  font-size: 18px;
  font-family: "Arial", sans-serif;
}

.btn {
  position: relative;
  display: block;
  margin: 0 25px;
  margin-top: 100px;
  padding: 20px 0;
  width: 250px;
  border: none;
  box-sizing: content-box;
  background-color: #2c3e50;
  box-shadow:
    0  20px 0 -10px #2980b9,
    0 -20px 0 -10px #c0392b,
    0  40px 0 -20px #3498db,
    0 -40px 0 -20px #e74c3c,
    inset 0 5px 0 0 #16a085,
    inset 0 -5px 0 0 #2ecc71;
  color: white;
  text-align: center;
  text-transform: uppercase;
  font: inherit;
  line-height: 20px;
}


.btn:before {
  content: "";
  position: absolute;
  bottom: 5px; left: 0;
  width: 125px;
  height: 50px;
  box-shadow:
    0 -5px 0 0 #2ecc71,
    0  5px 0 0 #16a085;
}

Я сделал чуток по-другому

5 лайков

Самое изящное решение :+1:

молодцы, додумались круто! я вообще забыл про before & after.

Мой 100% вариант:

html,
body {
  margin: 0;
  padding: 0;
  width: 300px;
  background-color: #ecf0f1;
  font-size: 18px;
  font-family: "Arial", sans-serif;
}

.btn {
  display: block;
  margin: 0 25px;
  margin-top: 100px;
  padding: 20px 0;
  width: 250px;
  border: none;
  box-sizing: content-box;
  background-color: #2c3e50;
  color: white;
  text-align: center;
  text-transform: uppercase;
  font: inherit;
  line-height: 20px;
  box-shadow:
    inset 0 5px 0 0 #16a085,
    0 -20px 0 -10px #c0392b,
    0 -40px 0 -20px #e74c3c,
    
    inset 0 -5px 0 0px #2ecc71,
    0 20px 0 -10px #2980b9,
    0 40px 0 -20px #3498db;
}

.help {
  width: 125px;
  height: 60px;
  position: absolute;
  left: 25px;
  top: 100px;
  box-shadow: 
    inset 0 5px 0 0 #2ecc71,
    inset 0 -5px 0 0 #16a085;
}

sceen