Проблема с мобильной версией сайта

Проблема заключается в неправильном размере страницы, а именно navbar при загрузке (ниже фотографии проблемы) В чем может быть проблема?

Что бы увидеть проблему, F12 -> Toggle device toolbar -> Mobile L

Полностью видно .background при двойном нажатии на экран

Фото проблемы:

При первой загрузке:

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

Вот что должно быть:

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

var myPlugin = {
     name: 'debugger',
     params: {
       debugger: false,
     },
     on: {
       init: function (swiper) {
         if (!swiper.params.debugger) return;
         console.log('init');
       },
       click: function (swiper, e) {
         if (!swiper.params.debugger) return;
         console.log('click');
       },
       tap: function (swiper, e) {
         if (!swiper.params.debugger) return;
         console.log('tap');
       },
       doubleTap: function (swiper, e) {
         if (!swiper.params.debugger) return;
         console.log('doubleTap');
       },
       sliderMove: function (swiper, e) {
         if (!swiper.params.debugger) return;
         console.log('sliderMove');
       },
       slideChange: function (swiper) {
         if (!swiper.params.debugger) return;
         console.log('slideChange', this.previousIndex, '->', this.activeIndex);
       },
       slideChangeTransitionStart: function (swiper) {
         if (!swiper.params.debugger) return;
         console.log('slideChangeTransitionStart');
       },
       slideChangeTransitionEnd: function (swiper) {
         if (!swiper.params.debugger) return;
         console.log('slideChangeTransitionEnd');
       },
       transitionStart: function (swiper) {
         if (!swiper.params.debugger) return;
         console.log('transitionStart');
       },
       transitionEnd: function (swiper) {
         if (!swiper.params.debugger) return;
         console.log('transitionEnd');
       },
       fromEdge: function (swiper) {
         if (!swiper.params.debugger) return;
         console.log('fromEdge');
       },
       reachBeginning: function (swiper) {
         if (!swiper.params.debugger) return;
         console.log('reachBeginning');
       },
       reachEnd: function (swiper) {
         if (!swiper.params.debugger) return;
         console.log('reachEnd');
       },
     },
   };
*{
  font-family: "montserrat", sans-serif;
  box-sizing: border-box;
  margin: 0;
  margin-top: -10px;
  padding: 0;
}


body {
  background-color: #ececec;
  font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  font-size: 14px;
  color: #fff;
  margin: 0;
  padding: 0;
}

.background {
  background: #333;
  height: 100px;
  width: 100%;
}

.background h1.logo {
  font-size: 29px;
  margin-left: 30px;
  transform: translateY(80%);
  color: #e3e3e3;
}

.background h3.sub_logo {
  font-size: 19px;
  margin-left: 30px;
  transform: translateY(170%);
  color: #e3e3e3;
}

.background .checkbtn {
  font-size: 30px;
  color: white;
  float: right;
  line-height: 80px;
  margin-right: 40px;
  cursor: pointer;
  display: none;
}

#check {
  display: none;
}

.background nav {
  height: 120px;
  width: 100%;
}

.background ul {
  float: right;
  margin-right: 30.5px;
  transform: translateY(136%);
}

.background ul li {
  display: inline-block;
}

.background ul li a,
.background ul li a:after {
  transition: all .3s;
}

.background ul li a {
  text-decoration: none;
  color: #fff;
  font-size: 21px;
  padding: 10px 15px;
  position: relative;
}

.background ul li a:after {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  width: 0%;
  content: ".";
  color: transparent;
  background: #aaa;
  height: 1px;
}

.background ul li a:hover:after {
  width: 100%;
}

.background ul li a.active {
  text-decoration: none;
  color: yellow;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  font-size: 21px;
  padding: 10px 15px;
  position: relative;
}

.background ul li a.active:after {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  width: 0%;
  content: ".";
  color: transparent;
  height: 1px;
}

.background ul li a.active:hover:after {
  width: 100%;
}

.background ul li a:hover, a.active {
  transition: .5s;
}

.main-part {
  height: auto;
  width: 80%;
  box-shadow: 0 0 10px rgba(0, 0, 0, 1);
  transform: translateX(13%);
  margin-top: 10px;
  background-color: #fff;
}

h2.latest {
  color: #333;
  letter-spacing: 0.2em;
  text-align: center;
  transform: translateY(500%);
  transition: .5s;
}
.swiper-container {
  width: 70%;
  height: 90%;
  margin-top: 100px;
  border: 2px solid #000;
}

.swiper-wrapper {
  padding-top: 18px;
  padding-bottom: 40px;
  justify-content: center;
  align-items: center;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;
  justify-content: center;
  align-items: center;
  padding-bottom: 40px;
}

.swiper-pagination {
  height: 10px;
  width: 200px;
  padding-bottom: 25px;
}

