Переключатель jQuery перемещает нижний элемент

У меня есть блоки с некоторым содержимым, но не весь текст отображается. При щелчке я переключаю весь текст, но проблема в том, что я не хочу, чтобы нижний элемент перемещался, вместо этого я хочу, чтобы переключаемый div находился поверх нижнего элемента. Кто-нибудь поможет с идеями, как это сделать? Спасибо.

Пс. Также по какой-то причине не работает переход/анимация.

Вот ссылка на codepen: https://codepen.io/christmastrex/pen/gOwGvap и вот мой код:

<div class = "card">
  <div class = "card__header js-toggle">
    <p class = "card__title">“It’s not about weight it’s about how<br> your body changes”</p>
  </div>
  <div class = "card__toggle">
    <p>Doing resistance training and cardio combined and I have not lost one single ounce on the scale….I was feeling horribly frustrated being it has been a month so I decided to do a progress sequence and wth look at me now!! It’s not about weight, it’s about how your body changes when you eat right and exercise! Yay!!”</p>
   </div>
 </div>
  
<div class = "card">
  <div class = "card__header js-toggle">
    <p class = "card__title">“It’s not about weight it’s about how<br> your body changes”</p>
  </div>
  <div class = "card__toggle">
   <p>Doing resistance training and cardio combined and I have not lost one single ounce on the scale….I was feeling horribly frustrated being it has been a month so I decided to do a progress sequence and wth look at me now!! It’s not about weight, it’s about how your body changes when you eat right and exercise! Yay!!”</p>
  </div>
</div>
------------------------------------------------------------
 .card {
      background-color: #fff;
      max-width: 490px;        
    padding: 20px;
    margin-bottom: 30px;
    border-radius: 5px;        
    position: relative;
    box-sizing: border-box;
    box-shadow: 0 3px 30px 0 rgba(74,74,74,.3);

    &__toggle {        
        overflow: hidden;
        max-height: 55px;

        p {
            font-size: 16px;
            margin-bottom: 10px;
        }
    }

    &__title { 
        font-weight: 900;
        margin-bottom: 5px;
    }   

    &__header {
        position: relative;
        cursor: pointer;

        &::after{
            content: "\f078";
            font-family: "Font Awesome 5 Pro";         
            font-weight: 400;
            display: inline-block;
            background-color: #d54f80;
            border: 2px solid #d54f80;
            color: #fff;
            width: 30px;
            height: 30px;
            border-radius: 15px;
            font-size: 14px;
            text-align: center;
            line-height: 2;
            position: absolute;
            top: 0;         
            right: 0;
            transition: all .3s ease-in-out;
        }        

    }

    &.active {

        .card__toggle {
            max-height: 700px;
            transition: all .3s ease-in-out;
        }
        
        .card__header {            

            &::after { 
                background-color: #fff;
                color: red;
                transform: rotate(180deg);
            }
        }
    }
}

