Почему css grid-template-area не соблюдает мой медиа-запрос?

Вот код. Думаю, это глупая ошибка, но я не вижу ее -grr. Я много раз пробовал.

Области шаблона сетки медиа-запроса в моем коде:

". title title ."
". img-1-title img-2-title ."
". img-1 img-2 ."
". img-3-title img-4-title ."
". img-3 img-4 ."

но он показывает этот шаблон в моем браузере

"img-1 title title img-2"
"img-3 img-1-title img-2-title img-4"
". img-3-title img-4-title ."

html

<section>
  <div class="grid">
    <div class="title">Here is a couple of side projects</div>
    <div class="img-1-title">A chat app build with socket.io and node.js</div>
    <div class="arrow-1"><i class="fas fa-arrow-down"></i></div>
    <div class="img-1"></div>
    <div class="img-2-title">A responsive mock template of a company build with html css and flexboxgrid</div>
    <div class="arrow-2"><i class="fas fa-arrow-down"></i></div>
    <div class="img-2"></div>
    <div class="img-3-title">Wikipedia search bar connected to the wikipedia API</div>
    <div class="arrow-3"><i class="fas fa-arrow-down"></i></div>
    <div class="img-3"></div>
    <div class="img-4-title">Vanilla js calculator</div>
    <div class="arrow-4"><i class="fas fa-arrow-down"></i></div>
    <div class="img-4"></div>
  </div>
</section>

Причина, по которой я повторно объявляю свою область сетки, заключается в том, что в моей консоли отображается желтая ошибка, если я этого не сделаю. Это работает, но мне не нравится ошибка, так что да.

css

       .grid {
        display: grid;
        grid-template-columns: 1fr;
        grid-template-areas: 
        "title"
        "img-1-title"
        "arrow-1"
        "img-1"
        "img-2-title"
        "arrow-2"
        "img-2"
        "img-3-title"
        "arrow-3"
        "img-3"
        "img-4-title"
        "arrow-4"
        "img-4";
        background: rgb(27, 27, 27);
    }

    .title {
        grid-area: title;
        padding: 20px 0;
        font-family: Verdana, Tahoma, sans-serif;
        display: flex;
        justify-content: center;
        align-items: center;
        font-weight: 900;
        color: white;
    }

    .img-1 {
        grid-area: img-1;
        background: url("../postimg/chat_app.png") center/cover;
        height: 300px;
    }

    .img-2 {
        grid-area: img-2;
        background: url("../postimg/Web_template.png") center/cover;
        height: 300px;
    }

    .img-3 {
        grid-area: img-3;
        background: url("../postimg/Wiki_viewer.png") center/cover;
        height: 300px;
    }

    .img-4 {
        grid-area: img-4;
        background: url("../postimg/js_calculator.png") center/cover;
        height: 300px;
    }

    .img-1-title {
        grid-area: img-1-title;
    }

    .img-2-title {
    grid-area: img-2-title;
    }

    .img-3-title {
        grid-area: img-3-title;
    }

    .img-4-title {
    grid-area: img-4-title;
    }

    .img-1-title, .img-2-title, .img-3-title, .img-4-title {
        display: flex;
        height: 80px;
        padding: 8px;
        justify-content: center;
        align-items: center;
        font-weight: 200;
        font-family: Verdana, Tahoma, sans-serif;
        font-style: italic;
        color: white;
        border-top: 3px solid rgb(15, 177, 15);
    }

    .arrow-1 {
        grid-area: arrow-1;
    }

    .arrow-2 {
        grid-area: arrow-2;
    }

    .arrow-3 {
        grid-area: arrow-3;
    }

    .arrow-4 {
        grid-area: arrow-4;
    }

    .arrow-1, .arrow-2, .arrow-3, .arrow-4 {
        display: flex;
        padding: 15px;
        height: 25px;
        justify-content: center;
        font-size: 20px;
    }

    .fas {
        color: white;
    }

    @media only screen and (min-width: 1000px) {
        .grid {
            grid-template-columns: 200px 1fr 1fr 200px;
            grid-template-areas: 
            ". title title ."
            ". img-1-title img-2-title ."
            ". img-1 img-2 ."
            ". img-3-title img-4-title ."
            ". img-3 img-4 .";
            background: rgb(27, 27, 27);
        }

        .title {
            grid-area: title;
        }

        .img-1 {
            grid-area: img-1;
        }

        .img-2 {
            grid-area: img-2;
        }

        .img-3 {
            grid-area: img-3;
        }

        .img-4 {
            grid-area: img-4;
        }

        .img-1-title {
            grid-area: img-1-title;
        }

        .img-2-title {
        grid-area: img-2-title;
        }

        .img-3-title {
            grid-area: img-3-title;
        }

        .img-4-title {
        grid-area: img-4-title;
        }

        div.arrow-1, div.arrow-2, div.arrow-3, div.arrow-4 {
            display: none;
        }
    }

