Добавление ссылки на lo go добавляет ссылку на всю панель навигации - PullRequest
0 голосов
/ 11 июля 2020

Я добавил ссылку на lo go (изображение) на панели навигации, но когда я go перехожу на страницу, вся панель навигации, кроме ссылок, становится ссылкой. Как мне сделать так, чтобы он применялся только к изображению?

Согласно комментариям, я обновил код с помощью CSS и JS. Я новичок в веб-разработке, это может объяснить отсутствие у меня знаний и чрезмерное использование CSS.

image

function navHamburger() {
 var x = document.getElementById("nav-links");
 if (x.style.display === "block") {
  x.style.display = "none";
 } else {
  x.style.display = "block";
 }
}
nav {
  background-color: #fff;
}

.nav-row {
  /* margin: 0; */
  overflow: hidden;
  position: relative;
  padding: 10px;
}

.nav-row #nav-links {
  display: none;
}
.nav-row a {
  color: #0075b2;
  text-decoration: none;
  font-weight: 500;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  text-align: center;
  text-transform: uppercase;
  padding: 20px;
}

.nav-row a.icon {
  font-size: 200%;
  display: block;
  position: absolute;
  right: 0;
  top: 0;
  margin-top: 0.1em;
  margin-right: 25px;
}

.nav-row a:hover {
  color: #19afff;
}

.main-nav {
  text-decoration: none;
  list-style: none;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
      -ms-flex-direction: row;
          flex-direction: row;
}

.mobile-menu {
  text-decoration: none;
  list-style: none;
}

.main-nav li a:link,
.main-nav li a:visited {
  color: #0075b2;
  text-decoration: none;
  text-transform: uppercase;
  font-size: 150%;
  font-weight: 500;
  padding: 4px;
}

.main-nav li a:hover,
.main-nav li a:active {
  border-top: 2px solid #b36500;
  border-bottom: 2px solid #b36500;
  -webkit-transition: border-bottom 0.2s;
  -o-transition: border-bottom 0.2s;
  transition: border-bottom 0.2s;
}

@media (min-width: 601px) {
  .mobile-menu {
    display: none;
  }
}

.desktop-menu {
  display: none;
  right: 0;
  top: 0;
}
@media (min-width: 601px) {
  .desktop-menu {
    display: block;
    position: absolute;
    margin-top: 30px;
    margin-right: 10px;
  }
  .nav-row {
    margin-right: 20px;
  }
  .nav-row a {
    margin-left: 20px;
  }
}

@media (min-width: 901px) {
  .desktop-menu {
    margin-top: 50px;
    margin-right: 10px;
  }
}

@media (min-width: 1290px) {
  .desktop-menu {
    margin-top: 70px;
    margin-right: 10px;
  }
}
image

Ответы [ 3 ]

1 голос
/ 11 июля 2020

Вы используете flex для основного класса nav, который принимает полное встроенное значение:

fiddle для воспроизведения.

nav {
  background-color: #fff;
}

.nav-row {
  /* margin: 0; */
  overflow: hidden;
  position: relative;
  padding: 10px;
}

.nav-row #nav-links {
  display: none;
}

img {
  height: 100px;
  width: 100px;
}

.nav-row a {
  color: #0075b2;
  text-decoration: none;
  font-weight: 500;
  text-align: center;
  text-transform: uppercase;
  padding: 20px;
}

.nav-row a.icon {
  font-size: 200%;
  display: block;
  position: absolute;
  right: 0;
  top: 0;
  margin-top: 0.1em;
  margin-right: 25px;
}

.nav-row a:hover {
  color: #19afff;
}

.main-nav {
  text-decoration: none;
  list-style: none;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
}

.mobile-menu {
  text-decoration: none;
  list-style: none;
}

.main-nav li a:link,
.main-nav li a:visited {
  color: #0075b2;
  text-decoration: none;
  text-transform: uppercase;
  font-size: 150%;
  font-weight: 500;
  padding: 4px;
}

.main-nav li a:hover,
.main-nav li a:active {
  border-top: 2px solid #b36500;
  border-bottom: 2px solid #b36500;
  -webkit-transition: border-bottom 0.2s;
  -o-transition: border-bottom 0.2s;
  transition: border-bottom 0.2s;
}

@media (min-width: 601px) {
  .mobile-menu {
    display: none;
  }
}

.desktop-menu {
  display: none;
  right: 0;
  top: 0;
}

@media (min-width: 601px) {
  .desktop-menu {
    display: block;
    position: absolute;
    margin-top: 30px;
    margin-right: 10px;
  }
  .nav-row {
    margin-right: 20px;
  }
  .nav-row a {
    margin-left: 20px;
  }
}

@media (min-width: 901px) {
  .desktop-menu {
    margin-top: 50px;
    margin-right: 10px;
  }
}

@media (min-width: 1290px) {
  .desktop-menu {
    margin-top: 70px;
    margin-right: 10px;
  }
}
image
1 голос
/ 11 июля 2020

"display: flex" здесь виноват. Из-за свойства display: flex css в ссылке ссылка занимает полную строку. Но это не похоже на то, что другие элементы навигации также превратились в ссылку, но поскольку ссылка занимает всю ширину и накладывается поверх других элементов навигации, это должно создавать ощущение, что другие элементы навигации также стали такой же ссылкой. Вы можете обратиться к приведенному ниже снимку экрана:

enter image description here

Here is the code of it:

<!DOCTYPE html>



    
        .logo-link {
            display: flex;
            cursor: pointer
        }

        .logo-link img {
            max-height: 200px;
        }
    



    

Вы можете создать ваш код, подобный этому, чтобы решить эту проблему:

<!DOCTYPE html>
<html>

<head>
    <style>
        nav {
            width: 100%;
            height: 100px;
            background-color: bisque;
            box-sizing: border-box;
            display: flex;
            align-items: center;
        }

        nav .align-left {
            margin-left: 10px;
            margin-right: auto;
            height: 90%;
        }

        nav .align-right {
            margin-left: auto;
            margin-right: 10px;
            height: 100%;
            display: flex;
            justify-content: space-between;
            width: 11%;
            height: 20%;

        }

        nav .logo-link>img {
            height: 100%;
        }
    </style>
</head>

<body>
    <nav>
        <div class="align-left">
            <a class="logo-link" href=""><img
                    src="https://i.pinimg.com/736x/5b/b4/8b/5bb48b07fa6e3840bb3afa2bc821b882.jpg"></a>
        </div>
        <div class="align-right">
            <div>Item 1</div>
            <div>Item 2</div>
            <div>Item 3</div>
        </div>
    </nav>
</body>

</html>
0 голосов
/ 11 июля 2020

Просто вставьте тег изображения тура внутри тега привязки, например: Текст

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...