当前位置:网站首页>解决 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;
}
边栏推荐
- The input value "18-20000hz" is incorrect. The setting information is incomplete. Please select a company
- 重投农业,加码技术服务,拼多多底盘进一步夯实
- Serval and Rooted Tree(CF1153D)-DP
- Research and Analysis on the market status of polybutene-1 in China from 2021 to 2027 and forecast report on its development prospect
- unity package manager starting server stuck(Unity启动卡在starting server,然后报错)
- Ubantu1804 two opencv versions coexist
- Interviewer: what is the event flow and event model in JS?
- Redis fourth session - redis high performance principle (multiplexing) and high availability analysis (backup, master-slave)
- Deploy website traffic statistics background based on Tencent cloud lightweight application server and umami
- 全球机器视觉市场规模持续上涨,PoE图像采集卡为工业相机提供高速传输通道
猜你喜欢

Modify appid of local wechat applet

Usage methods and cases of PLSQL blocks, cursors, functions, stored procedures and triggers of Oracle Database

My collection of scientific research websites

moderlarts第二次作业

【数据可视化】Apache Superset 1.2.0教程 (二)——快速入门(可视化王者英雄数据)

A mechanics informed artistic neural network approach in data driven constructive modeling

moderlarts第一次培训
![[data visualization] use Apache superset to visualize Clickhouse data](/img/4b/a73c2eb810f1d2b492e950afb2d0bc.png)
[data visualization] use Apache superset to visualize Clickhouse data

Application scenario: wide application of Poe network card in NDI technology for live broadcast program production

新品发布:国产单电口千兆网卡正式量产!
随机推荐
Unity screenshot
黑圆圈显示实现
Why is your LDO output unstable?
Mysql add 新增多个新字段并指定字段位置
[data visualization] use Apache superset to visualize Clickhouse data
桌面以及文件资源管理器无限重启的解决
JSON introduction
2022-2028 current situation and future development trend of global and Chinese thermocouple belt Market
What is the meaning of holding shares of financial products?
New product release: lr-link Lianrui launched the first 25g OCP 3.0 network card
Solution to unlimited restart of desktop and file explorer
2022-2028 global and Chinese thermopile infrared sensor market status and future development trend
[Err] 1045 - Access denied for user ‘root‘@‘%‘ (using password: YES)
Product information | Poe network card family makes a collective appearance, the perfect partner of machine vision!
Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
[nk] 牛客练习赛100 C 小红的删数字
27. this pointing problem
Serval and Rooted Tree(CF1153D)-DP
第一部分 物理层
What are striplines and microstrip lines? Reference planes and transmission lines