person Zein.Mrwan    schedule 28.07.2018    source источник


Ответы (2)


Может быть, это только я, но мне все кажется хорошо. Он меняет медиа-запрос на 1000 пикселей.

введите здесь описание изображения

Единственное, что я бы изменил, - это использовать промежуток между сеткой, чтобы изображения не слипались. Это значительно улучшит внешний вид небольших устройств.

.grid {
  grid-gap: 20px;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas: "title" "img-1-title" "arrow-1" "img-1" "img-2-title" "arrow-2" "img-2" "img-3-title" "arrow-3" "img-3" "img-4-title" "arrow-4" "img-4";
  background: rgb(27, 27, 27);
}

.title {
  grid-area: title;
  padding: 20px 0;
  font-family: Verdana, Tahoma, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 900;
  color: white;
}

.img-1 {
  grid-area: img-1;
  background: url("http://placekitten.com/1500/650") center/cover;
  height: 300px;
}

.img-2 {
  grid-area: img-2;
  background: url("http://placekitten.com/1500/500") center/cover;
  height: 300px;
}

.img-3 {
  grid-area: img-3;
  background: url("http://placekitten.com/2500/500") center/cover;
  height: 300px;
}

.img-4 {
  grid-area: img-4;
  background: url("http://placekitten.com/1500/600") center/cover;
  height: 300px;
}

.img-1-title {
  grid-area: img-1-title;
}

.img-2-title {
  grid-area: img-2-title;
}

.img-3-title {
  grid-area: img-3-title;
}

.img-4-title {
  grid-area: img-4-title;
}

.img-1-title,
.img-2-title,
.img-3-title,
.img-4-title {
  display: flex;
  height: 80px;
  padding: 8px;
  justify-content: center;
  align-items: center;
  font-weight: 200;
  font-family: Verdana, Tahoma, sans-serif;
  font-style: italic;
  color: white;
  border-top: 3px solid rgb(15, 177, 15);
}

.arrow-1 {
  grid-area: arrow-1;
}

.arrow-2 {
  grid-area: arrow-2;
}

.arrow-3 {
  grid-area: arrow-3;
}

.arrow-4 {
  grid-area: arrow-4;
}

.arrow-1,
.arrow-2,
.arrow-3,
.arrow-4 {
  display: flex;
  padding: 15px;
  height: 25px;
  justify-content: center;
  font-size: 20px;
}

.fas {
  color: white;
}

