如何使导航按钮按顺序移动响应和崩溃?

时间:2017-10-06 18:41:54

标签: html css twitter-bootstrap-3 responsive-design navbar

我用不同的方法尝试了几个小时,让我的导航按钮移动响应,并以指定的垂直顺序折叠。一旦屏幕尺寸缩小(大约500px),我希望导航按钮在两个徽标下方的垂直列中折叠。如何修复我的代码来实现这一目标?



.container-fluid {
  border: 1px solid #000000;
  max-width: 1600px;
  overflow: hidden;
}

.wrap {
  /*background-color: yellow;*/
  /*overflow: hidden;*/
}

.Logos {
  width: 312px;
  display: inline-block;
  /*background-color: blue;*/
}


/*
    .Logos img{
    max-width: 300px;
    height: auto;
    }
    */

.nav.wrap.one {
  display: inline-block;
  /*background-color: green;*/
  float: right;
  margin-top: 25px;
}

ul.navigation {
  font: bold 11px "Helvetica Neue", Helvetica, Arial, sans-serif;
  /*text-align center;*/
  /*border: 1px solid green;*/
  /*overflow: hidden;*/
}

.navigation li {
  display: inline-block;
}

.navigation a {
  background: #395870;
  background: linear-gradient(#49708f, #293f50);
  border-right: 1px solid rgba(0, 0, 0, .3);
  color: #fff;
  padding: 12px 20px;
  text-decoration: none;
}

.navigation a:hover {
  background: #314b0;
  box-shadow: inset 0 0 10px 1px rgba(0, 0, 0, .3);
}

.navigation li:first-child a {
  border-radius: 4px 0 0 4px;
}

.navigation li:last-child a {
  border-right: 0;
  border-radius: 0 4px 4px 0;
}

.row.two {
  background-image: url(https://s1.postimg.org/5gvbly4hin/East_Hyde_Park_Chicago_aerial_0470.jpg);
  background-position: absolute;
  background-size: cover;
  background-repeat: no-repeat;
  max-width: 100%;
  height: 550px;
  margin: auto;
}

.floater.box {
  background-color: rgba(255, 255, 255, .40);
  border-radius: 10px;
  /*opacity: .45;*/
  max-width: 75%;
  height: 200px;
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  margin: auto;
  overflow: hidden;
}

.form-search {
  margin: 0 auto;
  text-align: center;
  font: bold 13px sans-serif;
  max-width: 325px;
  position: relative;
}

.form-search input {
  width: 230px;
  box-sizing: border-box;
  border-bottom-left-radius: 2px;
  border-top-left-radius: 2px;
  background-color: #ffffff;
  box-shadow: 1px 2px 4px 0 rgba(0, 0, 0, 0.08);
  padding: 14px 15px 14px 40px;
  border: 1px solid #b6c3cd;
  ;
  border-right: 0;
  color: #4E565C;
  outline: none;
  margin-top: 70px;
  -webkit-appearance: none;
}

.form-search button {
  border-bottom-right-radius: 2px;
  border-top-right-radius: 2px;
  background-color: #6caee0;
  box-shadow: 1px 2px 4px 0 rgba(0, 0, 0, 0.08);
  color: #ffffff;
  padding: 15px 22px;
  margin-left: -4px;
  cursor: pointer;
  border: none;
  outline: none;
}

.form-search i {
  position: absolute;
  top: 15px;
  left: 20px;
  font-size: 16px;
  color: #80A3BD;
}


/* Placeholder color */

.form-search input::-webkit-input-placeholder {
  color: #879097;
}

.form-search input::-moz-placeholder {
  color: #879097;
  opacity: 1;
}

.form-search input:-ms-input-placeholder {
  color: #879097;
}

.nav.wrap.two {
  display: inline-block;
  text-align: center;
  width: 100%;
  margin-top: 10px;
}

<div class="container-fluid">

  <!-- Top Box -->
  <div class="wrap">
    <div class="Logos">
      <img src="https://s26.postimg.org/iqkxecqnd/Coldwell_Banker-_Logo_RS1.jpg" width="150" height="82" class="img-responsive" />
      <img src="https://s26.postimg.org/iqkxecqnd/Coldwell_Banker-_Logo_RS1.jpg" width="150" height="82" class="img-responsive" /> </div>
    <div class="nav wrap one">
      <!--navigation buttons-->
      <ul class="navigation">
        <li id="NAV-ONE"><a href="#">LOG IN</a></li>
        <li id="NAV-TWO"><a href="#">BUY A HOME</a></li>
        <li id="NAV-THREE"><a href="#">SELL A HOME</a></li>
        <li id="NAV-FOUR"><a href="#">CONTACT US</a></li>
      </ul>
    </div>
  </div>

  <!-- Middle Box -->
  <div class="row two">
    <div>
      <div class="floater box">

        <form class="form-search" method="get" action="#">
          <input type="search" name="search" placeholder="I am looking for..">
          <button type="submit">Search</button>
          <i class="fa fa-search"></i>
        </form>

      </div>


    </div>
  </div>
</div>

<!-- Bottom Box -->
<div class="row three">
  <div class="nav wrap two">
    <!--navigation buttons-->
    <ul class="navigation">
      <li id="NAV-A"><a href="#">MY LISTINGS</a></li>
      <li id="NAV-B"><a href="#">COMMUNITIES SERVED</a></li>
      <li id="NAV-C"><a href="#">PROPERTIES</a></li>
    </ul>
  </div>
</div>
</div>
&#13;
&#13;
&#13;

以下是我的CodePen的链接:https://codepen.io/IDCoder/full/rGWeEE/

1 个答案:

答案 0 :(得分:1)

CSS完全是自然顺序,自然位置,自然风格......我的意思是你的代码不是自然的,你可以在这里看到:

.navigation li {
  display: inline-block;

}

.navigation a {
  padding: 12px 20px;
}

我想把我的注意力放在那些属性上,因为我们在这里说:

  

此人中的<a>元素 - &gt; <li><li id="NAV-ONE"><a href="#">LOG IN</a></li>),是的你!即使你在他里面,你也会变得更大!

嗯,在现实生活中,我们不能把更大的东西放到更小的空间里。在现实生活和CSS中发生的事情是: 小事做大事

所以如果我们做出这个改变:

.navigation li {
  display: inline-block;
  padding: 12px 20px;
}

.navigation a {
  /* We changed who is bigger than who */
}

它需要一个自然的顺序(因为现在.navigation a所在的空间比他大)。最终的代码是这样的(这将在你使用手机时换行):

.navigation li {
  display: inline-block;
  padding: 12px 20px;
  background: linear-gradient(#49708f, #293f50);
  background: #395870;
  border-right: 1px solid rgba(0, 0, 0, .3);
}

.navigation a {
  color: #fff;
  text-decoration: none;
}

<强> 更多

我正在玩,当屏幕很小时我发现这种很酷的方式,我觉得很酷:

@media all and (max-width: 500px){
    ul.navigation{
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
    }
}

此外,请记住,当您想要进行自适应设计时,您需要将 meta:viewport 添加到您的HTML头中:

<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">