2017-02-21 13 views
1

ブラウザの画面が最大化されると、ヘッダーはラップトップコンピュータで完全に機能します。しかし、ブラウザ画面のサイズが変更されたときに応答しなくなり、ポストボタンが消えて検索ボタンの位置が変更され、モバイルの応答性がチェックされたときは完全に置き換えられます。ヘッダーを反応させるには?

.navbar-fixed-top{ 
 
    -webkit-box-shadow: 0 6px 6px -6px red; 
 
    -moz-box-shadow: 0 6px 6px -6px red; 
 
    box-shadow: 0 6px 6px -6px red; 
 
    background: rgba(192, 192, 192, 0.1) 
 
} 
 

 
#logo{ 
 
\t margin-top: -5px; 
 
} 
 

 
/*Search field*/ 
 
#search{ 
 
     
 
     font: 13px 'Lucida sans', Arial, Helvetica; 
 
     color: #eee; 
 
     text-align: center; 
 
    } 
 
    
 
#search a { 
 
     color: #ccc; 
 
    } 
 
    
 
    /*-------------------------------------*/ 
 
    
 
    .cf:before, .cf:after{ 
 
     content:""; 
 
     display:table; 
 
    } 
 
    
 
    .cf:after{ 
 
     clear:both; 
 
    } 
 

 
    .cf{ 
 
     zoom:1; 
 
    } 
 

 
    /*-------------------------------------*/ \t 
 
    
 
    .form-wrapper{ 
 
     height :60px; 
 
    } 
 
    
 
    .form-wrapper input { 
 
     width: 500px; 
 
     height: 40px; 
 
     padding: 10px 5px; 
 
     float: left;  
 
     font: bold 15px 'lucida sans', 'trebuchet MS', 'Tahoma'; 
 
     border: 0; 
 
     margin-top: 10px; 
 
     margin-left: 150px; 
 
     background: #eee; 
 
     -moz-border-radius: 3px 0 0 3px; 
 
     -webkit-border-radius: 3px 0 0 3px; 
 
     border-radius: 3px 0 0 3px;  
 
    } 
 
    
 
    .form-wrapper input:focus { 
 
     outline: 0; 
 
     background: #fff; 
 
     -moz-box-shadow: 0 0 2px rgba(0,0,0,.8) inset; 
 
     -webkit-box-shadow: 0 0 2px rgba(0,0,0,.8) inset; 
 
     box-shadow: 0 0 2px rgba(0,0,0,.8) inset; 
 
    } 
 
    
 
    .form-wrapper input::-webkit-input-placeholder { 
 
     color: #999; 
 
     font-weight: normal; 
 
     
 
    } 
 
    
 
    .form-wrapper input:-moz-placeholder { 
 
     color: #999; 
 
     font-weight: normal; 
 
     
 
    } 
 
    
 
    .form-wrapper input:-ms-input-placeholder { 
 
     color: #999; 
 
     font-weight: normal; 
 
     
 
    }  
 
    
 
    .form-wrapper button { 
 
\t \t overflow: visible; 
 
     position: relative; 
 
     
 
     border: 0; 
 
     padding: 0; 
 
     cursor: pointer; 
 
     height: 40px; 
 
     width: 110px; 
 
     font: bold 15px/40px 'lucida sans', 'trebuchet MS', 'Tahoma'; 
 
     color: #fff; 
 
     text-transform: uppercase; 
 
     background: #d83c3c; 
 
     -moz-border-radius: 0 3px 3px 0; 
 
     -webkit-border-radius: 0 3px 3px 0; 
 
     border-radius: 0 3px 3px 0;  
 
     text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3); 
 
     top:-40px !important; 
 
     margin-left: 373px; 
 
    } 
 
     
 
    .form-wrapper button:hover{ \t \t 
 
     background: #e54040; 
 
    } \t 
 
     
 
    .form-wrapper button:active, 
 
    .form-wrapper button:focus{ 
 
     background: #c42f2f;  
 
    } 
 
    
 
    
 
    
 
    .form-wrapper button:hover:before{ 
 
     border-right-color: #e54040; 
 
    } 
 
    
 
    .form-wrapper button:focus:before{ 
 
     border-right-color: #c42f2f; 
 
    }  
 
    
 
    .form-wrapper button::-moz-focus-inner { 
 
     border: 0; 
 
     padding: 0; 
 
    } 
 

 
/*End of search style*/ 
 

 
/* post button*/ 
 
.post{ 
 
    height:5px; 
 
} 
 
