2016-03-27 11 views
1

私は自分のdivを "head" divに入れようとしています。問題は私のイメージと私の "ソーシャル"ヘッダーの間に置くようにしていますが、それだけでオーバーラップしてdivsをプッシュします。私はどのように私はタイトルを作ることができるようにテキストを置くことができるようにそれらの2つの間でそれを中心にすることができますか?入れ子になっているdivがコンテンツをプッシュダウンしているのはなぜですか?

\t body { 
 
    \t \t background : #b3d9ff; 
 
    \t \t margin : 0; 
 
    \t \t padding: 0; 
 
    \t \t font-family : Futura; 
 
    \t } 
 
    \t #wrapper { 
 
    \t \t width: 960px; 
 
    \t \t height: auto; 
 
    \t \t background: #cce5ff; 
 
    \t \t border-left: 5px solid #737373; 
 
    \t \t border-right: 5px solid #737373; 
 
    \t \t overflow : auto; 
 
    \t \t margin : 0 auto; 
 
    \t \t padding: 10px; 
 
    \t } 
 
    \t #header { 
 
    \t \t width:100%; 
 
    \t \t height:100px; 
 
    \t \t border-bottom: 3px solid #000; 
 
    \t \t clear: right; 
 
    \t } 
 
    \t #header > img { 
 
    \t \t margin: 15px 0px 0px 0px; 
 
    \t } 
 
    \t #social { 
 
    \t \t float: right; 
 
    \t \t margin: 20px 30px 0px 0px; 
 
    \t } 
 
    \t #social ul li { 
 
    \t \t float: left; 
 
    \t \t list-style: none; 
 
    \t \t padding-right: 5px; 
 
    \t } 
 
    \t #sidebar { 
 
    \t \t float: left; 
 
    \t \t width: 275px; 
 
    \t \t height: 100%; 
 
    \t } 
 
    \t #menu { 
 
    \t \t float: left; 
 
    \t \t height: auto; 
 
    \t \t width: 200px; 
 
    \t } 
 
    \t #menu ul li { 
 
    \t \t list-style : none; 
 
    \t \t padding: 0px; 
 
    \t \t text-align: center; 
 
    \t } 
 
    \t #menu ul li a { 
 
    \t \t color: #666666; 
 
    \t \t text-decoration: none; 
 
    \t \t display: block; 
 
    \t } 
 
    \t #menu ul li a:visited{ 
 
    \t \t color:purple; 
 
    \t } 
 
    \t #menu ul li a:hover { 
 
    \t \t color:black; 
 
    \t } 
 
    \t #content { 
 
    \t \t float: left; 
 
    \t \t width: 655px; 
 
    \t \t height: 100%; 
 
    \t \t padding-left: 15px; 
 
    \t \t letter-spacing : 1; 
 
    \t \t border-left: 3px solid black; 
 
    \t } 
 
    \t h1 { 
 
    \t \t text-align: center; 
 
    \t \t padding : 5px; 
 
    \t \t border-bottom: 1px solid black; 
 
    \t } 
 
    \t p { 
 
    \t \t text-indent: 50px; 
 
    \t \t line-height: 25px; 
 
    \t } 
 
    \t .top a { 
 
    \t \t color : #666666; 
 
    \t \t text-decoration: none; 
 
    \t } 
 
    \t #readMore { 
 
    \t \t text-align: right; 
 
    \t } 
 
    \t #readMore a:visited { 
 
    \t \t color:purple; 
 
    \t } 
 
    \t #footer { 
 
    \t \t clear: both; 
 
    \t \t width: 100%; 
 
    \t \t height: 80px; 
 
    \t \t color: black; 
 
    \t \t border-top: 3px solid black; 
 
    \t } 
 
    \t h5 { 
 
    \t \t text-align: center; 
 
    \t \t color: #666666; 
 
    \t } 
 
    \t #title { 
 
    \t \t position relative 
 
    \t }