-----------------------------------------------------
   $(document).ready(function() {  
     $(".js-toggle").on("click", function () {
        $(".card__header.active").not($(this)).removeClass("active").next(".js-card-toggle").slideUp("slow");
        $(this).toggleClass("active").next(".js-card-toggle").slideToggle("slow");
        $(this).closest(".card").toggleClass("active").siblings().removeClass("active");
    });
                                 
});```

привет, возможно, использовать гибкий пояс?

IronMan 24.12.2020 19:48

@IronMan, что именно ты имеешь в виду? На самом деле на моей исходной странице поля отображаются с гибкими строками и столбцами, но все равно происходит то же самое.

Elka 24.12.2020 20:01

Примите мой ответ, если он поможет :)

Tayyab Ferozi 24.12.2020 21:52
Улучшение производительности загрузки с помощью Google Tag Manager и атрибута Defer
Улучшение производительности загрузки с помощью Google Tag Manager и атрибута Defer
В настоящее время производительность загрузки веб-сайта имеет решающее значение не только для удобства пользователей, но и для ранжирования в...
Введение в CSS
Введение в CSS
CSS является неотъемлемой частью трех основных составляющих front-end веб-разработки.
Как выровнять Div по центру?
Как выровнять Div по центру?
Чтобы выровнять элемент <div>по горизонтали и вертикали с помощью CSS, можно использовать комбинацию свойств и значений CSS. Вот несколько методов,...
Навигация по приложениям React: Исчерпывающее руководство по React Router
Навигация по приложениям React: Исчерпывающее руководство по React Router
React Router стала незаменимой библиотекой для создания одностраничных приложений с навигацией в React. В этой статье блога мы подробно рассмотрим...
Система управления парковками с использованием HTML, CSS и JavaScript
Система управления парковками с использованием HTML, CSS и JavaScript
Веб-сайт по управлению парковками был создан с использованием HTML, CSS и JavaScript. Это простой сайт, ничего вычурного. Основная цель -...
Toor - Ангулярный шаблон для бронирования путешествий
Toor - Ангулярный шаблон для бронирования путешествий
Toor - Travel Booking Angular Template один из лучших Travel & Tour booking template in the world. 30+ валидированных HTML5 страниц, которые помогут...
1
3
241
2
Перейти к ответу Данный вопрос помечен как решенный

Ответы 2

Я думаю, вы пытаетесь добиться этого, скопируйте его и посмотрите, работает ли он.

HTML:

<div class = "card">
  <div class = "card__header js-toggle">
    <p class = "card__title">
      “It’s not about weight it’s about how<br />
      your body changes”
    </p>
  </div>
  <div class = "card__toggle">
    <p>
      Doing resistance training and cardio combined and I have not lost one
      single ounce on the scale….I was feeling horribly frustrated being it has
      been a month so I decided to do a progress sequence and wth look at me
      now!! It’s not about weight, it’s about how your body changes when you eat
      right and exercise! Yay!!”
    </p>
  </div>
</div>

<div class = "card">
  <div class = "card__header js-toggle">
    <p class = "card__title">
      “It’s not about weight it’s about how<br />
      your body changes”
    </p>
  </div>
  <div class = "card__toggle">
    Doing resistance training and cardio combined and I have not lost one single
    ounce on the scale….I was feeling horribly frustrated being it has been a
    month so I decided to do a progress sequence and wth look at me now!! It’s
    not about weight, it’s about how your body changes when you eat right and
    exercise! Yay!!”
  </div>
</div>

СКСС: .

card {
    max-height: 125px;
    overflow: hidden;
    background-color: #fff;
    max-width: 490px;
    padding: 20px;
    margin-bottom: 30px;
    border-radius: 5px;
    position: relative;
    height: 150px;
    box-sizing: border-box;
    box-shadow: 0 3px 30px 0 rgba(74, 74, 74, 0.3);
    transition: 0.4s ease;

    &.active {
      max-height: 210px;
    }

    &__toggle {
      background-color: white;

      p {
        font-size: 16px;
        margin-bottom: 10px;
      }
    }

    &__title {
      font-weight: 900;
      margin-bottom: 5px;
    }

    &__header {
      position: relative;
      cursor: pointer;

      &::after {
        content: "\f078";
        font-family: "Font Awesome 5 Pro";
        font-weight: 400;
        display: inline-block;
        background-color: #d54f80;
        border: 2px solid #d54f80;
        color: #fff;
        width: 30px;
        height: 30px;
        border-radius: 15px;
        font-size: 14px;
        text-align: center;
        line-height: 2;
        position: absolute;
        top: 0;
        right: 0;
        transition: all 0.3s ease-in-out;
      }
    }

    &.active {
      .card__toggle {
        transition: all 0.3s ease-in-out;
        width: 100%;
        z-index: 1;
        background-color: white;
      }

      .card__header {
        &::after {
          background-color: #fff;
          color: red;
          transform: rotate(180deg);
        }
      }
    }
  }

jQuery:

  $(".js-toggle").click(function () {
    console.info($(this).parents(".card"));
    $(this).parents(".card").toggleClass("active");
  });

Спасибо, но это точно так же, как у меня. Может быть, я не ясно, что мне нужно. Я хочу добиться этого prnt.sc/w9mwl8 , а не этого prnt.sc/w9mwys

Elka 25.12.2020 10:35

о, извините, под bottom element вы имели в виду следующий элемент карты, я не совсем понял :'(..... Я только что увидел, что вы его достигли

Tayyab Ferozi 25.12.2020 19:50
Ответ принят как подходящий

В конце концов, мне удалось найти решение. Я внес изменения только в css

  background-color: #fff;
  max-width: 490px;
  padding: 20px;
  margin: 0 auto 70px auto;
  border-radius: 5px;
  position: relative;
  box-sizing: border-box;
  box-shadow: 0 3px 30px 0 rgba(74, 74, 74, 0.3);

  &::after {
    content: "";
    position: absolute;
    height: 20px;
    background-color: #fff;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    bottom: -40px;
    left: 0;
    z-index: 10;
    width: 100%;
    box-shadow: 0 10px 20px -7px rgba(74, 74, 74, 0.3); 
    transition: all 0.3s ease-in-out;
    transition-delay: 0.5s;
  }

  &__toggle {
    overflow: hidden;
    max-height: 45px;
    position: absolute;
    z-index: 1;
    background-color: #fff;
    margin-left: -20px;
    padding-left: 20px;
    padding-right: 20px;
    border-radius: 5px;
    box-shadow: 0 10px 15px -12px rgba(74, 74, 74, 0.3);
    transition: all 1s ease-in-out;

    p {
      font-size: 16px;
      margin-bottom: 20px;
      line-height: 1.3;
    }

    &-s {
      max-height: 18px;
    }
  }

  &--s {
    max-width: 350px;
  }

  &__img {
    border: 5px solid #d54f80;
    border-radius: 5px;
    padding: 5px 5px 1px 5px;
    margin-bottom: 20px;
  }

  &__title {
    font-weight: 900;
    margin-bottom: 5px;
  }

  &__header {
    position: relative;
    cursor: pointer;

    &::after {
      content: "\f078";
      font-family: "Font Awesome 5 Pro";
      font-weight: 400;
      display: inline-block;
      background-color: #d54f80;
      border: 2px solid #d54f80;
      color: #fff;
      width: 30px;
      height: 30px;
      border-radius: 15px;
      font-size: 14px;
      text-align: center;
      line-height: 2;
      position: absolute;
      top: 0;
      right: 0;
      transition: all 0.3s ease-in-out;
    }
  }

  &.active {
    &.card::after {
      background-color: transparent;
      transition: all 0s ease-in-out;
    }

    .card__toggle {
      max-height: 700px;
    }

    .card__header {
      &::after {
        background-color: #fff;
        color: pink;
        transform: rotate(180deg);
      }
    }
  }
}

Другие вопросы по теме