.post button { 
 
     overflow: visible; 
 
     position: relative; 
 
     
 
     border: 0; 
 
     padding: 0; 
 
     cursor: pointer; 
 
     height: 40px; 
 
     width: 110px; 
 
     font: bold 15px/40px 'lucida sans', 'trebuchet MS', 'Tahoma'; 
 
     color: #fff; 
 
     text-transform: uppercase; 
 
     background: #d83c3c; 
 
     -moz-border-radius: 3px 3px 3px 3px; 
 
     -webkit-border-radius: 3px 3px 3px 3px; 
 
     border-radius: 3px 3px 3px 3px;  
 
     text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3); 
 
     top:-49px !important; 
 
     margin-left: 1100px; 
 
    } 
 

 
    .post{ 
 
     width: 100% 
 
    } 
 
     
 
    .post button:hover{  
 
     background: #e54040; 
 
    } 
 
     
 
    .post button:active, 
 
    .post button:focus{ 
 
     background: #c42f2f;  
 
    } 
 
    
 
    
 
    
 
    .post button:hover:before{ 
 
     border-right-color: #e54040; 
 
    } 
 
    
 
    .post button:focus:before{ 
 
     border-right-color: #c42f2f; 
 
    }  
 
    
 
    .post button::-moz-focus-inner { 
 
     border: 0; 
 
     padding: 0; 
 
    }
<nav class="navbar navbar-fixed-top"> 
 
    <div class="container-fluid"> 
 
    <div class="navbar-header"> 
 
     <a class="navbar-brand" href="#"><img src="images/logo.svg" id="logo"></a> 
 
    </div> 
 

 

 
    <div id="search"> 
 
    <form class="form-wrapper cf"> 
 
\t <input type="text" placeholder="Search here..." required> 
 
\t <button type="submit">Search</button> 
 
\t </form> 
 
\t </div> 
 
\t <div class="post"> 
 
\t <button type="submit">POST</button> 
 
\t </div> 
 
    </div> 
 
</nav> 
 

enter image description here

+1

が追加できるすべてのデバイスのために働く私のコードを使用して簡単に見るそのフレックスで試してみてくださいどのように動作するかを取得ホープplunkrや他のオープンコードへのコードはどこで編集して遊べますか? – Smit

+0

https://plnkr.co/edit/VFA33I7TjJy2aYysZpBL?p = preview –

+0

** **ヘッダー**を意味しますか?どのヘッダ? ** THE **何かのようなことはありません – vsync

答えて

0

あなたはCSSで@mediaアノテーションを使用することができ、またはあなたは、ブートストラップのフレームワークを使用することができます。

@media only screen and (max-width: 768px) { 
    /*For mobile or iPad*/ 
    .post { 
     width: 100%; 
    } 
} 
+1

これは間違っています - 既にコード内にありますが、これでボタン上に余白が残っています:1100px; –

0

css media queriesについて聞いたことがありますか?私はあなたがそれら(単純なGoogleの検索が行うだろう)を読んでアドバイスしない場合。メディアクエリは、オプションのメディアタイプと、メディア機能を使用してスタイルシートの範囲を制限する0個以上の式で構成されています。 media queriesを使用して、cssに特定の画面サイズで特定のものを表示または再配置するよう指示することができます。これはquery画面サイズが500px未満の場合100%.size widthを変更し、画面サイズを超える500px

read more here

あなたは可能性がある場合50%に戻すだろう

.size { 
    width: 50%; 
} 

@media only screen and (min-width: 160px) and (max-width: 500px) { 
    .size { 
     width: 100%; 
    } 
} 

例えば

のような応答可能なフレームワークを試してみてください3210

bootstrap

例を示すためにコードの一部を編集しましたが、メディアクエリを学ぶことをお勧めします。

あなたのCSS

.navbar-fixed-top{ 
    -webkit-box-shadow: 0 6px 6px -6px red; 
    -moz-box-shadow: 0 6px 6px -6px red; 
    box-shadow: 0 6px 6px -6px red; 
    background: rgba(192, 192, 192, 0.1) 
} 

#logo{ 
    margin-top: -5px; 
} 

/*Search field*/ 
#search{ 

    font: 13px 'Lucida sans', Arial, Helvetica; 
    color: #eee; 
    text-align: center; 
} 

#search a { 
    color: #ccc; 
} 

/*-------------------------------------*/ 

.cf:before, .cf:after{ 
    content:""; 
    display:table; 
} 

.cf:after{ 
    clear:both; 
} 

.cf{ 
    zoom:1; 
} 

/*-------------------------------------*/ 
/*EDITTED*/ 
.form-wrapper{ 
    height :50px; 
    width: 100%; 
} 