.swiper-wrapper img {
  height: 100.38%;
  width: 100%;
  padding: 10px;
  padding-bottom: 10px;
}

.swiper-button-prev {
  margin-left: 20px;
}

.swiper-button-next {
  margin-right: 20px;
}

.latest {
  color: #000;
  text-align: center;
  letter-spacing: 0.1em;
  transform: translateY(60%);
  font-size: 80px;
  font-weight: bold;
}
/*-------------------------------------------*/

/*-------------------------------------------*/

.top {
  font-size: 50px;
  color: #000;
  border-bottom: 2px solid #000;
  border-top: 2px solid #000;
  padding: 15px;
  margin-left: 290px;
  margin-right: 290px;
  text-align: center;
  transform: translateY(170%);
}

.top-photos-gallery {
  transform: translateY(7%);
  border: 2px solid rgba(0, 0, 0, 0.9);
  padding: 2px 0 auto;
  justify-content: center;
  align-items: center;
  padding: 15px;
  margin-left: 295px;
  margin-right: 295px;
}

.image-slide {
  justify-content: center;
  align-items: center;
  text-align: center;
  align-content: center;
  padding-bottom: 20px;
  padding-top: 20px;
}

.image-slide img {
  justify-content: center;
  align-items: center;
}

.top-photos-gallery::after {
  content: "";
  display: table;
  clear: both;
}

.modal {
  display: none;
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 100%;
  height: 110%;
  overflow: hidden;
  background-color: rgba(0, 0, 0, 0.8);
}

.modal-content {
  position: relative;
  background: transparent;
  padding: 0;
  transform: translateY(8%);
  margin-left: 300px;
  width: 90%;
  max-width: 1200px;
}

.close {
  color: white;
  position: absolute;
  top: 45px;
  right: 45px;
  font-size: 55px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: #999;
  text-decoration: none;
  cursor: pointer;
}

.Slides {
  display: none;
}

.prev,
.next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  padding: 16px;
  margin-top: -50px;
  color: white;
  font-weight: bold;
  font-size: 40px;
  transition: 0.6s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
  -webkit-user-select: none;
}

.next {
  transform: translateX(2302%);
  border-radius: 3px 0 0 3px;
}

.prev:hover,
.next:hover {
  background-color: rgba(0, 0, 0, 0.8);
}

.numbertext {
  color: #f2f2f2;
  font-size: 22px;
  padding: 8px 12px;
  position: absolute;
  top: 0;
}

.caption-container {
  text-align: center;
  background-color: black;
  padding: 2px 16px;
  color: white;
}

img.demo {
  opacity: 0.6;
}

.active,
.demo:hover {
  opacity: 1;
}

img.hover-shadow {
  transition: 0.3s;
}

