html - 即使我最小化屏幕,如何在 HTML/CSS 中绝对修复文本
问题描述
所以现在我正在尝试应用我在 Front Web Development 中学到的知识,但我遇到了一个问题,即文本在较小的视口中没有保持应有的方式。
body {
font-family: "Roboto Condensed", sans-serif;
margin: 0;
background: #f2f2fc;
color: #302e4d;
}
.about-section {
position: absolute;
max-width: 100%;
top: 20%;
left: 40%;
transform: translate(-40%, -60%);
}
.about-me div {
font-size: 40px;
font-weight: bold;
}
.intro {
font-size: 30px;
padding-top: 50px;
font-weight: bold;
}
.intro-stud {
color: #E00;
}
.description {
color: #504e70;
font-size: 20px;
font-weight: normal;
}
<div id="main-content">
<section class="about-section">
<div class="about-me">
<div>About Me</div>
</div>
<div class="intro">
<span class="intro-name">I'm Christian Wells Martin and</span>
<span class="intro-stud">a Student</span>
<p class="description">Hi! My name is Christian Wells Martin, a BSIT/BSCS student in _____ College/University, and currently studying web development, and this website is my first mini-project, and I hope you guys will like it!.</p>
</div>
</section>
</div>
欢迎提出建议,特别是如果我做了一些错误的做法。
解决方案
有几种方法可以解决这个问题。
一,您在绝对定位中使用百分比。百分比会随着窗口大小的变化而变化。这可以产生很好的效果,但它似乎不是你想要的。如果您不希望您的文本做出响应,请尝试使用精确的像素值。https://www.w3schools.com/cssref/pr_dim_width.asp
另一种更高级的解决方法是使用媒体查询。这些允许您根据屏幕的当前大小定义不同的 css 样式。https://www.w3schools.com/cssref/css3_pr_mediaquery.asp
推荐阅读
- php - 如何使用 curl 和 discord api (php) 修复 400 错误请求
- c++ - clang 无法检测到初始化并给出错误
- c - While 循环要求输入两次,而不是第一次中断
- android - 使用产品风味复制类
- python - 我可以使用哪些算法来检查一个多边形是否适合另一个多边形?
- java - 为什么 DriverManager.getConnection 不使用 Driver.class 中的“acceptsURL”方法
- sql-server - 如何将数千行 T-SQL 剪切为小型存储过程或函数?
- c# - 如何在外部类的每个方法调用周围自动添加锁?
- php - 当 woocommerce 订单状态通过操作挂钩完成时,如何触发 mailster 自动回复?
- shell - ** .SH 文件正确运行的更新问题