javascript - 如何在 React.js 中使用溢出:隐藏以及位置:粘性
问题描述
我一直在尝试使用溢出:隐藏,因为我创建的导航栏似乎在我的网页右侧创建了一个空白。我已经使用 Header 组件来创建导航栏。我还希望导航栏处于位置:粘性。我发现我可以使用其中之一,但不能同时使用两者。有没有办法解决?
解决方案
先试试这个。因为你不知道粘性元素和视口边界之间的差距,你可以在你的 css 规则中插入他:
element {
overflow: hidden;
position: sticky;
top: 0; // this will get rid of gap
}
您也可以使用以下。你可能有空间,因为你已经给出了动态宽度,也许你也padding, margin
定义了 etc。如果您发布了代码片段,它会有所帮助,但我已经通过以下方式完成了我的样式。flex-root
被用作显示器也有帮助。只有在上述方法不起作用时才尝试。
// Try CSS attributes:
element {
word-break: break-word;
}
// if you have padding which is creating white space:
element {
width: auto;
padding: 0;
word-break: break-word;
}
// Try this as well
element {
display: flex-root;
}
// display flex guidelines:
// https://developer.mozilla.org/en-US/docs/Web/CSS/display
// The element generates a block element box that establishes a new block formatting
----------
context, defining where the formatting root lies
推荐阅读
- postgresql - 在 Heroku 中连接到 Postgres db 时出错
- c++ - 使用带有 std::condition_variable_any 的虚拟假锁是否安全?
- python - SQL 滚动窗口唯一计数
- jquery - 视频悬停 JQuery 条件 - 检查源是否为视频
- xml - 从添加到 TFS 测试用例工作项的自定义字段中打印文本
- amazon-web-services - 与 Amazon Redshift 同步
- java - Java Spring(页面
.Map(新转换器)) - node.js - async await not working with Node.js gdrive API v3
- swagger-codegen - Is it possible to configure the source code file header generated by swagger-codegen?
- c - Finite State Machines in C