vertical-align: middle;
调整图片预设多余的空间position:absolute;
绝对定位和相对定位position:relative;
来排版先做一个wrap区块
wrap里面会有四个item区块
每个item区块内有图片和文字
item内的文字内容用一个txt区块包起来
<div class="wrap">
<div class="item">
<img src="https://picsum.photos/500/400?random=10" alt="">
<div class="txt">
<h2>金鱼都能懂得这个网页画面怎麽切:互动图文卡片</h2>
<p>互动图文卡片是我们在网页中经常见到的另一种稀饭版,不会切你就逊掉罗。</p>
</div>
</div>
<div class="item">
<img src="https://picsum.photos/500/400?random=5" alt="">
<div class="txt">
<h2>每天都要打开VS Code刻意练习!</h2>
<p>一旦假设某件事情是天生的,等於告诉自己对此束手无策</p>
</div>
</div>
<div class="item">
<img src="https://picsum.photos/500/400?random=20" alt="">
<div class="txt">
<h2>学过的观念没弄清楚,切版就切不好</h2>
<p>你不需要很厉害才能开始,但你需要开始才会很厉害</p>
</div>
</div>
<div class="item">
<img src="https://picsum.photos/500/400?random=30" alt="">
<div class="txt">
<h2>比过去的自己更好,就很好了</h2>
<p>做自己,其他人都已经有人做了</p>
</div>
</div>
</div>
*{
margin: 0;
padding: 0;
list-style: none;
}
.wrap{
width:100%;
}
.item{
width:25%;
}
.item img{
width:100%;
}
vertical-align: middle;
来调整调整前
.item img{
width:100%;
vertical-align: middle;
}
调整後
.item{
width:25%;
position:relative;
}
.item .txt{
position: absolute;
top:0;
right:0;
bottom:0;
left: 0;
padding:20px;
background-color:rgba(0,0,0,.6);
}
.item h2{
font-size: 24px;
color:#ff0;
}
.item p{
font-size: 18px;
color:#fff;
}
display: flex;
flex-direction: column;
justify-content: center;
.item .txt{
position: absolute;
top:0;
right:0;
bottom:0;
left: 0;
padding:20px;
background-color:rgba(0,0,0,.6);
display: flex;
flex-direction: column;
justify-content: center;
}
插入<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@100;300;500&display=swap" rel="stylesheet">
到head内
<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>铁人赛Day22</title>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@100;300;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./styles/style.css">
</head>
CSS新增字体font-family: 'Noto Sans TC', sans-serif;
新增font-weight
*{
margin: 0;
padding: 0;
list-style: none;
font-family: 'Noto Sans TC', sans-serif;
}
.item h2{
font-size: 24px;
color:#ff0;
font-weight: 500;
}
.item p{
font-size: 18px;
color:#fff;
font-weight: 100;
}
display:flex;
,将四个item区块设成从左到右排列.wrap{
width:100%;
display: flex;
}
opacity: 0;
opacity:1;
transition: opacity .5s;
.item .txt{
position: absolute;
top:0;
right:0;
bottom:0;
left: 0;
padding:20px;
background-color:rgba(0,0,0,0);
display: flex;
flex-direction: column;
justify-content: center;
opacity: 0;
transition: opacity .5s .3s;
}
.item:hover .txt{
opacity:1;
}
.item h2::after{
content:'';
display: block;
width:0%;
height:2px;
margin:10px 0;
background-color: #ff0;
transition: width .5s .3s;
}
.item:hover h2::after{
width:100%;
}
*{
margin: 0;
padding: 0;
list-style: none;
font-family: 'Noto Sans TC', sans-serif;
}
.wrap{
width:100%;
display: flex; /*将item区块设成并排*/
}
.item{
width:25%;
position:relative; /*使用绝对定位将文字内容定在图片内*/
}
.item img{
width:100%;
vertical-align: middle; /*消除图片下方预设的空白区块*/
}
.item h2{
font-size: 24px;
color:#ff0;
font-weight: 500;
}
.item p{
font-size: 18px;
color:#fff;
font-weight: 100;
}
.item .txt{
position: absolute; /*使用绝对定位将文字内容定在图片内*/
top:0;
right:0;
bottom:0;
left: 0;
padding:20px;
background-color:rgba(0,0,0,.6); /*将背景颜色设定成带黑色的透明色*/
display: flex;
flex-direction: column;
justify-content: center;
opacity: 0; /* 文字设为透明*/
transition: opacity .5s; /*设定渐变效果*/
}
.item:hover .txt{
opacity:1; /*滑鼠碰到图片时,文字内容从透明变成不透明*/
}
.item h2::after{
content:''; /*使用伪元素一定要搭配这句才会有效果*/
display: block; /*伪元素预设是display:inline-block;*/
width:0%;/*设定一开始宽度是0 */
height:2px;
margin:10px 0;
background-color: #ff0;
transition: width .5s .3s; /*设定渐变效果 跑0.5秒 delay0.3秒*/
}
.item:hover h2::after{
width:100%; /*设定碰到item区块才会出现h2底线*/
}
参考资料:金鱼都能懂的网页切版 : 互动图文卡片 NO002 | 切版教学 | HTML教学 | 网页教学 | 网页切版, CSS vertical-align 属性, RGB、HSL、Hex 网页色彩码,看完这篇全懂了
以上为个人学习笔记整理
若有错误,欢迎指正
变换图表折线图颜色样式 「y」:黄色 「--」:虚线 「^」:三角形 绘制两条线的折线图 显示图表的...
今天要讲的主题是权重,权重在CSS中扮演着裁决者的角色,在被重复赋予样式时,决定最终该显示哪一个样式...
组合技 Drone + godog + Mattermost 当有需求要在k8s上透过drone定期...
前言: 今天要来让大家做一个小型的成果发表,看完接下来的内容後,希望大家都可以学到怎麽让大家连上你...
今天的内容会跟各位介绍 Google Cloud 相关的基础知识,希望不会不小心的讲成像业配文QQ,...