0

Пытаюсь сделать заголовок с двумя линиями с боку, все вроде нормально, но на медиазапросах, мне нужно линии переопределить, чтоб они находились по другому, position почему-то не отменяется

h2 {
  text-align: center;
  position: relative;
  text-transform: uppercase;
  overflow: hidden;
}

h2::before {
  content: "";
  width: 170px;
  height: 2px;
  background: #fff;
  position: absolute;
  top: 50%;
  margin-left: -200px;
}

h2::after {
  content: "";
  width: 170px;
  height: 2px;
  background: #fff;
  position: absolute;
  top: 50%;
  margin-left: 30px;
}

@media screen and (max-width: 700px) {
  h2 {
    overflow: visible;
  }
  h2::before {
    width: 350px;
    top: -8px;
    left: 50%;
    margin-left: -175px;
  }
  h2::after {
    width: 350px;
    bottom: -8px;
    left: 50%;
    margin-left: -175px;
  }
}
<h2>Lorem ipsum dolor sit</h2>

2 ответа 2

1

Вам нужно переопределить свойство position переписав его свойство например на unset или relative. Если вы просто не пропишите его в медиазапросе - оно останется прежним.

1

h2 {
  text-align: center;
  position: relative;
  text-transform: uppercase;
  overflow: hidden;
}

h2::before {
  content: "";
  width: 170px;
  height: 2px;
  background: black;
  position: absolute;
  top: 50%;
  margin-left: -200px;
}

h2::after {
  content: "";
  width: 170px;
  height: 2px;
  background: black;
  position: absolute;
  top: 50%;
  margin-left: 30px;
}

@media screen and (min-width: 320px) and (max-width: 768px) {
  h2 {
    overflow: visible;
  }
  h2::before {
    width: 350px;
    bottom: -8px;
    left: 50%;
    margin-left: -175px;
    top: -8px;
    position: absolute;
  }
  h2::after {
    width: 350px;
    bottom: -8px;
    left: 50%;
    top: auto;
    margin-left: -175px;
    position: absolute;
  }
}
<h2>Lorem ipsum dolor sit</h2>

1

Ваш ответ

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

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