<div id="wrapper"> 
 
    \t <div id="header"> 
 
    \t \t <div id="title"><h2>Title centered in header</h2></div> 
 
    \t \t <a name="top"></a> 
 
    \t \t \t \t <img src="https://janikvonrotz.ch/wp-content/uploads/2015/10/Python-Logo.png" width="232" height="101" alt="Logo" title="python"> 
 
    \t \t <div id="social"> 
 
    \t \t \t <ul> 
 
    \t \t \t \t <li><a href="https://github.com/GallardoBrayan" target="_blank"><img src="http://icons.iconarchive.com/icons/limav/flat-gradient-social/512/Github-icon.png" width="55" height="55"alt="github" title="github"></a></li> 
 
    \t \t \t </ul> 
 
    \t \t </div> <!-- End of social --> 
 
    \t </div> <!-- End of header --> 
 
    \t <div id="sidebar"> 
 
    \t \t <div id="menu"> 
 
    \t \t \t <ul> 
 
    \t \t \t \t <li><h4><a href="index.html">Home</a></h4></li> 
 
    \t \t \t \t <li><h4><a href="overview">Overview</a></h4></li> 
 
    \t \t \t </ul> 
 
    \t \t </div> <!-- End of menu --> 
 
    \t </div> <!-- End of sidebar --> 
 
    \t <div id="content"> 
 
    
 
    <a name="overview"><h1>Overview</h1> 
 
    <pre style="word-wrap: break-word; white-space: pre-wrap;"> 
 
    Sample 
 
    </pre> 
 
    <div class="top"><h4><a href="#top">Back To Top</a></h4></div> 
 
    
 
    
 
    \t </div> <!-- End of content --> 
 
    \t <div id="footer"> 
 
    \t \t <h5>2016 &copy Brayan Rafael Gallardo </br><a href="mailto:?subject=Sample">Contact me</a></h5> 
 
    \t </div> 
 
    </div> <!-- End of wrapper --> 
 
    
 

答えて

1

あなたは、あなたのheaderだけで自動に設定し

100px;の高さをハードコードの単純なミスを犯しました。 title要素のスタイルに: "右フロート" を追加

チェックFiddle

0

してみてください。フレックスボックスを見てみると、このようなアライメントが非常に簡単になり、浮動小数点数よりも頭を上げる方が簡単です。 Here's a great resource to get you started.

0

ので私は私があなたのタイトルの前にそれを置くロゴの位置を変更して、私はそれが場所に悪い習慣であるフレキシボックス

body { 
 
     background : #b3d9ff; 
 
     margin : 0; 
 
     padding: 0; 
 
     font-family : Futura; 
 
    } 
 
    #wrapper { 
 
     width: 960px; 
 
     height: auto; 
 
     background: #cce5ff; 
 
     border-left: 5px solid #737373; 
 
     border-right: 5px solid #737373; 
 
     overflow : auto; 
 
     margin : 0 auto; 
 
     padding: 10px; 
 
    } 
 
    #header { 
 
     width:100%; 
 
     height:100px; 
 
     border-bottom: 3px solid #000; 
 
     clear: right; 
 
     display:flex; 
 
    flex-direction:row; 
 
    justify-content:space-between; 
 
    } 
 
    #header > img { 
 
     margin: 15px 0px 0px 0px; 
 
    } 
 
    #social { 
 
     float: right; 
 
     margin: 20px 30px 0px 0px; 
 
    } 
 
    #social ul li { 
 
     float: left; 
 
     list-style: none; 
 
     padding-right: 5px; 
 
    } 
 
    #sidebar { 
 
     float: left; 
 
     width: 275px; 
 
     height: 100%; 
 
    } 
 
    #menu { 
 
     float: left; 
 
     height: auto; 
 
     width: 200px; 
 
    } 
 
    #menu ul li { 
 
     list-style : none; 
 
     padding: 0px; 
 
     text-align: center; 
 
    } 
 
    #menu ul li a { 
 
     color: #666666; 
 
     text-decoration: none; 
 
     display: block; 
 
    } 
 
    #menu ul li a:visited{ 
 
     color:purple; 
 
    } 
 
    #menu ul li a:hover { 
 
     color:black; 
 
    } 
 
    #content { 
 
     float: left; 
 
     width: 655px; 
 
     height: 100%; 
 
     padding-left: 15px; 
 
     letter-spacing : 1; 
 
     border-left: 3px solid black; 
 
    } 
 
    h1 { 
 
     text-align: center; 
 
     padding : 5px; 
 
     border-bottom: 1px solid black; 
 
    } 
 
    p { 
 
     text-indent: 50px; 
 
     line-height: 25px; 
 
    } 
 
    .top a { 
 
     color : #666666; 
 
     text-decoration: none; 
 
    } 
 
    #readMore { 
 
     text-align: right; 
 
    } 
 
    #readMore a:visited { 
 
     color:purple; 
 
    } 
 
    #footer { 
 
     clear: both; 
 
     width: 100%; 
 
     height: 80px; 
 
     color: black; 
 
     border-top: 3px solid black; 
 
    } 
 
    h5 { 
 
     text-align: center; 
 
     color: #666666; 
 
    } 
 
    #title { 
 
     position relative 
 
     
 
    }