/*EDITTED*/ 
.form-wrapper input { 
    width: 500px; 
    height: 40px; 
    float: left; 
    padding: 0 0 0 5px;  
    font: bold 15px 'lucida sans', 'trebuchet MS', 'Tahoma'; 
    border: 0; 
    margin-left: 150px; 
    background: #eee; 
    -moz-border-radius: 3px 0 0 3px; 
    -webkit-border-radius: 3px 0 0 3px; 
    border-radius: 3px 0 0 3px;  
} 

.form-wrapper input:focus { 
    outline: 0; 
    background: #fff; 
    -moz-box-shadow: 0 0 2px rgba(0,0,0,.8) inset; 
    -webkit-box-shadow: 0 0 2px rgba(0,0,0,.8) inset; 
    box-shadow: 0 0 2px rgba(0,0,0,.8) inset; 
} 

.form-wrapper input::-webkit-input-placeholder { 
    color: #999; 
    font-weight: normal; 
} 

.form-wrapper input:-moz-placeholder { 
    color: #999; 
    font-weight: normal; 
} 

.form-wrapper input:-ms-input-placeholder { 
    color: #999; 
    font-weight: normal; 
}  

.form-wrapper button { 
    overflow: visible; 
    position: relative; 

    border: 0; 
    padding: 0; 
    cursor: pointer; 
    height: 40px; 
    width: 110px; 
    font: bold 15px/40px 'lucida sans', 'trebuchet MS', 'Tahoma'; 
    color: #fff; 
    text-transform: uppercase; 
    background: #d83c3c; 
    -moz-border-radius: 0 3px 3px 0; 
    -webkit-border-radius: 0 3px 3px 0; 
    border-radius: 0 3px 3px 0;  
    text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3); 
    float: left; 
} 

.form-wrapper button:hover{  
    background: #e54040; 
} 

.form-wrapper button:active, 
.form-wrapper button:focus{ 
    background: #c42f2f;  
} 



.form-wrapper button:hover:before{ 
    border-right-color: #e54040; 
} 

.form-wrapper button:focus:before{ 
    border-right-color: #c42f2f; 
}  

.form-wrapper button::-moz-focus-inner { 
    border: 0; 
    padding: 0; 
} 

/*End of search style*/ 

/* post button*/ 
.post{ 
    height:5px; 
} 
.post button { 
    overflow: visible; 
    position: relative; 

    border: 0; 
    padding: 0; 
    cursor: pointer; 
    height: 40px; 
    width: 110px; 
    font: bold 15px/40px 'lucida sans', 'trebuchet MS', 'Tahoma'; 
    color: #fff; 
    text-transform: uppercase; 
    background: #d83c3c; 
    -moz-border-radius: 3px 3px 3px 3px; 
    -webkit-border-radius: 3px 3px 3px 3px; 
    border-radius: 3px 3px 3px 3px;  
    text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3); 
    top:-49px !important; 
    margin-left: 80%; 
} 


.post{ 
    width: 100% 
} 

.post button:hover{  
    background: #e54040; 
} 

.post button:active, 
.post button:focus{ 
    background: #c42f2f;  
} 



.post button:hover:before{ 
    border-right-color: #e54040; 
} 

.post button:focus:before{ 
    border-right-color: #c42f2f; 
}  

.post button::-moz-focus-inner { 
    border: 0; 
    padding: 0; 
} 

メディアクエリ

@media only screen and (min-width: 160px) and (max-width: 1200px) { 
    .post { 
     clear: both; 
     margin: 50px auto 0 auto; 
     text-align: center; 
     margin-left: -45%; 
    } 
    .container-fluid { 
     height: 120px; 
    } 
} 
@media only screen and (min-width: 160px) and (max-width: 900px) { 
    .form-wrapper input { 
     width: 300px; 
     margin-left: 20%; 
    } 
    } 
@media only screen and (min-width: 160px) and (max-width: 535px) { 
    .form-wrapper input { 
     width: 150px; 
    } 
    .form-wrapper button { 
     width: 100px; 
    } 
} 

HTML

<!--same as question--> 

After query on small screen

あなたは、これが

+0

はい、聞いたことがあります!しかし、それを使用せずに私の体は反応があります。ほとんど変化のないヘッダーは可能ですか? –

+0

申し訳ありませんが、あなたのコードを一瞬見てみましょう –

+0

これは私の完全なコードです:https://plnkr.co/edit/VFA33I7TjJy2aYysZpBL?p=preview –

0

は、そのは

