css - Bootstrap 4 make the navbar-brand image overlap on big screen & shrink-to-fit on small screen
问题描述
Here's what I'm trying to do. I want to have the navbar-brand image overlapping the navbar without altering it's height (navbar has fixed height of 80px).
It kinda works, however I cannot get the image to fully expose, it's being cut at the top. I tried vertical-align: top
but it just slightly changes the position, the image is still being cut off. I want it to start exactly at the top of the screen, without any padding.
On devices with screens smaller than md
the overlapping image is being hidden and another one is show, which should now be img-fluid
and adjust it's size to the size of the navbar. However when resizing the screen so the navbar collapses, the navbar size remains 80px
but the image starts overlapping it and the collapse-toggler button gets also messed up.
How can I get both of these things to work?
Here's a codepen: https://codepen.io/anon/pen/QYmMyg
Edit: Also, I noticed that setting the navbar to a fixed height actually prevents the collapse from working, because the height is limited. Is there any way I could increase the navbar height and keep the overlapping image and also keep the collapse working?
解决方案
.navbar-brand {
transform: translateY(calc(50% - 40px));
padding-top: 0;
}
...将解决您的问题(40px
高度的一半在哪里.navbar
)。
工作示例:https ://codepen.io/andrei-gheorghiu/pen/pGLrOZ
问题根源于.navbar>.container { align-items: center;}
你不想惹的祸。
Ref: "Edit",这完全是一个不同的问题。在这里回答它对任何有类似问题的人都是有害的,因为它会降低他们找到答案的机会。
避免一次问多个问题。你的问题需要对任何有类似问题的人都有帮助,所以你需要单独问他们。
推荐阅读
- c# - 如何将图像从 Android 传递到我的 API 并将其保存在文件夹中?
- javascript - 将克隆触发器img复制到另一个元素jquery
- c# - C#如何做一个动作队列,其中动作有不同的参数
- angular - 如何仅在垫表的几行上显示编辑图标
- .net-core - Github Action DotNetCore sln 和项目在同一个文件夹中
- python - AttributeError:“str”对象没有“包含”属性
- angular - AWS Codepipeline 使用 --delete 标志部署到 S3
- android - 将两个数据类绑定到一个片段 - Android Kotlin
- algorithm - 查找 XOR 和为零的数组数量
- google-bigquery - 特殊组成员时的 BigQuery 数据集访问