在特定屏幕宽度时使DIV宽度响应迅速
好的,因此,对于学校作业,我必须使这些块在特定屏幕宽度上响应和变化,而在1024px以上,它们必须是2行,并且低于1024px 2行垂直行驶,始终拼写“ LOI”。现在,当660px时,这些块变小,它们掉出屏幕。当屏幕宽度为660px时,有没有办法使它们逐渐变小?提前致谢!
main {
max-width: 1024px;
margin: auto;
}
.blokken {
display: flex;
flex-wrap: wrap;
flex-direction: column;
max-height: 1200px;
align-content: center;
max-width: 100%;
justify-content: center;
}
@media screen and (min-width: 1024px) {
.blokken {
flex-direction: row;
}
}
.letter {
width: 300px;
height: 300px;
margin: 5px;
background-color: #eee;
border: 5px solid black;
font-family: sans-serif;
font-size: 5em;
color: black;
display: flex;
justify-content: center;
align-items: center;
border-radius: 25%;
overflow: hidden;
}
<main>
<h2 id="letterblokjes">Letterblokjes</h2>
<div class="blokken">
<div class="letter">L</div>
<div class="letter">O</div>
<div class="letter">I</div>
<div class="letter">L</div>
<div class="letter">O</div>
<div class="letter">I</div>
</div>
</main>
Okay so, for a school assignment I have to make these blocks responsive and changing rows when on a certain screen width, above 1024px they have to be 2 rows going horizontally, and below 1024px 2 rows going vertically, always spelling out 'LOI'. Now when at 660px, the blocks dont get smaller, they fall out of the screen. Is there a way to make them gradually get smaller when the screen width is at say 660px? Thanks in advance!
main {
max-width: 1024px;
margin: auto;
}
.blokken {
display: flex;
flex-wrap: wrap;
flex-direction: column;
max-height: 1200px;
align-content: center;
max-width: 100%;
justify-content: center;
}
@media screen and (min-width: 1024px) {
.blokken {
flex-direction: row;
}
}
.letter {
width: 300px;
height: 300px;
margin: 5px;
background-color: #eee;
border: 5px solid black;
font-family: sans-serif;
font-size: 5em;
color: black;
display: flex;
justify-content: center;
align-items: center;
border-radius: 25%;
overflow: hidden;
}
<main>
<h2 id="letterblokjes">Letterblokjes</h2>
<div class="blokken">
<div class="letter">L</div>
<div class="letter">O</div>
<div class="letter">I</div>
<div class="letter">L</div>
<div class="letter">O</div>
<div class="letter">I</div>
</div>
</main>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用动态
计算
最大宽度
而不是静态300px
width
。在这里看到它:
You can try using a dynamic
calculated
max-width
instead of a static300px
width
.See it working here:
您可以使用另一个@Media将您的宽度设置为660px时的百分比:
编辑:
现在,您的块是正方形的,随着空间的较小而变小,
我更改了
字母
与vw
相称的,因为它的响应能力很快,允许它们在任何小屏幕上保持正方形,我也更改了高度
blokken
为信件始终通过将单元放入vw
在660px宽屏幕上,请始终保持包装。You can use another @media to set your width to a percentage when you're at 660px:
EDIT :
now your blocks are square and getting smaller with less space
I changed the
letter
proportion tovw
as it's responsive, allowing them to stay square on any small screenI also changed the height of
blokken
for the letter to always stay packed by putting the unit tovw
on under 660px wide screen