Как получить круглое меню (включая функцию наведения + ссылки) полностью адаптивным? - PullRequest
0 голосов
/ 29 сентября 2019

Я пытаюсь заставить круглое меню (включая функцию наведения + ссылки) вести себя полностью ответственный .

  • Часть с зависанием и связыванием в основном работает нормально.
  • Без парящей части, круглое меню ведет себя отзывчиво.
  • Но с включенной парящей частью меню сжимается при регулировке ширины экрана / дисплея.

Я пробовал подход @media, устанавливая разные значения ширины и высоты в .ch-grid li для разной ширины экрана, но это не следует рассматривать как истинное решение, это просто временное решение.

ul,
li {
  list-style: none;
  margin: 0;
  padding: 0;
}

#test1 {
  display: -webkit-flex;
  display: flex;
  text-align: center;
  justify-content: space-between;
  margin-bottom: 30px;
  margin-left: 35px;
  margin-right: 35px;
}

#test2 {
  width: 15%;
  text-align: center;
  position: relative;
  border-radius: 50%;
  overflow: hidden;
  background-color: #ff0082;
}

ul li img {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  object-fit: cover;
}

.ch-grid:after,
.ch-item:before {
  content: '';
  display: table;
}

.ch-grid:after {
  clear: both;
}

.ch-grid li {
  width: 220px;
  height: 90px;
  display: inline-block;
}

.ch-item {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  cursor: default;
  box-shadow: inset 0 0 0 16px rgba(255, 255, 255, 0.6), 0 1px 2px rgba(0, 0, 0, 0.1);
  transition: all 0.4s ease-in-out;
}

.ch-info {
  position: absolute;
  background: rgba(63, 147, 147, 0.8);
  width: inherit;
  height: inherit;
  border-radius: 50%;
  overflow: hidden;
  opacity: 0;
  transition: all 0.4s ease-in-out;
  transform: scale(0);
}

.ch-info p {
  color: #fff;
  padding: 13px 0px;
  font-style: normal;
  font-size: 9px;
  border-top: 1px solid rgba(255, 255, 255, 0.5);
  opacity: 0;
  transition: all 1s ease-in-out 0.4s;
}

.ch-info p a {
  display: block;
  color: rgba(255, 255, 255, 0.7);
  font-style: normal;
  font-weight: 700;
  font-size: 140%;
  letter-spacing: 1px;
  padding-top: 4px;
  font-family: 'Open Sans', Arial, sans-serif;
}

.ch-info p a:hover {
  color: rgba(255, 242, 34, 0.8);
}

.ch-item:hover {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 1px 2px rgba(0, 0, 0, 0.1);
}

.ch-item:hover .ch-info {
  transform: scale(1);
  opacity: 1;
}

.ch-item:hover .ch-info p {
  opacity: 1;
}
<ul id="test1" class="ch-grid">
  <li id="test2">
    <div class="ch-item">
      <img src="https://gespreksmakers.nl/images/1_hansie_hansumus.jpg" />
      <div class="ch-info">
        <p><a href="https://nkbv.nl">Hansie<BR>Hansumus</a></p>
      </div>
    </div>
  </li>
  <li id="test2">
    <div class="ch-item">
      <img src="https://gespreksmakers.nl/images/1_missie_marble.jpg" />
      <div class="ch-info">
        <p><a href="https://kakivi.de">Missie<BR>Marble</a></p>
      </div>
    </div>
  </li>
  <li id="test2">
    <div class="ch-item">
      <img src="https://gespreksmakers.nl/images/1_piotr_linski.jpg" />
      <div class="ch-info">
        <p><a href="https://telegraaf.nl">Piotr<BR>Linski</a></p>
      </div>
    </div>
  </li>
  <li id="test2">
    <div class="ch-item">
      <img src="https://gespreksmakers.nl/images/1_red.jpg" />
      <div class="ch-info">
        <p><a href="https://www.tukhut.nl">Mister<BR>Red</a></p>
      </div>
    </div>
  </li>
  <li id="test2">
    <div class="ch-item">
      <img src="https://gespreksmakers.nl/images/1_green.jpg" />
      <div class="ch-info">
        <p><a href="https://www.alumnei.nl">Miss<BR>Green</a></p>
      </div>
    </div>
  </li>
  <li id="test2">
    <div class="ch-item">
      <img src="https://gespreksmakers.nl/images/1_blue.jpg" />
      <div class="ch-info">
        <p><a href="https://www.astronieuws.nl">Mister<BR>Blue</a></p>
      </div>
    </div>
  </li>
