如何在“navbar”折叠(Bootstrap)时使按钮拉伸?

时间:2017-08-22 00:05:37

标签: jquery html css twitter-bootstrap

JSFiddle,https://jsfiddle.net/4tusk977/

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
</head>
<body>
  <div class="container-fluid">
    <nav class="navbar navbar-default">
      <div class="navbar-header">
        <a class="navbar-brand" href="#">...</a>
        <button aria-expanded="false" class="collapsed navbar-toggle" data-target="#main_menu" data-toggle="collapse" type="button">
          <span class="sr-only">toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
      </div>
      <div class="collapse navbar-collapse" id="main_menu">
        <form class="navbar-form navbar-right" id="main_menu_form" style="border: none;">
          <input class="form-control" type="text" name="username" placeholder="User name">
          <input class="form-control" type="password" name="password" placeholder="Password">
          <input class="btn btn-success" type="button" value="sign in">
          <input class="btn btn-primary" type="button" value="sign up">
        </form>
      </div>
    </nav>
  </div>
  <script src="bower_components/jquery/dist/jquery.js"></script>
  <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
</body>
</html>

我想要在折叠导航栏时同等地拉伸“登录”和“注册”按钮。我尝试过使用弹性盒,但它成功了,但是当导航栏没有折叠时它也会破坏布局。我该怎么办?

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以使用@media css规则根据特定属性(如屏幕)设置选择器的值。

@media screen and (max-width: 768px) {
  .navbar-collapse input[type="submit"] {
    width: 49%;
  }
}

这是你的jsfiddle:
https://jsfiddle.net/4tusk977/2/