0

Необходимо при наведении на картинку сделать выдвигающийся флажок. Обычная версия флажка у меня есть, но как сделать так, чтобы при наведении он выдвигался?
Скрин без :hover эффекта: Обычный флажок

Скрин с :hover эффектом: Флажок при наведении на картинку

Код самого флажка:

.thblock {
  display: inline-flex;
  justify-content: space-between;
  align-items: center;
  margin: 50px 0;
  width: 1200px;
  height: 270px;
}
.thblock .im1,
.thblock .im2,
.thblock .im3,
.thblock .im4 {
  widtH: 270px;
  height: 270px;
  position: relative;
}
.thblock .im1 {
  background-image: url(https://static.pexels.com/photos/46871/pexels-photo-46871-large.jpeg);
}
.thblock .im2 {
  background-image: url(https://static.pexels.com/photos/60163/pexels-photo-60163-large.jpeg);
}
.thblock .im3 {
  background-image: url(https://static.pexels.com/photos/1539/vintage-technology-music-old-large.jpg);
}
.thblock .im4 {
  background-image: url(https://static.pexels.com/photos/36092/pexels-photo-large.jpg);
}
.thblock .im1,
.thblock .im2,
.thblock .im3,
.thblock .im4 {
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}
.thblock .mi1 {
  position: absolute;
  bottom: 15px;
  right: 0;
  width: 60px;
  height: 90px;
  overflow: hidden;
}
.thblock .mi1:before,
.thblock .mi1:after {
  content: '';
  position: absolute;
  right: -25px;
  background: #c95757;
  width: 60px;
  height: 65px;
  -webkit-transition: 0.3s;
  transition: 0.3s;
}
.thblock .mi1:before {
  top: 0;
  -webkit-transform: skew(35deg);
  transform: skew(35deg);
}
.thblock .mi1:after {
  bottom: 0;
  -webkit-transform: skew(-35deg);
  transform: skew(-35deg);
}
.thblock .mi1 > span {} .thblock .mi1 > span:before,
.thblock .mi1 > span:after {
  content: '';
  position: absolute;
  right: -11px;
  width: 100%;
  height: 4px;
  background: #ffffcc;
  z-index: 1;
}
.thblock .mi1 > span:before {
  top: 10px;
  -webkit-transform: skew(35deg);
  transform: skew(35deg);
}
.thblock .mi1 > span:after {
  bottom: 10px;
  -webkit-transform: skew(-35deg);
  transform: skew(-35deg);
}
/* Добавил анимацию флажка */

.thblock .mi1:hover,
.thblock .mi1:hover:after,
.thblock .mi1:hover:before {
  width: 240px;
  z-index: 0;
}
<section class="thblock">
  <div class="im1">
    <div class="mi1"><span></span>
    </div>
  </div>

  <div class="im2">
    <div class="mi1"><span></span>
    </div>
  </div>

  <div class="im3">
    <div class="mi1"><span></span>
    </div>
  </div>

  <div class="im4">
    <div class="mi1"><span></span>
    </div>
  </div>
</section>

3 ответа 3

3

.thblock {
  display: inline-flex;
  justify-content: space-between;
  align-items: center;
  margin: 50px 0;
  width: 1200px;
  height: 270px;
}
.thblock .im1,
.thblock .im2,
.thblock .im3,
.thblock .im4 {
  widtH: 270px;
  height: 270px;
  position: relative;
}
.thblock .im1 {
  background-image: url(https://static.pexels.com/photos/46871/pexels-photo-46871-large.jpeg);
}
.thblock .im2 {
  background-image: url(https://static.pexels.com/photos/60163/pexels-photo-60163-large.jpeg);
}
.thblock .im3 {
  background-image: url(https://static.pexels.com/photos/1539/vintage-technology-music-old-large.jpg);
}
.thblock .im4 {
  background-image: url(https://static.pexels.com/photos/36092/pexels-photo-large.jpg);
}
.thblock .im1,
.thblock .im2,
.thblock .im3,
.thblock .im4 {
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}
.thblock .mi1 {
  position: absolute;
  bottom: 15px;
  right: 0;
  width: 60px;
  height: 90px;
  overflow: hidden;
  transition: 0.3s
}
.thblock .mi1:before,
.thblock .mi1:after {
  content: '';
  position: absolute;
  right: -25px;
  background: #c95757;
  width: 60px;
  height: 65px;
  -webkit-transition: 0.3s;
  transition: 0.3s;
}
.thblock .mi1:before {
  top: 0;
  -webkit-transform: skew(35deg);
  transform: skew(35deg);
}
.thblock .mi1:after {
  bottom: 0;
  -webkit-transform: skew(-35deg);
  transform: skew(-35deg);
}
.thblock .mi1 > span {} .thblock .mi1 > span:before,
.thblock .mi1 > span:after {
  content: '';
  position: absolute;
  right: -11px;
  width: 100%;
  height: 4px;
  background: #ffffcc;
  z-index: 1;
}
.thblock .mi1 > span:before {
  top: 10px;
  -webkit-transform: skew(35deg);
  transform: skew(35deg);
}
.thblock .mi1 > span:after {
  bottom: 10px;
  -webkit-transform: skew(-35deg);
  transform: skew(-35deg);
}
.thblock .mi1 h3 {
  display: none;
  transition: 0.3s;
}
.thblock .mi1:hover,
.thblock .mi1:hover:after,
.thblock .mi1:hover:before {
  width: 240px;
  position: absolute;
}
.thblock .mi1:hover h3 {
  display: block;
  overflow: visible;
  padding: 20px 0 0 80px;
  position: relative;
  z-index: 100;
}
<section class="thblock">
  <div class="im1">
    <div class="mi1">
      <h3>Retrospective</h3><span></span>
    </div>
  </div>
  <div class="im2">
    <div class="mi1">
      <h3>Retrospective</h3><span></span>
    </div>
  </div>
  <div class="im3">
    <div class="mi1">
      <h3>Retrospective</h3><span></span>
    </div>
  </div>
  <div class="im4">
    <div class="mi1">
      <h3>Retrospective</h3><span></span>
    </div>
  </div>
</section>

2
.flag {
   position:absolute;
   right:-100px;  /* прячем флаг */
   transition: all 200ms ease; /* добавляем плавность */
}
.flag:hover {
   right:0; /* выдвигаем флаг */
}
2
  • проблема состоит в том, что я не знаю, как вывести какой-либо текст на флажок, т.к. он во всех случаях появляется под флажком, а не на нём 21 мая 2016 в 17:24
  • @TylerManing .thblock .mi1::before, .thblock .mi1::after - z-index: -1 21 мая 2016 в 17:35
0

* {
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  background: #303030;
}

#wrapperflag {
  overflow: hidden;
  position: relative;
  width: 300px;
  height: 180px;
  background-image: url(http://livefomdet.ru/uploads/images/f/o/t/foto_krasivih_jaguarov.jpg);
  background-size: cover;
}

#flag {
  position: absolute;
  bottom: 0;
  right: -150px;
  width: 200px;
  height: 50px;
  background: #5a0808;
  text-align: center;
  line-height: 1.6;
  font-family: sans-serif;
  font-size: 30px;
  color: white;
  clip-path: polygon(50% 0%, 0% 0%, 10% 50%, 0% 100%, 0% 100%, 50% 100%, 100% 100%, 100% 100%, 100% 58%, 100% 0%);
  transition: right .3s;
}

#wrapperflag:hover #flag {
  right: 0;
  transition: right .3s;
}
<div id="wrapperflag">
  <div id="flag">

    it`s flag
  </div>
</div>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.