<body> 
 

 
<div id="wrapper"> 
 
    <div id="header"> 
 
    
 
    <img src="https://janikvonrotz.ch/wp-content/uploads/2015/10/Python-Logo.png" width="232" height="101" alt="Logo" title="python"> 
 
     <div id="title"> 
 
     <h2>Title centered in header</h2></div> 
 
     <a name="top"></a> 
 
     <div id="social"> 
 
      <ul> 
 
       <li><a href="https://github.com/GallardoBrayan" target="_blank"><img src="http://icons.iconarchive.com/icons/limav/flat-gradient-social/512/Github-icon.png" width="55" height="55"alt="github" title="github"></a></li> 
 
      </ul> 
 
     </div> <!-- End of social --> 
 
    </div> <!-- End of header --> 
 
    <div id="sidebar"> 
 
     <div id="menu"> 
 
      <ul> 
 
       <li><h4><a href="index.html">Home</a></h4></li> 
 
       <li><h4><a href="overview">Overview</a></h4></li> 
 
      </ul> 
 
     </div> <!-- End of menu --> 
 
    </div> <!-- End of sidebar --> 
 
    <div id="content"> 
 

 
<a name="overview"><h1>Overview</h1> 
 
<pre style="word-wrap: break-word; white-space: pre-wrap;"> 
 
Sample 
 
</pre> 
 
<div class="top"><h4><a href="#top">Back To Top</a></h4></div> 
 

 

 
    </div> <!-- End of content --> 
 
    <div id="footer"> 
 
     <h5>2016 &copy Brayan Rafael Gallardo </br><a href="mailto:?sub

+0

flex:directionは何をしますか?私はあなたのソリューションを使用してみましたが、それでも正しく表示されません。私は崇高なテキストエディタを使用しています。フレックスキーワードは、それが重要であれば残りのように色分けされていません。 – buttonSmasher96

+0

白い場合は正常です!フレックス方向は何をするのですか:この場合、私は行を使用して、1行ですべてを欲しいと悲しく思っています:justify-content:space-between; 3との間のスペースは同じなので、タイトルは真ん中にとどまります。フレックスボックスは本当に良いです。私はそれを使って作業したいのです – DanyCode

0

でそれを中心に何をしました必須ではないハードコーデッド値(ブラウザのウィンドウサイズに応じて変更する余白など)では、em、vw、%の値を可能な限り使用します。構造化にはHTMLを厳密に使用してください。コードに高さや幅などを入れないでください。このようなスタイリングの目的では、常にCSSを使用してください。

@Romanの言ったようにヘッダーを100pxに設定しないでください。本当に悪いです。 position: relative; float:left;display: inline-block;を使用すると、title、social、およびimg insideヘッダーの目的の結果が得られます。ここで

はコードです:ウルは、他の2つのものの間で何かを維持しようとSTHの間にかなっを維持しようとしたとき

body { 
 
    \t \t background : #b3d9ff; 
 
    \t \t margin : 0; 
 
    \t \t padding: 0; 
 
    \t \t font-family : Futura; 
 
    \t } 
 
    \t #wrapper { 
 
    \t \t width: 960px; 
 
    \t \t height: auto; 
 
    \t \t background: #cce5ff; 
 
    \t \t border-left: 5px solid #737373; 
 
    \t \t border-right: 5px solid #737373; 
 
    \t \t overflow : auto; 
 
    \t \t margin : 0 auto; 
 
    \t \t padding: 10px; 
 
    \t } 
 
    \t #header { 
 
    \t \t width:100%; 
 
    \t \t height:auto; 
 
    \t \t border-bottom: 3px solid #000; 
 
    \t \t clear: right; 
 
    \t } 
 
    \t #header > img { 
 
    \t \t margin: 1em 0 0 0; 
 
      width: 232px; 
 
      height: 101px; 
 
      position: relative; 
 
      float:left; 
 
    \t } 
 
    \t #social { 
 
    \t position: relative; 
 
    \t \t float: right; 
 
      display:inline-block; 
 
    \t \t margin: 1em 1.2em 0 0; 
 
    \t } 
 
     
 
    \t #social ul li { 
 
    \t \t float: left; 
 
    \t \t list-style: none; 
 
    \t \t padding-right: 5px; 
 
    \t } 
 
    \t #sidebar { 
 
    \t \t float: left; 
 
    \t \t width: 275px; 
 
    \t \t height: 100%; 
 
    \t } 
 
    \t #menu { 
 
    \t \t float: left; 
 
    \t \t height: auto; 
 
    \t \t width: 200px; 
 
    \t } 
 
    \t #menu ul li { 
 
    \t \t list-style : none; 
 
    \t \t padding: 0px; 
 
    \t \t text-align: center; 
 
    \t } 
 
    \t #menu ul li a { 
 
    \t \t color: #666666; 
 
    \t \t text-decoration: none; 
 
    \t \t display: block; 
 
    \t } 
 
    \t #menu ul li a:visited{ 
 
    \t \t color:purple; 
 
    \t } 
 
    \t #menu ul li a:hover { 
 
    \t \t color:black; 
 
    \t } 
 
    \t #content { 
 
    \t \t float: left; 
 
    \t \t width: 655px; 
 
    \t \t height: 100%; 
 
    \t \t padding-left: 15px; 
 
    \t \t letter-spacing : 1; 
 
    \t \t border-left: 3px solid black; 
 
    \t } 
 
    \t h1 { 
 
    \t \t text-align: center; 
 
    \t \t padding : 5px; 
 
    \t \t border-bottom: 1px solid black; 
 
    \t } 
 
    \t p { 
 
    \t \t text-indent: 50px; 
 
    \t \t line-height: 25px; 
 
    \t } 
 
    \t .top a { 
 
    \t \t color : #666666; 
 
    \t \t text-decoration: none; 
 
    \t } 
 
    \t #readMore { 
 
    \t \t text-align: right; 
 
    \t } 
 
    \t #readMore a:visited { 
 
    \t \t color:purple; 
 
    \t } 
 
    \t #footer { 
 
    \t \t clear: both; 
 
    \t \t width: 100%; 
 
    \t \t height: 80px; 
 
    \t \t color: black; 
 
    \t \t border-top: 3px solid black; 
 
    \t } 
 
    \t h5 { 
 
    \t \t text-align: center; 
 
    \t \t color: #666666; 
 
    \t } 
 
    \t #title { 
 
    \t \t position relative; 
 
      float:left; 
 
      margin: 1.1em 0 0 7em; 
 
    \t }