.hover-shadow:hover {
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

/*-----------------------------------------*/

.social-icon-list {
  width: 100%;
  height: auto;
  margin: auto;
  margin-top: 50px;
}

.social-icon-list ul {
  margin: 0px;
  padding: 0px;
  margin-top: -50px;
  transform: translateX(670%);
  position: relative;
  background: transparent;
  height: 100px;
  width: 240px;
}

.social-icon-list ul li {
  display: inline-block;
  width: 70px;
  height: 70px;
  text-align: center;
  margin: 0px;
}

.social-icon-list ul li a {
  display: inline-block;
  color: #fff;
  font-size: 20px;
  opacity: 60%;
  transition: .2s;
}

.social-icon-list ul li a:hover {
  opacity: 100%;
  transition: .2s;
}

.social-icon-list ul li a img {
  height: 50px;
  width: 50px;
  margin-top: 25px;
  text-align: center;
}

/*-----------------------------------------*/
footer {
  border-top: 3px solid #333;
  border-radius: 3px;
  padding: 20px;
  transform: translateY(900%);
  color: #000;
  text-align: center;
}

footer h4 {
  font-size: 20px;
}

footer h5 {
  transform: translateY(60%);
}

@media (max-width: 425px) {
  body {
    height: auto;
    width: 425px;
  }

  .background {
    transform: translateX(0%);
    width: 1750px;
    height: 300px;
    z-index: -1;
  }

  .background h1.logo {
    font-size: 90px;
    margin-left: 70px;
    transform: translateY(60%);
  }

  .background h3.sub_logo {
    font-size: 50px;
    margin-left: 100px;
    transform: translateY(130%);
  }

  .background .checkbtn {
    font-size: 90px;
    display: block;
    transform: translateX(-160%);
  }

  .background ul {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 400vh;
    transform: translateY(0.4%);
    background: rgb(109, 109, 109);
    top: 80px;
    left: -100%;
    text-align: center;
    transition: all .5s;
    border: none;
  }

  .background ul li {
    display: block;
    margin: 50px 0;
    line-height: 30px;
    text-align: center;
  }

  .background ul li a {
    font-size: 20px;
  }

  .background ul li a:hover, a.active {
    background: none;
    color: rgb(255, 230, 0);
  }

  #check:checked ~ ul {
    left: 0;
  }
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta oncontextmenu="return false;">
    <title>Photography</title>
    <script src="https://kit.fontawesome.com/a076d05399.js"></script>
    <link rel="stylesheet" type="text/css" href="Home.css"/>
    <link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css">
    <script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
    <link rel="stylesheet" href="../package/swiper-bundle.min.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  </head>
  <body>
    <script src="Home.js"></script>

    <header class="background">
      <h1 class="logo">Name</h1>
      <h3 class="sub_logo">Photography</h3>

      <nav>
        <input type="checkbox" id="check">
        <label for="check" class="checkbtn">
          <i class="fas fa-bars"></i>
        </label>
        <ul>
          <li><a href="Home.html" class="active">Home</a></li>
          <li><a href="Gallery.html">Gallery</a></li>
          <li><a href="About.html">About</a></li>
          <li><a href="Contact.html">Contact</a></li>
        </ul>
      </nav>
    </header>

    <div class="social-icon-list">
      <ul>
        <li><a href="https://www.instagram.com/agurec.ph/" class="instagram"><img src="img/instagram.png"></a></li>
        <li><a href="https://www.facebook.com/messages/t/stas.zakharov.35" class="facebook-messenger"><img src="img/facebook messenger.png"></a></li>
        <li><a href="https://web.telegram.org/#/im?p=@agurec7" class="telegram"><img src="img/telegram.png"></a></li>
      </ul>
    </div>
    
    <h1 class="latest">Latest: </h1>

    <div class="swiper-container">
      <div class="swiper-wrapper">
        <img src="img/wheel.jpg" class="swiper-slide" oncontextmenu="return false;">
        <img src="img/car_filtered_wide.jpg" class="swiper-slide">
        <img src="img/car_park_bg.jpg" class="swiper-slide">
        <img src="img/car_build_bg.jpg" class="swiper-slide">
        <img src="img/car_road_bg.jpg" class="swiper-slide">
      </div>

      <div class="swiper-pagination"></div>
      <div class="swiper-button-prev"></div>
      <div class="swiper-button-next"></div>
    </div>

    <h1 class="top">Top:</h1>

    <!-- Site photos -->

    <div class="top-photos-gallery">
      <div class="image-slide">
        <img src="img/wheel.jpg" onclick="openModal();currentSlide(1)" class="hover-shadow">
      </div>
      <div class="image-slide">
        <img src="img/car_filtered_wide.jpg" onclick="openModal();currentSlide(2)" class="hover-shadow">
      </div>
      <div class="image-slide">
        <img src="img/car_park_bg.jpg" onclick="openModal();currentSlide(3)" class="hover-shadow">
      </div>
      <div class="image-slide">
        <img src="img/car_road_bg.jpg" onclick="openModal();currentSlide(4)" class="hover-shadow">
      </div>
    </div>

    <!-- Modal -->

    <div id="Modal" class="modal">
      <span class="close cursor" onclick="closeModal()">&times;</span>
      <div class="modal-content">

        <div class="Slides">
          <div class="numbertext">1 / 4</div>
          <img src="img/wheel.jpg">
        </div>

        <div class="Slides">
          <div class="numbertext">2 / 4</div>
          <img src="img/car_filtered_wide.jpg">
        </div>

        <div class="Slides">
          <div class="numbertext">3 / 4</div>
          <img src="img/car_park_bg.jpg">
        </div>

        <div class="Slides">
          <div class="numbertext">4 / 4</div>
          <img src="img/car_road_bg.jpg">
        </div>

        <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
        <a class="next" onclick="plusSlides(1)">&#10095;</a>
      </div>
    </div>

    <script>
      function openModal() {
        document.getElementById("Modal").style.display = "block";
      }
      
      function closeModal() {
        document.getElementById("Modal").style.display = "none";
      }
      
      var slideIndex = 1;
      showSlides(slideIndex);
      
      function plusSlides(n) {
        showSlides(slideIndex += n);
      }
      
      function currentSlide(n) {
        showSlides(slideIndex = n);
      }
      
      function showSlides(n) {
        var i;
        var slides = document.getElementsByClassName("Slides");
        var dots = document.getElementsByClassName("demo");
        var captionText = document.getElementById("caption");
        if (n > slides.length) {slideIndex = 1}
        if (n < 1) {slideIndex = slides.length}
        for (i = 0; i < slides.length; i++) {
          slides[i].style.display = "none";
        }
        for (i = 0; i < dots.length; i++) {
          dots[i].className = dots[i].className.replace(" active", "");
        }
        slides[slideIndex-1].style.display = "block";
        dots[slideIndex-1].className += " active";
        captionText.innerHTML = dots[slideIndex-1].alt;
      }
    </script>

    <script src="../package/swiper-bundle.min.js"></script>

    <script>
     Swiper.use(myPlugin);

     var swiper = new Swiper('.swiper-container', {
       pagination: {
         el: '.swiper-pagination',
         clickable: true,
       },
       navigation: {
         nextEl: '.swiper-button-next',
         prevEl: '.swiper-button-prev',
       },
       debugger: true,
     });
    </script>

    <footer>
      <div class="text"></div>
        <h4>&copy; Name</h4>
    </footer>
  </body>
</html>


Ответы (1 шт):

Автор решения: xydope

Основная проблема в том, что у вас куча ошибок в разметке и стилизации, которые наслаиваются друг на друга и раз за разом вызывают различные побочные эффекты.

  • Вы не группируете элементы в блоки, например checkbox и logo (см пример ниже)
  • Непонимание позиционирования элементов, вы все позиционирование выполняете через transform: translate - это ошибка. Смотрите в сторону grid, flex, float
  • Куча мелких ошибок, например, вы для ВСЕХ элементов устанавливаете margin-top: -10px, зачем?

Можно продолжать дальше, но смысла в этом особого нет.

Ниже пример вашего меню, сделал беглые правки, чтобы работало.

* {
  font-family: "montserrat", sans-serif;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: #ececec;
  font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  font-size: 14px;
  color: #fff;
  margin: 0;
  padding: 0;
}

.background {
  background: #333;
  height: 100px;
  
  /*Элементы позиционируются через flex, слева и справа*/
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/*отступ назначается на весь блок logo*/
.logo {
  margin-left: 30px;  
}

/* name - теперь logo_name, убрать смещения, убрать отступы*/
.logo_name {
  font-size: 29px;
  color: #e3e3e3;
}

.sub_logo {
  font-size: 19px;
  color: #e3e3e3;
}

.background .checkbtn {
  font-size: 30px;
  color: white;
  float: right;
  line-height: 80px;
  margin-right: 40px;
  cursor: pointer;
}

.background ul {
  float: right;
  margin-right: 30.5px;
}

.background ul li {
  display: inline-block;
}

.background ul li a,
.background ul li a:after {
  transition: all 0.3s;
}

.background ul li a {
  text-decoration: none;
  color: #fff;
  font-size: 21px;
  padding: 10px 15px;
  position: relative;
}

.background ul li a:after {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  width: 0%;
  content: ".";
  color: transparent;
  background: #aaa;
  height: 1px;
}

.background ul li a:hover:after {
  width: 100%;
}

.background ul li a.active {
  text-decoration: none;
  color: yellow;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  font-size: 21px;
  padding: 10px 15px;
  position: relative;
}

.background ul li a.active:after {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  width: 0%;
  content: ".";
  color: transparent;
  height: 1px;
}

.background ul li a.active:hover:after {
  width: 100%;
}

.background ul li a:hover,
a.active {
  transition: 0.5s;
}

/*скрываем чекбокс*/
.checkbox {
   display: none;
}

@media (max-width: 425px) {

  .checkbox {
    display: block;
  }

  .background ul {
    z-index: 1;
    position: absolute;
    margin: 0;
    width: 100%;
    /*height: 400vh; это что? высота 4 экрана? зачем?*/
    background: rgb(109, 109, 109);
    top: 100px;
    right: 0;
    text-align: center;
    transition: all 0.5s;
    border: none;
  }

  .background ul li {
    display: block;
    margin: 50px 0;
    line-height: 30px;
    text-align: center;
  }

  .background ul li a {
    font-size: 20px;
  }

  .background ul li a:hover,
  a.active {
    background: none;
    color: rgb(255, 230, 0);
  }

  #check:checked ~ ul {
    left: 0;
  }
}
<header class="background">
  <!-- Объединил элементы логотипа в блок-->
  <div class="logo">
    <h1 class="logo_name">Name</h1> 
    <h3 class="sub_logo">Photography</h3>
  </div>
  <nav>
    <!-- Все, что относится к чекбоксу объединяем в блок чекбокс -->
    <div class="checkbox">
      <!-- Иконку бургера вместо чекбокса оставлю вам -->
      <input type="checkbox" id="check">
      <label for="check" class="checkbtn">
        <i class="fas fa-bars"></i>
      </label>
    </div>
    <ul>
      <li><a href="Home.html" class="active">Home</a></li>
      <li><a href="Gallery.html">Gallery</a></li>
      <li><a href="About.html">About</a></li>
      <li><a href="Contact.html">Contact</a></li>
    </ul>
  </nav>
</header>

→ Ссылка