当前位置:网站首页>解决 img 5px 间距的问题
解决 img 5px 间距的问题
2022-06-11 20:54:00 【只是六号z】
解决 img 5px 间距的问题
前言
在css的使用中,如果我们将img放置在div中,这时就会出现div的底部存在一个5px的间距,这会是我们的样式显得不融洽。所以我今天就记录一下这个问题该如何解决。
一、img存在5px问题
如下示例代码,我们将图片放置在一个div中。
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>清除图片多5px问题</title>
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<div class="img-container">
<img src="../image/1.jpg" alt="">
</div>
</body>
</html>
给定的样式如下:
index.css
*{
margin: 0;
padding: 0;
}
.img-container{
/*设置盒子背景颜色*/
background-color: lightblue;
}
img{
/*设置图片高度,宽度*/
height: 700px;
width: 100%;
}
运行结果:
可以看到,图片下方出现了一点绿色的间距,虽然很小,但是仔细看还是能够看到的。
下面我们就去解决这个问题。
二、解决方法(四种)
1.设置父元素字体大小为 0
关键代码:
.img-container{
background-color: lightblue;
font-size: 0;
}
2.将 img 元素设置为 display: block
关键代码:
img{
height: 700px;
width: 100%;
display: block;
}
3.将 img 元素设置为 vertical-align: bottom
关键代码:
img{
height: 700px;
width: 100%;
vertical-align: bottom;
}
4.给父元素设置 line-height: 5px
关键代码:
.img-container{
background-color: lightblue;
line-height: 5px;
}
边栏推荐
- 第二部分 数据链路层
- 输入值“18-20000hz”错误,设置信息不完整,请选择单位
- 第一部分 物理层
- moderlarts第一次培訓
- Gestionnaire de paquets d'Unit é Starting Server Stuck
- First modelarts training
- Current situation and future development trend of global and Chinese cogeneration system market from 2022 to 2028
- Simple classification example of brain cell membrane equivalent neural network
- Current situation and future development trend of tropical forage seed market in the world and China from 2022 to 2028
- Current situation and future development trend of thermoelectric generator Market in the world and China from 2022 to 2028
猜你喜欢

Solution to unlimited restart of desktop and file explorer

应用场景:现场直播节目制作NDI技术中PoE网卡的广泛应用

频域滤波器

Yintai department store and Taobao tmall jointly create a green fashion show to help "carbon neutrality"

Why is your LDO output unstable?
![[nk] deleted number of 100 C Xiaohong in Niuke practice match](/img/f1/a99600e1800c087aceb60a559dee39.png)
[nk] deleted number of 100 C Xiaohong in Niuke practice match

从概率论基础出发推导卡尔曼滤波

IDEA中,运行yarn命令,显示无法加载文件,因为在此系统上禁用运行脚本

Simulate Oracle lock waiting and manual unlocking

10 R vector operation construction
随机推荐
[unity plug-in] shader keyword analysis tool shadercontrol
Chinese text classification based on CNN
Work assessment of spectral analysis of Jilin University in March of the 22nd spring -00079
Deploy website traffic statistics background based on Tencent cloud lightweight application server and umami
ubantu1804 两个opencv版本共存
Ubantu1804 two opencv versions coexist
A mechanics informed artistic neural network approach in data driven constructive modeling
浅谈UGUI中Canvas RectTransform的Scale
Première formation sur les largeurs modernes
Implement AOP and interface caching on WPF client
Toolbar替换ActionBar后Title不显示
The official announced the launch of Alibaba's 2023 global school recruitment: Technical Posts account for more than 60%
Brain cell membrane equivalent neural network training code
14 r basic exercises
为什么100G网络传输要使用iWARP、RoCE v2、NVMe-oF等协议
Two end carry output character
[Unity插件]着色器关键字分析工具ShaderControl
Research and Analysis on the market status of polybutene-1 in China from 2021 to 2027 and forecast report on its development prospect
【数据可视化】Apache Superset 1.2.0教程 (二)——快速入门(可视化王者英雄数据)
Current situation and future development trend of global and Chinese cogeneration system market from 2022 to 2028