当前位置:网站首页>响应式布局经典范例——巨幅背景大标题
响应式布局经典范例——巨幅背景大标题
2022-08-03 08:36:00 【朝阳39】
效果如下
电脑浏览器最大时的效果:
电脑浏览器窗口变窄的效果:
电脑浏览器窗口最窄的效果:
手机上的效果:
完整范例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>巨幅标题效果演示</title>
</head>
<body>
<header>
<div class="header-text-container">
<h1 class="header-article_title">你不知道的水杉</h1>
<time class="header-article_pub">2015年3月10日</time>
</div>
</header>
<article>
水杉(学名:Metasequoia glyptostroboides Hu & W. C.
Cheng):裸子植物杉科。落叶乔木,小枝对生,下垂。叶线形,交互对生,假二列成羽状复叶状,长1-1.7厘米,下面两侧有4-8条气孔线。雌雄同株。球果下垂,近球形,微具4棱,长1.8-2.5厘米,有长柄;种鳞木质,盾形,每种鳞具5-9种子,种子扁平,周围具窄翅。
水杉属在中生代白垩纪和新生代约有6-7种,过去认为早已绝灭,1941年中国植物学者在湖北利川谋道镇(当时四川万县磨刀溪)首次发现这一闻名中外古老珍稀孑遗树种。据近年调查,重庆万州、重庆石柱县、湖北利川和湖南龙山、桑植均发现300余年的巨树。
水杉适应性强,喜湿润生长快,北京以南各地均有栽培。材质轻软,可供建筑、板料、造纸等用;树姿优美,为庭园观赏树。
</article>
<style> html, body {
margin: 0; padding: 0; } header {
display: block; font-size: 1.125rem; /* 18px / 16px = 1.125 */ font-weight: 700; height: 500px; /* 样式回滚 */ height: 80vh; /* 如果浏览器不支持vh单位,则上面的500px可生效 */ min-height: 500px; max-height: 1080px; background: url("./水杉林.jpeg"); background-position: 50% 0; background-repeat: no-repeat; /* 设置容器background-size属性为cover,意为保持在图片长宽比的基础上缩放背景图像,使其尽可能完整地覆盖背景 */ background-size: cover; /* 弹性布局实现标题在背景图片中垂直居中 */ display: flex; flex-direction: column; justify-content: center; } .header-text-container {
text-align: center; color: white; /* 一定的文字阴影,使文字更加立体 */ text-shadow: 1px 1px 4px rgba(34, 34, 34, 0.6); } .header-article_title {
font-size: 2em; /* 80px / 40px = 2 */ } .header-article_pub {
display: block; font-size: 1em; /* 40px / 40px = 1 */ } @media all and (min-width: 480px) {
header {
font-size: 2.5rem; /* 40px / 16px = 2.5 */ } } /* 移动优先: 默认在移动设备上, 内边距为20px。 字体大小,行高,最大宽度等可以继续在后面的样式中沿用 */ article {
font-size: 1rem; line-height: 1.625rem; /* 26px / 16px = 1.625 */ max-width: 42.8125em; /* 685px / 16px = 42.8125em */ margin: 0 auto; box-sizing: border-box; padding: 1.25em; /* 20px / 16px = 1.25 */ } /* 当页面宽度在685px与600px之间时 调整内边距宽度为40px; */ @media all and (min-width: 600px) and (max-width: 685px) {
article {
padding: 2.5em; /* 40px / 16px = 2.5 */ } } /* 当页面宽度大于或等于685px(符合最佳宽度条件) 将内边距设为0 */ @media all and (min-width: 685px) {
article {
padding: 0; margin-top: 2.5em; /* 40px / 16px = 2.5 */ } } </style>
</body>
</html>
边栏推荐
- Qt 下拉复选框(MultiSelectComboBox)(一) 实现下拉框多选,搜索下拉框内容
- flutter 应用 抓包
- Laya中关于摄像机跟随人物移动或者点击人物碰撞器触发事件的Demo
- 行业洞察 | 如何更好的实现与虚拟人的互动体验?
- What are pseudo-classes and pseudo-elements?The difference between pseudo-classes and pseudo-elements
- ArcEngine (six) use the tool tool to realize the zoom in, zoom out and translation of the pull box
- Logic Pro X自带音色库列表
- 10分钟带你入门chrome(谷歌)浏览器插件开发
- 牛客 - 鼠标的天选(字符串哈希)
- HCIA实验(07)
猜你喜欢
随机推荐
dflow入门5——Big step & Big parameter
MySQL数据库————数据库与vs的连接
热部署系统实现
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之二:编码实现
Guava的Service
【LeetCode】101.对称二叉树
ArcEngine (4) Use of MapControl_OnMouseDown
二进制日志过期时间设置expire_logs_days
SQL每日一练(牛客新题库)——第5天:高级查询
Eject stubborn hard drives with diskpart's offline command
How does Mysql query two data tables for the same fields in two tables at the same time
【LeetCode】226.翻转二叉树
Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器
sqlite 日期字段加一天
flutter 应用 抓包
ArcEngine(八)用IWorkspaceFactory加载矢量数据
面渣逆袭:MySQL六十六问,两万字+五十图详解
mysql服务器上的mysql这个实例中表的介绍
【LeetCode】112.路径总和
36氪详情页AES