* { 
 
     padding: 0; 
 
     margin: 0; 
 
     box-sizing: border-box; 
 
     outline: none; 
 
     resize: none; 
 
    } 
 
    .navbar-fixed-top{ 
 
     -webkit-box-shadow: 0 6px 6px -6px red; 
 
     -moz-box-shadow: 0 6px 6px -6px red; 
 
     box-shadow: 0 6px 6px -6px red; 
 
     background: rgba(192, 192, 192, 0.1) 
 
    } 
 
    .navbar-brand { 
 
     display:inline-block; 
 
    } 
 
    
 
    /*Search field*/ 
 
    #search{ 
 
     font: 13px 'Lucida sans', Arial, Helvetica; 
 
     color: #eee; 
 
     text-align: center; 
 
    }  
 
    .form-wrapper{ 
 
     display: -webkit-box; 
 
     display: -ms-flexbox; 
 
     display: -webkit-flex; 
 
     display: flex; 
 
     -webkit-box-align: center; 
 
     -webkit-align-items: center; 
 
     -ms-flex-align: center; 
 
     align-items: center; 
 
     
 
     -webkit-box-flex: 2; 
 
     -webkit-flex: 2; 
 
     -ms-flex: 2; 
 
     flex: 2; 
 

 
     padding-left:10px; 
 
     padding-right:10px; 
 

 
     width:100%; 
 
    }  
 
    .form-wrapper input { 
 
     -webkit-box-flex: 2; 
 
     -webkit-flex: 2; 
 
     -ms-flex: 2; 
 
     flex: 2; 
 
     
 
     height: 40px; 
 
     padding: 10px 5px; 
 
     font: bold 15px 'lucida sans', 'trebuchet MS', 'Tahoma'; 
 
     border: 0; 
 
     background: #eee; 
 
     -moz-border-radius: 3px 0 0 3px; 
 
     -webkit-border-radius: 3px 0 0 3px; 
 
     border-radius: 3px 0 0 3px;  
 
    }  
 
    .form-wrapper input:focus { 
 
     outline: 0; 
 
     background: #fff; 
 
     -moz-box-shadow: 0 0 2px rgba(0,0,0,.8) inset; 
 
     -webkit-box-shadow: 0 0 2px rgba(0,0,0,.8) inset; 
 
     box-shadow: 0 0 2px rgba(0,0,0,.8) inset; 
 
    } 
 
    
 
    .form-wrapper input:-moz-placeholder, 
 
    .form-wrapper input:-ms-input-placeholder, 
 
    .form-wrapper input::-webkit-input-placeholder { 
 
     color: #999; 
 
     font-weight: normal; 
 
    } 
 

 
    .btn-style { 
 
     overflow: visible; 
 
     position: relative; 
 
     
 
     border: 0; 
 
     padding: 0 16px; 
 
     cursor: pointer; 
 
     height: 40px; 
 
     font: bold 15px/40px 'lucida sans', 'trebuchet MS', 'Tahoma'; 
 
     color: #fff; 
 
     text-transform: uppercase; 
 
     background: #d83c3c; 
 
     -moz-border-radius: 0 3px 3px 0; 
 
     -webkit-border-radius: 0 3px 3px 0; 
 
     border-radius: 0 3px 3px 0;  
 
     text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3); 
 
    } 
 
    .btn-style:hover{ 
 
     background: #e54040; 
 
    } 
 
    .btn-style:active, 
 
    .btn-style:focus{ 
 
     background: #c42f2f;  
 
    } 
 
    .btn-style:hover:before{ 
 
     border-right-color: #e54040; 
 
    } 
 
    .btn-style:focus:before{ 
 
     border-right-color: #c42f2f; 
 
    } 
 
    .btn-style::-moz-focus-inner { 
 
     border: 0; 
 
     padding: 0; 
 
    } 
 

 
    .container-fluid { 
 
     display: -webkit-box; 
 
     display: -ms-flexbox; 
 
     display: -webkit-flex; 
 
     display: flex; 
 
     -webkit-box-align: center; 
 
     -webkit-align-items: center; 
 
     -ms-flex-align: center; 
 
     align-items: center; 
 
     padding:16px; 
 
    } 
 

 
    form { 
 
     margin: 0; 
 
     display:block; 
 
    } 
 
    
 
    @media only screen and (max-width: 767px) { 
 
     .container-fluid { 
 
      -webkit-box-orient: vertical; 
 
      -webkit-box-direction: normal; 
 
      -ms-flex-direction: column; 
 
      flex-direction: column; 
 
      height: 144px; 
 
     } 
 
    }
<nav class="navbar navbar-fixed-top"> 
 
    <div class="container-fluid"> 
 
     <a class="navbar-brand" href="#"><img src="https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" id="logo" width="100"></a> 
 
     
 
     <form class="form-wrapper"> 
 
      <input type="text" placeholder="Search here..." required> 
 
      <button class="btn-style" type="submit">Search</button> 
 
     </form> 
 

 
     <div class="post"> 
 
      <button class="btn-style" type="submit">POST</button> 
 
     </div> 
 
    </div> 
 
</nav>

関連する問題