admin管理员组文章数量:1287840
Genuinely apologizing if this has already been asked before, I looked Everywhere and couldn't find an answer to my specific question outside of guides on responsiveness that didn't quite work when I tried them out (although that could be entirely on me.)
I have one container in another and I want the page to be viewable when zoomed in, however the container gets cut off by the other one it's inside when you zoom in, but what I'd prefer is if it shrunk with it instead. I've tried max and min width but min width didn't do anything. Here's my code.
document.getElementById('wrapper').addEventListener('click', (e) => {
const btn = e.target.closest('button.tablinks');
if (!btn) return;
const targetId = btn.dataset.target;
const currentTab = document.getElementById(targetId);
if (!currentTab) return;
// Use the parent of the target tab as the container.
const container = currentTab.parentElement;
// Only toggle direct children of that container.
container.querySelectorAll(':scope > .tabcontent').forEach(tab => {
tab.classList.toggle('active', tab === currentTab);
});
});
@media screen and (max-width: 320px) {
.wrapper {
display: flex;
}
}
#wrapper {
width: 100%;
height: 100%;
}
#main {
color: red;
background-color: pink;
max-width: 76rem;
min-width: 40rem;
width: 52%;
height: 30rem;
margin-top: 3rem;
margin-inline: auto;
border: 6px solid;
border-color: brown;
border-radius: 15% / 38px;
padding: 4px;
}
#content {
color: rgb(0, 0, 0);
background-color: beige;
max-width: 66rem;
width: 96%;
height: 27rem;
position: relative;
top: 1.4rem;
margin-inline: auto;
border: 4.5px solid brown;
border-radius: 15% / 30px;
overflow: auto;
scrollbar-width: none;
}
#profileimage {
background-color: pink;
width: 16rem;
height: 25rem;
border: 2.5px solid brown;
border-radius: 15% / 15px;
position: relative;
top: 0.4rem;
}
#references {
color: red;
}
#about {
position: relative;
background-color: pink;
left: 17rem;
bottom: 22.6rem;
width: 27.4rem;
height: 20rem;
}
#aboutimg {
position: relative;
background-color: lightblue;
width: 10rem;
height: 12rem;
}
#aboutcontent {}
#aboutbio {}
.flex-container {
display: flex;
flex-wrap: wrap;
margin: 0 auto;
}
.box {
flex-grow: 1;
flex-shrink: 1;
flex-basis: calc(25% - 10px);
margin: 5px;
}
img {
width: 100%;
}
.tab {
position: relative;
text-align: center;
top: 4.5rem;
}
.tab button {
background-color: burlywood;
padding: 4px;
width: 10rem;
font-size: 1.8rem;
border: 6px solid brown;
border-radius: 10% / 8px;
cursor: pointer;
color: rgb(176, 103, 66);
}
.tab2 {
position: absolute;
text-align: center;
top: 0.5rem;
left: 22rem;
}
.tab2 button {
background-color: burlywood;
width: 8rem;
font-size: 18px;
border: 3.5px solid brown;
border-radius: 10% / 8px;
cursor: pointer;
color: rgb(176, 103, 66);
}
.tab button:hover {
background-color: rgb(191, 147, 89);
color: rgb(144, 58, 32);
border: 6px solid brown;
border-radius: 10% / 8px;
}
.tab button:active {
background-color: rgb(153, 73, 51);
color: rgb(70, 21, 6);
border: 4px solid brown;
border-radius: 10% / 8px;
}
.tabcontent {
padding: 6px 12px;
border-top: none;
display: none;
}
.tabcontent.active {
display: block;
}
@media screen and (max-width: 800px) {}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="wrapper">
<!-- Outer tabs -->
<div class="tab">
<button class="tablinks active" data-target="profile">Profile</button>
<button class="tablinks" data-target="ref">Ref Sheet</button>
</div>
<div id="main">
<div id="content">
<!-- Outer tab content: Profile -->
<div id="profile" class="tabcontent active">
<div id="profileimage"></div>
<!-- Inner tab buttons -->
<div class="tab2" id="buttons2">
<button class="tablinks active" data-target="about">About</button>
<button class="tablinks" data-target="extra">Extra</button>
</div>
<!-- Wrap inner tab content in its own container -->
<div class="inner-tab-container">
<div id="about" class="tabcontent active">
<div id="aboutimg"></div>
<div id="aboutcontent"></div>
<div id="aboutbio"></div>
</div>
<div id="extra" class="tabcontent">Extra content</div>
</div>
</div>
<!-- Outer tab content: Ref Sheet -->
<div id="ref" class="tabcontent">
<div id="references" class="flex-container">
<div class="box">
<img src=".jpg">
</div>
<!-- (other image boxes) -->
</div>
</div>
</div>
</div>
</div>
<script src="javascript.js"></script>
</body>
</html>
Genuinely apologizing if this has already been asked before, I looked Everywhere and couldn't find an answer to my specific question outside of guides on responsiveness that didn't quite work when I tried them out (although that could be entirely on me.)
I have one container in another and I want the page to be viewable when zoomed in, however the container gets cut off by the other one it's inside when you zoom in, but what I'd prefer is if it shrunk with it instead. I've tried max and min width but min width didn't do anything. Here's my code.
document.getElementById('wrapper').addEventListener('click', (e) => {
const btn = e.target.closest('button.tablinks');
if (!btn) return;
const targetId = btn.dataset.target;
const currentTab = document.getElementById(targetId);
if (!currentTab) return;
// Use the parent of the target tab as the container.
const container = currentTab.parentElement;
// Only toggle direct children of that container.
container.querySelectorAll(':scope > .tabcontent').forEach(tab => {
tab.classList.toggle('active', tab === currentTab);
});
});
@media screen and (max-width: 320px) {
.wrapper {
display: flex;
}
}
#wrapper {
width: 100%;
height: 100%;
}
#main {
color: red;
background-color: pink;
max-width: 76rem;
min-width: 40rem;
width: 52%;
height: 30rem;
margin-top: 3rem;
margin-inline: auto;
border: 6px solid;
border-color: brown;
border-radius: 15% / 38px;
padding: 4px;
}
#content {
color: rgb(0, 0, 0);
background-color: beige;
max-width: 66rem;
width: 96%;
height: 27rem;
position: relative;
top: 1.4rem;
margin-inline: auto;
border: 4.5px solid brown;
border-radius: 15% / 30px;
overflow: auto;
scrollbar-width: none;
}
#profileimage {
background-color: pink;
width: 16rem;
height: 25rem;
border: 2.5px solid brown;
border-radius: 15% / 15px;
position: relative;
top: 0.4rem;
}
#references {
color: red;
}
#about {
position: relative;
background-color: pink;
left: 17rem;
bottom: 22.6rem;
width: 27.4rem;
height: 20rem;
}
#aboutimg {
position: relative;
background-color: lightblue;
width: 10rem;
height: 12rem;
}
#aboutcontent {}
#aboutbio {}
.flex-container {
display: flex;
flex-wrap: wrap;
margin: 0 auto;
}
.box {
flex-grow: 1;
flex-shrink: 1;
flex-basis: calc(25% - 10px);
margin: 5px;
}
img {
width: 100%;
}
.tab {
position: relative;
text-align: center;
top: 4.5rem;
}
.tab button {
background-color: burlywood;
padding: 4px;
width: 10rem;
font-size: 1.8rem;
border: 6px solid brown;
border-radius: 10% / 8px;
cursor: pointer;
color: rgb(176, 103, 66);
}
.tab2 {
position: absolute;
text-align: center;
top: 0.5rem;
left: 22rem;
}
.tab2 button {
background-color: burlywood;
width: 8rem;
font-size: 18px;
border: 3.5px solid brown;
border-radius: 10% / 8px;
cursor: pointer;
color: rgb(176, 103, 66);
}
.tab button:hover {
background-color: rgb(191, 147, 89);
color: rgb(144, 58, 32);
border: 6px solid brown;
border-radius: 10% / 8px;
}
.tab button:active {
background-color: rgb(153, 73, 51);
color: rgb(70, 21, 6);
border: 4px solid brown;
border-radius: 10% / 8px;
}
.tabcontent {
padding: 6px 12px;
border-top: none;
display: none;
}
.tabcontent.active {
display: block;
}
@media screen and (max-width: 800px) {}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="wrapper">
<!-- Outer tabs -->
<div class="tab">
<button class="tablinks active" data-target="profile">Profile</button>
<button class="tablinks" data-target="ref">Ref Sheet</button>
</div>
<div id="main">
<div id="content">
<!-- Outer tab content: Profile -->
<div id="profile" class="tabcontent active">
<div id="profileimage"></div>
<!-- Inner tab buttons -->
<div class="tab2" id="buttons2">
<button class="tablinks active" data-target="about">About</button>
<button class="tablinks" data-target="extra">Extra</button>
</div>
<!-- Wrap inner tab content in its own container -->
<div class="inner-tab-container">
<div id="about" class="tabcontent active">
<div id="aboutimg"></div>
<div id="aboutcontent"></div>
<div id="aboutbio"></div>
</div>
<div id="extra" class="tabcontent">Extra content</div>
</div>
</div>
<!-- Outer tab content: Ref Sheet -->
<div id="ref" class="tabcontent">
<div id="references" class="flex-container">
<div class="box">
<img src="https://t3.ftcdn/jpg/03/45/05/92/360_F_345059232_CPieT8RIWOUk4JqBkkWkIETYAkmz2b75.jpg">
</div>
<!-- (other image boxes) -->
</div>
</div>
</div>
</div>
</div>
<script src="javascript.js"></script>
</body>
</html>
Share
Improve this question
edited Feb 23 at 0:26
Lubomyr Pryt
1711 silver badge11 bronze badges
asked Feb 22 at 23:20
kurtiskurtis
135 bronze badges
1 Answer
Reset to default 1I got it :) I just had to remove the fixed width and ONLY have a max-width and min-width
版权声明:本文标题:javascript - How to stop one container from disappearing into another? When zooming in and out - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741324192a2372379.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论