【发布时间】:2012-11-01 17:32:11
【问题描述】:
它由9个盒子组成,中间有文字。 我已经做到了,所以这些框会随着屏幕的大小而调整,所以它会一直保持在同一个地方。
但是,即使我使用百分比,文本也不会调整大小。
- 如何调整文本大小,使其始终与整个页面保持相同的比例?
- 这是处理多种分辨率的合适解决方案吗?还是我应该在 CSS 中有很多
@media检查并为每种媒体类型设置很多布局?
html,
body {
height: 100%;
width: 100%;
}
#launchmain {
width: 55%;
display: inline-block;
position: relative;
top: 10%;
left: 25%;
}
#launchmain:after {
padding-top: 79.26%;
display: block;
content: '';
margin-top: 10px;
}
#box1 {
border: 1px solid #000000;
position: absolute;
width: 25.37%;
height: 21.88%
}
#box2 {
border: 1px solid #000000;
width: 48.48%;
height: 21.88%;
position: absolute;
left: 25.64%
}
#box3 {
border: 1px solid #000000;
width: 25.37%;
height: 21.88%;
position: absolute;
left: 74.39%;
}
#box4 {
border: 1px solid #000000;
width: 33.235%;
height: 53.84%;
position: absolute;
top: 22.07%;
}
#maininvite {
border: 1px solid #000000;
width: 33.53%;
height: 53.84%;
position: absolute;
top: 22.07%;
left: 33.235%;
}
#box6 {
border: 1px solid #000000;
width: 33.235%;
height: 53.84%;
position: absolute;
top: 22.07%;
left: 66.765%;
}
#box7 {
border: 1px solid #000000;
width: 25.37%;
height: 21.88%;
position: absolute;
top: 76.2%;
}
#box8 {
border: 1px solid #000000;
width: 48.48%;
height: 21.88%;
position: absolute;
left: 25.64%;
top: 76.2%;
}
#box9 {
border: 1px solid #000000;
width: 25.37%;
height: 21.88%;
position: absolute;
top: 76.2%;
left: 74.39%;
}
#maininvite h2 {
font-size: 180%;
}
p {
position: relative;
font-size: 80%;
}
<div id="launchmain">
<div id="box1"></div>
<div id="box2"></div>
<div id="box3"></div>
<div id="box4"></div>
<div id="maininvite">
<h2> header</h2>
<p>not a lot of text here but still overflowing</p>
</div>
<div id="box6"></div>
<div id="box7"></div>
<div id="box8"></div>
<div id="box9"></div>
</div>
【问题讨论】:
-
您的文字大小不会使用百分比来调整,它会保持不变。这不是容器 div 的百分比,而是容器中设置的文本大小的百分比。
-
仅使用 CSS 是不可能的。您将需要使用 Javascript。看看这个,我知道它在以下问题中将文本保留在 1 行,但它应该让你在正确的行上 stackoverflow.com/questions/3401136/…
标签: css responsive-design