<div id="wrapper"> 
 
    \t <div id="header"> 
 
     <img src="https://janikvonrotz.ch/wp-content/uploads/2015/10/Python-Logo.png" alt="Logo" title="python"> 
 
    \t \t <div id="title"><h2>Title centered in header</h2></div> 
 
    \t \t <a name="top"></a> 
 
    \t \t \t \t 
 
    \t \t <div id="social"> 
 
    \t \t \t <ul> 
 
    \t \t \t \t <li><a href="https://github.com/GallardoBrayan" target="_blank"><img src="http://icons.iconarchive.com/icons/limav/flat-gradient-social/512/Github-icon.png" width="55" height="55"alt="github" title="github"></a></li> 
 
    \t \t \t </ul> 
 
    \t \t </div> <!-- End of social --> 
 
    \t </div> <!-- End of header --> 
 
    \t <div id="sidebar"> 
 
    \t \t <div id="menu"> 
 
    \t \t \t <ul> 
 
    \t \t \t \t <li><h4><a href="index.html">Home</a></h4></li> 
 
    \t \t \t \t <li><h4><a href="overview">Overview</a></h4></li> 
 
    \t \t \t </ul> 
 
    \t \t </div> <!-- End of menu --> 
 
    \t </div> <!-- End of sidebar --> 
 
    \t <div id="content"> 
 
    
 
    <a name="overview"><h1>Overview</h1> 
 
    <pre style="word-wrap: break-word; white-space: pre-wrap;"> 
 
    Sample 
 
    </pre> 
 
    <div class="top"><h4><a href="#top">Back To Top</a></h4></div> 
 
    
 
    
 
    \t </div> <!-- End of content --> 
 
    \t <div id="footer"> 
 
    \t \t <h5>2016 &copy Brayan Rafael Gallardo </br><a href="mailto:?subject=Sample">Contact me</a></h5> 
 
    \t </div> 
 
    </div> <!-- End of wrapper --> 
 

0

は... [OK]を...使用表示:同じ行に他の要素を置くためのインラインブロック...ソーシャルイメージを右にしたいから...ディスプレイを使う:#titleとfloatでインラインブロック:右に社会イメージ

 #wrapper { 
     width: 960px; 
     height: auto; 
     background: #cce5ff; 
     border-left: 5px solid #737373; 
     border-right: 5px solid #737373; 
     overflow : auto; 
     margin : 0 auto; 
     padding: 10px; 
    } 
    #header { 
     width:100%; 
     height:100px; 
     border-bottom: 3px solid #000; 
     display:inline-block; 

    } 
    #header > img { 
     float:left; 
     margin: 15px 0px 0px 0px; 
    } 

    #title{ 
     width:50%; 
     text-align:center; 
     display:inline-block; 
    } 

    #social { 
     float: right; 
     margin: 20px 30px 0px 0px; 
    } 


<div id="header"> 
     <div id="title"><h2>Title centered in header</h2></div> 
     <a name="top"></a> 
       <img src="your image" width="232" height="101" alt="Logo" title="python"> 

     <div id="social"> 
      <a href="https://github.com/GallardoBrayan" target="_blank"><img src="http://icons.iconarchive.com/icons/limav/flat-gradient-social/512/Github-icon.png" width="55" height="55"alt="github" title="github"></a>   
     </div> <!-- End of social --> 
    </div> 
関連する問題