css - Why can't I margin the div, why do I have to margin the child to margin the div?
问题描述
This has 2 fixes...which is really weird to me.
1: If I remove the tag #MARGIN-30 and Remove the tag #Nav-bar under margin-3 it fixes itself when I reapply said tags.
2: If I add overflow:hidden;
The question is, is anyone able to assist me with the reason for this happening, like...I've never had this on any prior project or learning experience with css.
解决方案
It appears as though you are falling victim to Margin Collapse. It's just one of those many things that are a bit weird in HTML/CSS.
The top and bottom margins of blocks are sometimes combined (collapsed) into a single margin whose size is the largest of the individual margins (or just one of them, if they are equal), a behavior known as margin collapsing. Note that the margins of floating and absolutely positioned elements never collapse.
推荐阅读
- django - 当我使用 docker 和 nginx 在服务器上部署时,django 项目中的动态媒体出现问题
- python - Azure KeyVault:get_secret() - Python TypeError:字符串索引必须是整数
- javascript - 如何删除 localStorage 键中存在的选定对象项?
- assembly - 同一指令中的屏蔽和未屏蔽 FP 异常:在处理未屏蔽异常之前是否在 MXCSR 中设置了所有位?
- dictionary - 有没有办法将字典连接到 linux 中的 pdf 阅读器?
- python - 在 Python 中使用 OpenCV 而不是 Picamera 在 RPi 零野生动物相机中使用网络摄像头
- android - React Native Android 应用程序无法正确加载 JS 包
- snowflake-cloud-data-platform - 性能问题 - 基于 row_num 更新空列
- javascript - 在 head 标签 Nuxt Js 中的每个页面上运行一个函数
- terraform - Terraform:如何为动态用例改变块/集?