javascript - 单击 Navbar-Toggle 按钮时使页面向下移动

标签 javascript html css twitter-bootstrap navbar

我正在制作一个网站,以便练习我的网络技能,但我遇到了一个问题。问题是当网页在移动设备上时,例如 Navbar 折叠,因此它适合设备,但是当他们单击 Navbar-Toggle 按钮时,链接出现在我拥有的标题顶部,我不希望这样发生。我想要发生的是,当他们点击它时,如果您理解我的意思,它会将所有元素向下移动。

如果你不去这个网站 -> www.thestartupguys.co.uk <- 并缩小页面直到它变成你必须切换导航栏然后切换它的地方,你会看到标题图像向下移动.

Standard CSS Custom CSS

最佳答案

这些规则导致了它:参见工作示例。

移除 height: 50 和 margin-top: 20px

.navbar-brand img,
.navbar-nav {
    margin-top: 20px;
    display: inline;
    text-transform: uppercase;
    height: 50px;
}

移除高度:90px

.navbar-default {
    font-family: 'Raleway', sans-serif;
    height: 90px;
    background-color: #fff;
    box-shadow: 0px 2px 20px 0px rgba(0, 0, 0, 0.25);
}

@import url(https://fonts.googleapis.com/css?family=Raleway:100, 200, 300, 400, 500, 600, 700, 800, 900);
@import url(https://fonts.googleapis.com/css?family=Lato);

/*!
Main Page CSS || Created By Stephen Hinett | Crafted-Solutions
 */

* {
  margin: 0px;
  padding: 0px;
}
/*
 
* BASIC STYLE
- Headers and Paragraphs
 
* GLOBAL STYLE
- Navbar
- Header
 
*/

/*===========================================================================================*/

/* Headings & Paragraphs ------------------------- */

/*===========================================================================================*/

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: 'Raleway', sans-serif, serif;
  color: #474747;
}
p {
  color: #9E9E9E;
  font-family: 'Raleway', sans-serif, serif;
}
/*===========================================================================================*/

/* Navbar ------------------------- */

/*===========================================================================================*/

.navbar.navbar-default {
  font-family: 'Raleway', sans-serif;
  background-color: #fff;
  box-shadow: 0px 2px 20px 0px rgba(0, 0, 0, 0.25);
}
.navbar.navbar-default .navbar-nav {
  font-size: 0.9em;
}
.navbar .navbar-brand img,
.navbar-nav {
  display: inline;
  text-transform: uppercase;
  height: 50px;
}
.navbar.navbar-default .navbar-nav>li.active>a {
  font-weight: 600;
  text-decoration: underline;
}
.navbar.navbar-default .navbar-nav>li>a:hover,
.navbar.navbar-default .navbar-nav>li>a:focus {
  font-weight: 600;
  background-color: transparent;
  text-decoration: underline;
}
/*===========================================================================================*/

/* Header ------------------------- */

/*=
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>

      </button> <a class="navbar-brand" href="#">Brand</a>

    </div>
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a>

        </li>
        <li><a href="#">Link</a>

        </li>
      </ul>
    </div>
    <!-- /.navbar-collapse -->
  </div>
  <!-- /.container-fluid -->
</nav>
<div class="container">
  <div class="alert alert-info">Something</div>
  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
    took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
    sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
    standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the
    printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,
    but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker
    including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled
    it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
    and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since
    the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in
    the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting
    industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic
    typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem
    Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
    took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
    sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
    standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the
    printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,
    but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker
    including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled
    it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
    and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since
    the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in
    the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

关于javascript - 单击 Navbar-Toggle 按钮时使页面向下移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32908480/

相关文章:

javascript - 在特定索引处使用 .replace()

javascript - 如何通过 JavaScript 在新浏览器窗口中仅打开外部链接?

html - Schema.org 电话​​链接是否需要包装跨度元素?

html - 文本对齐中心在 IE 中不起作用

html - <body> 在我将样式添加到 Bootstrap nav { position :fixed } 时下降

css - 应用默认样式和 onClick 更改按钮的样式-Angular 4

php - 如何在 PHP 中回显原始 HTML?

javascript - 扩展功能以防止在输入字段内粘贴

html - 您如何克服 HTML 表单嵌套限制?

html - 将鼠标悬停在底部时更改 div 的高度