HTML中div总是比所包含的img高度高的问题

解决方案(任选一种):
1. div设置 font-size:0;

2. img设置 display:block;

3. div设置 display:flex;

4. img设置 vertical-align: middle;

原因:
  The white space displayed below image elements in HTML is often cause for confusion, but there is a logical explanation: Images are inline elements, and inline elements have descenders.

意思就是:

  img是一种类似text的元素,在结束的时候,会在末尾加上一个空白符,所以就会变高

posted @   向前、向前  阅读(177)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示