【问题标题】:Why sticky header is not working in form tags when I use bootstrap 4?为什么当我使用引导程序 4 时,粘性标题在表单标签中不起作用?
【发布时间】:2019-03-18 10:29:09
【问题描述】:

为什么表单输入或按钮与我的导航标题重叠? 当我不使用引导程序 4 时,它可以正常工作。

我希望标题位于我网站中所有对象的顶部。

有没有办法只使用引导程序而不使用额外的 Javascript 来解决这个问题?

Image Error:

window.onscroll = function() {myFunction()};

var header = document.getElementById("myHeader");
var sticky = header.offsetTop;

function myFunction() {
  if (window.pageYOffset > sticky) {
    header.classList.add("sticky");
  } else {
    header.classList.remove("sticky");
  }
}
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

.top-container {
  background-color: #f1f1f1;
  padding: 30px;
  text-align: center;
}

.header {
  padding: 10px 16px;
  background: #555;
  color: #f1f1f1;
}

.content {
  padding: 16px;
}

.sticky {
  position: fixed;
  top: 0;
  width: 100%;
}

.sticky + .content {
  padding-top: 102px;
}

.form-control {
	width: 40%;
}
<div class = "container-fluid">
<div class="top-container">
<h1>Main Header</h1>
<p>Scroll down to see the sticky effect.</p>
</div>

<div class="header" id="myHeader">
<h2 class = "navbar fixed-top">Navigation Header</h2>
</div>

<div class="content">
		
<div class = "row">
  <div class = "col-sm-12">
    <form action = "#" method = "post">
      <div class = "form-group">
        <label>Name:</label>
         <input type = "text" name = "name" class = "form-control" />
       </div>
     </form>
</div>
</div>
					

【问题讨论】:

    标签: javascript html css bootstrap-4


    【解决方案1】:

    设置位置固定顶...中殿栏

    【讨论】:

    • class="navbar 固定顶
    • 使用这个引导类.. 你的 css
    • 谢谢,但它与主标题重叠。这是我的设置主标题 - 导航标题(这应该是粘性或固定部分) - 然后是内容 - 然后是页脚
    猜你喜欢
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 2021-06-12
    • 2019-04-03
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多