</ul>

С скрипкой, показывающей настоящий CSS- и HTML-код, можно ознакомиться здесь: https://jsfiddle.net/piotrlinski/b3tL9v4h/8/

Есть предложения, как решить?

Ответы [ 3 ]

1 голос
/ 29 сентября 2019

Вы можете проверить мой код ниже, хотя я внес несколько изменений.

Некоторые советы:

Идентификаторы должны быть уникальными в документе HTML, поэтомуВы не должны использовать идентификатор более одного раза (например, # test2).

Кроме того, лучше использовать классы, созданные вами для оформления документа, а не идентификаторы (например, # test1, # test2 может бытьзаменены на .ch-grid и .ch-grid li соответственно).

<style>
  ul,
  li {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .ch-grid {
    display: -webkit-flex;
    display: flex;
    flex-wrap: wrap;
    text-align: center;
  }
  .ch-grid:after,
  .ch-item:before {
    content: "";
    display: table;
  }

  .ch-grid:after {
    clear: both;
    flex: auto;
  }
  .ch-grid li {
    flex: 1;
    display: inline-block;
    min-width: calc(100% / 6);
    max-width: calc(100% / 6);
    position: relative;
    background-color: #ff0082;
    overflow: hidden;
    border-radius: 50%;
    text-align: center;
  }
  .ch-grid li img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: relative;
    z-index: 10;
  }
  .ch-item {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    cursor: default;
    box-shadow: inset 0 0 0 16px rgba(255, 255, 255, 0.6),
      0 1px 2px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease-in-out;
  }
  .ch-info {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: -webkit-flex;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: rgba(63, 147, 147, 0.8);
    border-radius: 50%;
    overflow: hidden;
    opacity: 0;
    transition: all 0.4s ease-in-out;
    transform: scale(0);
    z-index: 20;
  }
  .ch-info p {
    color: #fff;
    padding: 13px 0px;
    font-style: normal;
    font-size: 9px;
    border-top: 1px solid rgba(255, 255, 255, 0.5);
    opacity: 0;
    transition: all 1s ease-in-out 0.4s;
  }
  .ch-info p a {
    display: block;
    color: rgba(255, 255, 255, 0.7);
    font-style: normal;
    font-weight: 700;
    font-size: 140%;
    letter-spacing: 1px;
    padding-top: 4px;
    font-family: "Open Sans", Arial, sans-serif;
  }
  .ch-info p a:hover {
    color: rgba(255, 242, 34, 0.8);
  }
  .ch-item:hover {
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1),
      0 1px 2px rgba(0, 0, 0, 0.1);
  }
  .ch-item:hover .ch-info {
    transform: scale(1);
    opacity: 1;
  }
  .ch-item:hover .ch-info p {
    opacity: 1;
  }
  @media (max-width: 767px) {
    .ch-grid li {
      min-width: calc(100% / 3);
      max-width: calc(100% / 3);
    }
  }
</style>
1 голос
/ 29 сентября 2019

Атрибут class может использоваться с несколькими HTML-элементами / тегами, и все будут иметь эффект.Где в качестве идентификатора предназначен для одного элемента / тега и считается уникальным.Более того, идентификатор имеет более высокое значение специфичности, чем класс.

Адаптивное изображение:

.img-responsive {
  display: block;
  max-width: 100%;
  height: auto;
}

Неупорядоченный список:

<ul class="thumbnails">
  <li>Thumbnail 1</li>
  <li>Thumbnail 2</li>
  <li>...</li>
</ul>

Список без стиля в одномстрока с display: flex:

.thumbnails {
  display: flex;
  list-style: none;
  ...
}

Структура миниатюры

<a href="https://nkbv.nl" class="thumbnail">
  <img src = "https://gespreksmakers.nl/images/1_hansie_hansumus.jpg"/>
  <div class="overlay">
    <p class="text">Mister White</p>
  </div>
</a>

, где .thumbnail имеет position: relative, а .overlay имеет position: absolute, так что .overlay являетсяв той же области , что и .thumbnail.

Приведите размер шрифта в соответствие с vw.

Модифицированное и понятное решение

.thumbnails {
  display: flex;
  list-style: none;
  padding: 0 2vw;
}

.thumbnails>li {
  flex: 1 0;
  margin: 0 5px;
  text-align: center;
  line-height: 0;
}

.thumbnail,
.thumbnail>img,
.thumbnail>.overlay {
  border-radius: 50%;
}

.thumbnail {
  position: relative;
  display: inline-block;
  cursor: pointer;
}


/* Responsive images */

.thumbnail>img {
  display: block;
  max-width: 100%;
  height: auto;
}

.thumbnail>.overlay {
  background: rgba(63, 147, 147, 0.8);
  opacity: 0.7;
  position: absolute;
  top: 0;
  height: 100%;
  width: 100%;
  transform: scale(0);
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  transition: all 0.4s ease-in-out;
}

.thumbnail>.overlay>.text {
  color: white;
  width: 66.66%;
  line-height: 100%;
  margin: 0 auto;
  padding: 5px 0;
  border-bottom: 1px solid;
  border-top: 1px solid;
  font-size: 1.85vw;
  transition: opacity 1s ease-in-out 0.4s;
  opacity: 0;
}

.thumbnail:hover>.overlay {
  transform: scale(1);
}

.thumbnail:hover>.overlay>.text {
  opacity: 1;
}
<ul class="thumbnails">
  <li>
    <a href="https://nkbv.nl" class="thumbnail">
      <img src="https://gespreksmakers.nl/images/1_hansie_hansumus.jpg" />
      <div class="overlay">
        <p class="text">Mister White</p>
      </div>
    </a>
  </li>
  <li>
    <a href="https://kakivi.de" class="thumbnail">
      <img src="https://gespreksmakers.nl/images/1_missie_marble.jpg" />
      <div class="overlay">
        <p class="text">Mister White</p>
      </div>
    </a>
  </li>
  <li>
    <a href="https://telegraaf.nl" class="thumbnail">
      <img src="https://gespreksmakers.nl/images/1_piotr_linski.jpg" />
      <div class="overlay">
        <p class="text">Mister White</p>
      </div>
    </a>
  </li>
  <li>
    <a href="https://www.tukhut.nl" class="thumbnail">
      <img src="https://gespreksmakers.nl/images/1_red.jpg" />
      <div class="overlay">
        <p class="text">Mister White</p>
      </div>
    </a>
  </li>
  <li>
    <a href="https://www.alumnei.nl" class="thumbnail">
      <img src="https://gespreksmakers.nl/images/1_green.jpg" />
      <div class="overlay">
        <p class="text">Mister White</p>
      </div>
    </a>
  </li>
  <li>
    <a href="https://www.astronieuws.nl" class="thumbnail">
      <img src="https://gespreksmakers.nl/images/1_blue.jpg" />
      <div class="overlay">
        <p class="text">Mister White</p>
      </div>
    </a>
  </li>
</ul>
0 голосов
/ 29 сентября 2019

Если вы установите ширину в процентах, элементы списка не будут отображаться в виде круга в зависимости от ширины экрана.Из-за этой ситуации вы должны установить фиксированную ширину для элементов списка и установить wrap для parent, как показано ниже:

#test1 {
    display: -webkit-flex;
    display: flex;
    text-align: center;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 30px;
    margin-left: 35px;
    margin-right: 35px;
}

#test2 {
    flex-basis: 85px;
    text-align: center;
    position: relative;
    border-radius: 50%;
    overflow: hidden;
    background-color: #ff0082;
}
...