как можно сделать стиль overflow: hidden для body когда открывается popup?
.popup {
position: fixed;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
top: 0;
left: 0;
opacity: 0;
visibility: hidden;
overflow-y: auto;
overflow-x: hidden;
transition: all 0.8s ease 0s;
z-index: 1;
}
.popup__area {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.popup__body {
display: flex;
justify-content: space-between;
align-items: center;
justify-content: center;
transition: all 0.8s ease 0s;
}
@media only screen and (max-width: 767.98px) {
.popup__body {
flex-direction: column-reverse;
}
}
.popup__content {
display: flex;
justify-content: space-between;
align-items: center;
justify-content: flex-start;
background-color: #FFF;
color: #000;
max-width: 50%;
width: 100%;
height: 100vh;
padding: 4rem;
position: relative;
transition: all 0.3s ease 0s;
}
@media only screen and (max-width: 767.98px) {
.popup__content {
max-width: 100%;
height: auto;
}
}
.popup__close {
position: absolute;
right: 12.8rem;
top: 8rem;
background: url(../icons/close.svg) center center/contain no-repeat;
width: 3.2rem;
height: 3.2rem;
text-decoration: none;
z-index: 1;
}
@media only screen and (max-width: 991.98px) {
.popup__close {
right: 1.5rem;
top: 1.5rem;
}
}
.popup__img {
max-width: 50%;
width: 100%;
height: 100vh;
}
@media only screen and (max-width: 767.98px) {
.popup__img {
max-width: 100%;
height: auto;
}
}
@media only screen and (max-height: 479.98px) {
.popup__img {
zoom: 142%;
}
}
.popup__text {
width: 100%;
margin: 0 auto;
}
.popup__text h3 {
color: #000;
font-size: 5.6rem;
font-weight: 600;
line-height: 1.4;
letter-spacing: -0.112rem;
max-width: 51.4rem;
width: 100%;
margin-bottom: 1.6rem;
}
@media only screen and (max-width: 767.98px) {
.popup__text h3 {
text-align: center;
margin-left: auto;
margin-right: auto;
}
}
@media only screen and (max-width: 479.98px) {
.popup__text h3 {
font-size: 3.6rem;
}
}
@media only screen and (max-width: 320px) {
.popup__text h3 {
font-size: 2.6rem;
}
}
.popup__text>p {
color: #333;
font-size: 1.8rem;
line-height: 1.8;
letter-spacing: -0.036rem;
margin-bottom: 3.2rem;
}
@media only screen and (max-width: 767.98px) {
.popup__text>p {
text-align: center;
}
}
.popup__form {
max-width: 55.4rem;
width: 100%;
}
@media only screen and (max-width: 767.98px) {
.popup__form {
margin: 0 auto;
}
}
.popup__form input,
.popup__form label {
display: block;
line-height: 1.6;
letter-spacing: -0.032rem;
padding: 1.2rem 1.6rem 1rem;
}
.popup__form input {
width: 100%;
color: #333;
border-bottom: 0.1rem solid #333;
}
.popup__form input:focus-visible,
.popup__form input:focus {
border-bottom: 0.1rem solid #1F4D38;
}
.popup__form label {
color: #808080;
}
.popup__form>input:not:first-child {
margin-top: 3.2rem;
}
.popup__form button {
color: #FFF;
font-size: 1.4rem;
line-height: 1;
max-width: 18rem;
width: 100%;
}
.popup__inputs {
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
margin-top: 3.2rem !important;
}
@media only screen and (max-width: 479.98px) {
.popup__inputs {
flex-direction: column;
}
}
.popup__checkbox {
display: flex;
justify-content: space-between;
align-items: center;
gap: 1.5rem;
margin-top: 3.2rem;
}
@media only screen and (max-width: 479.98px) {
.popup__checkbox {
flex-direction: column;
}
}
.popup__checkbox a {
color: #000;
font-weight: 600;
line-height: 1.2;
text-decoration-line: underline;
transition: all 0.3s ease 0s;
}
.popup__checkbox a:hover {
opacity: 0.7;
}
.popup__checkbox a:active {
opacity: 1;
}
.popup__btn {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
justify-content: flex-end;
align-items: stretch;
margin-top: 8.9rem;
gap: 1.2rem;
}
@media only screen and (max-width: 479.98px) {
.popup__btn {
margin-top: 4rem;
flex-direction: column;
}
}
.popup__btn button {
align-self: normal;
}
@media only screen and (max-width: 479.98px) {
.popup__btn button {
max-width: 100%;
}
}
.popup__form-consult>div+div {
margin-top: 3.1rem;
}
.popup__form-consult a {
max-width: 18rem;
width: 100%;
}
@media only screen and (max-width: 479.98px) {
.popup__form-consult a {
max-width: 100%;
height: 4.4rem;
}
}
.popup__form-consult-btn {
margin-top: 7rem !important;
}
.input-wrapper {
margin-top: 0;
overflow: hidden;
position: relative;
width: 100%;
}
.input-wrapper label {
position: absolute;
transition: all 0.2s ease;
bottom: 0;
pointer-events: none;
white-space: nowrap;
max-width: 100%;
overflow: hidden;
}
.input-wrapper select {
width: 100%;
}
.input-wrapper input:not(:placeholder-shown)+label,
.input-wrapper input:focus+label {
bottom: 2rem;
font-size: 1.2rem;
}
.popup:target {
opacity: 1;
z-index: 100;
visibility: visible;
}
<ul class="header__links links">
<li>
<a href="#popup__consult" class="text-1">For Providers</a>
<div class="decor-line"></div>
</li>
</ul>
<div id="popup__consult" class="popup">
<a href="#!" class="popup__area"></a>
<div class="popup__body justify-content-flex-end">
<a href="#close__popup" class="popup__close close-2"></a>
<div class="popup__content w-5 h-1">
<div class="popup__text w-7">
<h3 class="popup__title w-6">Request Consultation</h3>
<p>Answer a few questions so the provider can get in touch</p>
<form class="popup__form popup__form-consult w-7" action="#!">
<div class="popup__inputs">
<div class="input-wrapper">
<input type="text" id="name" required placeholder="" autocomplete="off">
<label for="name">First Name</label>
</div>
<div class="input-wrapper">
<input type="text" id="last" required placeholder="">
<label for="last">Last Name</label>
</div>
</div>
<div class="popup__inputs">
<div class="input-wrapper">
<input type="email" id="email" required placeholder="" autocomplete="off">
<label for="email">Email</label>
</div>
<div class="input-wrapper w-8">
<input type="text" id="phone" name="phone" required placeholder="" autocomplete="off">
<label for="phone">Phone Number</label>
</div>
</div>
<div class="choice">
<p>Payment type</p>
<div class="checkbox radio">
<label>
<input type="radio" checked name="coding-notes" class="checkbox__real">
<span class="checkbox__custom checkbox__custom_1">Insurance</span>
</label>
</div>
<div class="checkbox radio radio_2">
<label>
<input type="radio" name="coding-notes" class="checkbox__real">
<span class="checkbox__custom">Out of Pocket</span>
</label>
</div>
</div>
<div class="popup__inputs">
<div class="input-wrapper">
<input type="text" id="code" placeholder="">
<label for="code">City or ZIP code</label>
</div>
<div class="select" tabindex="1">
<div class="custom-select">
<select id="select-2">
<option value="0">Virtual or In-person</option>
<option value="1">Virtual</option>
<option value="2">In-person</option>
</select>
</div>
</div>
</div>
<div class="popup__inputs flex-direction-column">
<div class="input-wrapper">
<input type="text" id="subject" placeholder="">
<label for="subject">Subject</label>
</div>
<input type="text" required placeholder="What brings you here?" name="info">
</div>
<div class="popup__btn popup__form-consult-btn">
<a href="#close__popup" class="btn btn-4">Cancel</a>
<button type="submit" class="btn btn-3">
Submit
<span class="decor-ball-arrow color-3"><img class="arrow-white"
src="icons/arrow-white.svg" alt="arrow-white"></span>
</button>
</div>
</form>
</div>
</div>
</div>
</div>
Ответы (1 шт):
Автор решения: Михаил Камахин
→ Ссылка
Можно решить на CSS:
body:has(.popup:target) {
overflow: hidden;
}
Когда в body присутствует .popup:target, к body будет применяться overflow: hidden
Можно решить и на JS кроссбраузерно, но, думаю, вы не заботитесь о кроссбраузерности
.popup {
position: fixed;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
top: 0;
left: 0;
opacity: 0;
visibility: hidden;
overflow-y: auto;
overflow-x: hidden;
transition: all 0.8s ease 0s;
z-index: 1;
}
.popup__area {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.popup__body {
display: flex;
justify-content: space-between;
align-items: center;
justify-content: center;
transition: all 0.8s ease 0s;
}
@media only screen and (max-width: 767.98px) {
.popup__body {
flex-direction: column-reverse;
}
}
.popup__content {
display: flex;
justify-content: space-between;
align-items: center;
justify-content: flex-start;
background-color: #FFF;
color: #000;
max-width: 50%;
width: 100%;
height: 100vh;
padding: 4rem;
position: relative;
transition: all 0.3s ease 0s;
}
@media only screen and (max-width: 767.98px) {
.popup__content {
max-width: 100%;
height: auto;
}
}
.popup__close {
position: absolute;
right: 12.8rem;
top: 8rem;
background: url(../icons/close.svg) center center/contain no-repeat;
width: 3.2rem;
height: 3.2rem;
text-decoration: none;
z-index: 1;
}
@media only screen and (max-width: 991.98px) {
.popup__close {
right: 1.5rem;
top: 1.5rem;
}
}
.popup__img {
max-width: 50%;
width: 100%;
height: 100vh;
}
@media only screen and (max-width: 767.98px) {
.popup__img {
max-width: 100%;
height: auto;
}
}
@media only screen and (max-height: 479.98px) {
.popup__img {
zoom: 142%;
}
}
.popup__text {
width: 100%;
margin: 0 auto;
}
.popup__text h3 {
color: #000;
font-size: 5.6rem;
font-weight: 600;
line-height: 1.4;
letter-spacing: -0.112rem;
max-width: 51.4rem;
width: 100%;
margin-bottom: 1.6rem;
}
@media only screen and (max-width: 767.98px) {
.popup__text h3 {
text-align: center;
margin-left: auto;
margin-right: auto;
}
}
@media only screen and (max-width: 479.98px) {
.popup__text h3 {
font-size: 3.6rem;
}
}
@media only screen and (max-width: 320px) {
.popup__text h3 {
font-size: 2.6rem;
}
}
.popup__text>p {
color: #333;
font-size: 1.8rem;
line-height: 1.8;
letter-spacing: -0.036rem;
margin-bottom: 3.2rem;
}
@media only screen and (max-width: 767.98px) {
.popup__text>p {
text-align: center;
}
}
.popup__form {
max-width: 55.4rem;
width: 100%;
}
@media only screen and (max-width: 767.98px) {
.popup__form {
margin: 0 auto;
}
}
.popup__form input,
.popup__form label {
display: block;
line-height: 1.6;
letter-spacing: -0.032rem;
padding: 1.2rem 1.6rem 1rem;
}
.popup__form input {
width: 100%;
color: #333;
border-bottom: 0.1rem solid #333;
}
.popup__form input:focus-visible,
.popup__form input:focus {
border-bottom: 0.1rem solid #1F4D38;
}
.popup__form label {
color: #808080;
}
.popup__form>input:not:first-child {
margin-top: 3.2rem;
}
.popup__form button {
color: #FFF;
font-size: 1.4rem;
line-height: 1;
max-width: 18rem;
width: 100%;
}
.popup__inputs {
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
margin-top: 3.2rem !important;
}
@media only screen and (max-width: 479.98px) {
.popup__inputs {
flex-direction: column;
}
}
.popup__checkbox {
display: flex;
justify-content: space-between;
align-items: center;
gap: 1.5rem;
margin-top: 3.2rem;
}
@media only screen and (max-width: 479.98px) {
.popup__checkbox {
flex-direction: column;
}
}
.popup__checkbox a {
color: #000;
font-weight: 600;
line-height: 1.2;
text-decoration-line: underline;
transition: all 0.3s ease 0s;
}
.popup__checkbox a:hover {
opacity: 0.7;
}
.popup__checkbox a:active {
opacity: 1;
}
.popup__btn {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
justify-content: flex-end;
align-items: stretch;
margin-top: 8.9rem;
gap: 1.2rem;
}
@media only screen and (max-width: 479.98px) {
.popup__btn {
margin-top: 4rem;
flex-direction: column;
}
}
.popup__btn button {
align-self: normal;
}
@media only screen and (max-width: 479.98px) {
.popup__btn button {
max-width: 100%;
}
}
.popup__form-consult>div+div {
margin-top: 3.1rem;
}
.popup__form-consult a {
max-width: 18rem;
width: 100%;
}
@media only screen and (max-width: 479.98px) {
.popup__form-consult a {
max-width: 100%;
height: 4.4rem;
}
}
.popup__form-consult-btn {
margin-top: 7rem !important;
}
.input-wrapper {
margin-top: 0;
overflow: hidden;
position: relative;
width: 100%;
}
.input-wrapper label {
position: absolute;
transition: all 0.2s ease;
bottom: 0;
pointer-events: none;
white-space: nowrap;
max-width: 100%;
overflow: hidden;
}
.input-wrapper select {
width: 100%;
}
.input-wrapper input:not(:placeholder-shown)+label,
.input-wrapper input:focus+label {
bottom: 2rem;
font-size: 1.2rem;
}
.popup:target {
opacity: 1;
z-index: 100;
visibility: visible;
}
body:has(.popup:target) {
overflow: hidden;
}
<ul class="header__links links">
<li>
<a href="#popup__consult" class="text-1">For Providers</a>
<div class="decor-line"></div>
</li>
</ul>
<div id="popup__consult" class="popup">
<a href="#!" class="popup__area"></a>
<div class="popup__body justify-content-flex-end">
<a href="#close__popup" class="popup__close close-2"></a>
<div class="popup__content w-5 h-1">
<div class="popup__text w-7">
<h3 class="popup__title w-6">Request Consultation</h3>
<p>Answer a few questions so the provider can get in touch</p>
<form class="popup__form popup__form-consult w-7" action="#!">
<div class="popup__inputs">
<div class="input-wrapper">
<input type="text" id="name" required placeholder="" autocomplete="off">
<label for="name">First Name</label>
</div>
<div class="input-wrapper">
<input type="text" id="last" required placeholder="">
<label for="last">Last Name</label>
</div>
</div>
<div class="popup__inputs">
<div class="input-wrapper">
<input type="email" id="email" required placeholder="" autocomplete="off">
<label for="email">Email</label>
</div>
<div class="input-wrapper w-8">
<input type="text" id="phone" name="phone" required placeholder="" autocomplete="off">
<label for="phone">Phone Number</label>
</div>
</div>
<div class="choice">
<p>Payment type</p>
<div class="checkbox radio">
<label>
<input type="radio" checked name="coding-notes" class="checkbox__real">
<span class="checkbox__custom checkbox__custom_1">Insurance</span>
</label>
</div>
<div class="checkbox radio radio_2">
<label>
<input type="radio" name="coding-notes" class="checkbox__real">
<span class="checkbox__custom">Out of Pocket</span>
</label>
</div>
</div>
<div class="popup__inputs">
<div class="input-wrapper">
<input type="text" id="code" placeholder="">
<label for="code">City or ZIP code</label>
</div>
<div class="select" tabindex="1">
<div class="custom-select">
<select id="select-2">
<option value="0">Virtual or In-person</option>
<option value="1">Virtual</option>
<option value="2">In-person</option>
</select>
</div>
</div>
</div>
<div class="popup__inputs flex-direction-column">
<div class="input-wrapper">
<input type="text" id="subject" placeholder="">
<label for="subject">Subject</label>
</div>
<input type="text" required placeholder="What brings you here?" name="info">
</div>
<div class="popup__btn popup__form-consult-btn">
<a href="#close__popup" class="btn btn-4">Cancel</a>
<button type="submit" class="btn btn-3">
Submit
<span class="decor-ball-arrow color-3"><img class="arrow-white"
src="icons/arrow-white.svg" alt="arrow-white"></span>
</button>
</div>
</form>
</div>
</div>
</div>
</div>