前提・実現したいこと
headerをページの一番上に固定したい。
ここに質問の内容を詳しく書いてください。
HTML&CSSでheaderを固定するためにposition:fixed;を使い、固定することには成功したのですが、headerの下のmain要素がfloatを使った時と同じようにheaderの下に一部潜り込み被ってしまいます。
発生している問題・エラーメッセージ
要素同士の重なり
該当のソースコード
HTML&CSS
試したこと
一度position:fixed;を解除すると被らなくなるので、position:fixed;が原因だと思います。
補足情報(FW/ツールのバージョンなど)
HTML
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="UTF-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 7 <title>Document</title> 8 <link rel="stylesheet" href="stylesheet.css"> 9</head> 10<body> 11 <header> 12 <div class="container"> 13 <div class="header-left"> 14 <img src="images/isaralogo.png" alt="isara" class="header-logo"> 15 <p class="h1">バンコクのノマドエンジニア育成講座</p> 16 </div> 17 <div class="header-right"> 18 <a href="#">お問い合わせ / 資料請求はこちら</a> 19 </div> 20 </div> 21 </header> 22 <div id="wrap"> 23 <section class="top"> 24 <p class="text1">プログラミングで</p> 25 <p class="text1">人生の安定を手にいれよう</p> 26 <img src="images/isaralogolarge.png" alt="isara"> 27 <p class="text2">バンコクのノマドエンジニア育成講座</p> 28 <p class="text2">iSara[イサラ]</p> 29 </section> 30 31 </div> 32</body> 33</html>
CSS
1@charset "utf-8"; 2 3* { 4 box-sizing: border-box; 5 text-decoration: none; 6} 7body { 8 margin:0; 9} 10header { 11 height:75px; 12 width:100%; 13 background-color:white; 14 position:fixed; 15 top:0px; 16} 17header:after { 18 content:""; 19 display:block; 20 clear:both; 21} 22.container { 23 width:1170px; 24 height:75px; 25 margin:0 auto; 26} 27.header-left { 28 float:left; 29 width:400px; 30 height:75px; 31} 32.header-logo { 33 margin-top:17px; 34 width:120px; 35 float:left; 36} 37.header-left .h1 { 38 margin: 37px 0 0 0; 39 font-size: 14px; 40 color: #333333; 41 font-weight:600; 42 letter-spacing: 2px; 43} 44.header-right { 45 float:right; 46 width:320px; 47 height:45px; 48 margin-top:15px; 49 background-color: #da6b64; 50 border-radius:25px; 51} 52.header-right a { 53 line-height: 45px; 54 font-weight:300; 55 font-size: 14px; 56 text-align:center; 57 color:white; 58 letter-spacing: 2px; 59 display:block; 60} 61.header-right:hover { 62 background-color:#dc143c; 63}
回答1件
あなたの回答
tips
プレビュー