@media only screen and (min-width: 1000px) {
  .grid {
    grid-template-columns: 200px 1fr 1fr 200px;
    grid-template-areas: ". title title ." ". img-1-title img-2-title ." ". img-1 img-2 ." ". img-3-title img-4-title ." ". img-3 img-4 .";
    background: rgb(27, 27, 27);
  }
  .title {
    grid-area: title;
  }
  .img-1 {
    grid-area: img-1;
  }
  .img-2 {
    grid-area: img-2;
  }
  .img-3 {
    grid-area: img-3;
  }
  .img-4 {
    grid-area: img-4;
  }
  .img-1-title {
    grid-area: img-1-title;
  }
  .img-2-title {
    grid-area: img-2-title;
  }
  .img-3-title {
    grid-area: img-3-title;
  }
  .img-4-title {
    grid-area: img-4-title;
  }
  div.arrow-1,
  div.arrow-2,
  div.arrow-3,
  div.arrow-4 {
    display: none;
  }
}
<section>
  <div class="grid">
    <div class="title">Here is a couple of side projects</div>
    <div class="img-1-title">A chat app build with socket.io and node.js</div>
    <div class="arrow-1"><i class="fas fa-arrow-down"></i></div>
    <div class="img-1"></div>
    <div class="img-2-title">A responsive mock template of a company build with html css and flexboxgrid</div>
    <div class="arrow-2"><i class="fas fa-arrow-down"></i></div>
    <div class="img-2"></div>
    <div class="img-3-title">Wikipedia search bar connected to the wikipedia API</div>
    <div class="arrow-3"><i class="fas fa-arrow-down"></i></div>
    <div class="img-3"></div>
    <div class="img-4-title">Vanilla js calculator</div>
    <div class="arrow-4"><i class="fas fa-arrow-down"></i></div>
    <div class="img-4"></div>
  </div>
</section>

введите здесь описание изображения

Прошу прощения, если я неправильно понял ваш вопрос: D


Проблема может быть в вашем браузере, поскольку у вас уже были проблемы с ним.

Причина, по которой я повторно объявляю свою область сетки, заключается в том, что в моей консоли отображается желтая ошибка, если я этого не делаю. Это работает, но мне не нравится ошибка, так что да.

Firefox работает нормально, так что вы можете попробовать его использовать. У них также есть красивый вид сетки, который показывает вам сетку CSS.

Для справки моя версия firefox Firefox Quantum 61.0.1 (64-Bit)

Поскольку вы используете Chrome, я также рассмотрел проблему в Chrome, и файлы также отлично работали в моей версии Chrome Version 68.0.3440.75 (official build) (64-Bit)

Вероятно, вам следует проверить свою версию Chrome и сравнить ее со списком поддерживаемых браузеров.

Если вы не знаете, как проверить версию своего браузера, вот небольшое руководство для большинства современных веб-браузеров. [ССЫЛКА]

person Ironlors    schedule 28.07.2018
comment
Я просто использовал простой CSS и HTML. Какой браузер вы используете? Сейчас я использую firefox. Возможно, есть какие-то проблемы с совместимостью, поскольку вы сказали, что ваша консоль выдает вам ошибки. - person Ironlors; 28.07.2018
comment
Я использую Chrome. - person Zein.Mrwan; 28.07.2018
comment
Мне нужно уйти, я отвечу позже, я поддержу ваш ответ, если ваш следующий комментарий решит мою проблему. - person Zein.Mrwan; 28.07.2018
comment
добавил немного к моему ответу на вопрос о браузере - person Ironlors; 28.07.2018
comment
Мой Chrome не был последней версией, но когда я обновил его до (Версия 68.0.3440.75 (Build officiel) (64 бит)), он все еще не работал и все еще показывает желтые ошибки. Я пробовал в firefox (той же версии, что и ваша) и тот же результат. Я отдал вам голос за ваши усилия, спасибо. - person Zein.Mrwan; 29.07.2018
comment
Я просто пробовал на других страницах, и это работает, что-то не так с моим компонентом портфолио. - person Zein.Mrwan; 29.07.2018

OMG, я нашел свою проблему, у меня были теги <a> до моих div, которые портили сетку, я не знаю, почему я не включил их в свой HTML, я предположил, что это не проблема, - хлопает по лбу.

person Zein.Mrwan    schedule 29.07.2018