当前位置:网站首页>解决 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;
}
边栏推荐
- Simple classification example of brain cell membrane equivalent neural network
- 产品资讯|PoE网卡家族集体亮相,机器视觉完美搭档!
- The input value "18-20000hz" is incorrect. The setting information is incomplete. Please select a company
- 为什么100G网络传输要使用iWARP、RoCE v2、NVMe-oF等协议
- 27. this pointing problem
- 28. JS implementation mechanism
- BCC tool tool usage
- var 和 let的区别_let 和 var的区别
- JMeter load test finds the maximum number of concurrent users (including step analysis)
- Summary of C language programming knowledge points 01
猜你喜欢
随机推荐
Gestionnaire de paquets d'Unit é Starting Server Stuck
Two end carry output character
Teach you how to use win7 system to quickly build your own website
可综合RTL代码设计方法和注意事项
The difference between VaR and let_ The difference between let and VaR
Work assessment of spectral analysis of Jilin University in March of the 22nd spring -00079
Première formation sur les largeurs modernes
Unity package manager starting server stuck
2022-2028 current situation and future development trend of global and Chinese thermocouple belt Market
Why should I use iwarp, roce V2, nvme of and other protocols for 100g network transmission
Force buckle 6 Zigzag transformation
Summary of C language programming knowledge points 01
Docker installing MySQL
Docker installation redis
unity package manager starting server stuck(Unity启动卡在starting server,然后报错)
Ubantu1804 two opencv versions coexist
MySQL installation free configuration tutorial under Windows mysql-5.6.51-winx64 Zip version
浅谈UGUI中Canvas RectTransform的Scale
Frequency domain filter
Technical exchange | why should network security equipment use bypass function








