2017-12-29 10 views
0

私は自分のウェブサイトの真ん中にいくつかのコンテンツボックスを配置しようとしていますが、次のようなものを中心に置くときはいつでも、それは適切に中心に見えません。だから私はどのようにこれらのコンテンツボックスを適切に配置し、正しい方向に私を向けることができるか知っていますか?ありがとう。グループ内のすべてのコンテンツを中心に並べることなくグループコンテンツを整列するにはどうすればよいですか?

'top:50%; bottom:50%; 、変換:変換(-50%、-50%);これを達成する

body { 
 
     background-color: #323232; 
 
     max-width: 960px; 
 
     padding: 0; 
 
     margin: 0; 
 
     font-family: Lato; 
 
     } 
 

 
     nav a { 
 
     color: #fff; 
 
     text-decoration: none; 
 
     padding: 20px 25px; 
 
     display: inline-block; 
 
     } 
 

 
     .fixed-header, .fixed-footer { 
 
     background: #333; 
 
     color: #fff; 
 
     width: 100%; 
 
     position: fixed; 
 
     text-align: center; 
 
     z-index: 10; 
 
     background-color: #202020; 
 
     } 
 

 
     .fixed-header { 
 
     top: 0; 
 
     } 
 

 
     .fixed-footer { 
 
     bottom: 0; 
 
     padding: 20px 0px; 
 
     } 
 

 
     .fixed-header a:hover { 
 
     color: #c1c1c1; 
 
     } 
 

 
     .fixed-footer a { 
 
     color: #fff; 
 
     font-weight: lighter; 
 
     text-decoration: none; 
 
     } 
 

 
     .group-content { 
 
     max-width: 960px; 
 
     text-align: center; 
 
     margin-bottom: 4px; 
 
     display: flex; 
 
     flex-wrap: wrap; 
 
     justify-content: space-evenly; 
 

 
     } 
 

 
     .group-content h3 { 
 
     margin-top: 10px; 
 
     font-weight: normal; 
 
     font-size: 20px; 
 
     color: white; 
 
     } 
 

 
     .group-content p { 
 
     margin-top: 3px; 
 
     font-weight: lighter; 
 
     font-size: 20px; 
 
     color: white; 
 
     } 
 

 
     .content { 
 
     width: 30%; 
 
     background-color: #202020; 
 
     display: flex; 
 
     flex-direction: column; 
 
     padding: 20px 0 20px 0; 
 
     align-items: center; 
 
     margin-top: 20px; 
 
     } 
 

 
     .content >* { 
 
     max-width: 200px; 
 
     text-align: center; 
 
     margin: 0; 
 
     }
<!DOCTYPE html> 
 

 
    <html lang="en"> 
 

 
    <head> 
 
     <title>Kumo99.cf</title> 
 
     <meta charset="UTF-8"> 
 
     <link rel="stylesheet" type="text/css" href="css/style.css"> 
 
     <link rel="icon" href="favicon.ico"> 
 
    </head> 
 

 
    <body> 
 

 
    <div class="fixed-header"> 
 
     <nav> 
 
     <a href="index.html">HOME</a> 
 
     <a href="projects.html">PROJECTS</a> 
 
     <a href="about.html">ABOUT</a> 
 
     </nav> 
 
    </div> 
 

 
    <div class="fixed-footer"> 
 
    <a href="https://steamcommunity.com/id/kumo99">Made by Kumo © 2018</a> 
 
    </div> 
 

 
    <div class="group-content"> 
 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Arma 3: Exile Server</h3> 
 
     <p>A project for improving the exile mod.</p> 
 
     </div> 
 

 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Reserved Space</h3> 
 
     <p>Reserved space for future projects</p> 
 
     </div> 
 

 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Reserved Space</h3> 
 
     <p>Reserved space for future projects</p> 
 
     </div> 
 

 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Reserved Space</h3> 
 
     <p>Reserved space for future projects</p> 
 
     </div> 
 

 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Reserved Space</h3> 
 
     <p>Reserved space for future projects</p> 
 
     </div> 
 

 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Reserved Space</h3> 
 
     <p>Reserved space for future projects</p> 
 
     </div> 
 
    </div> 
 

 
    </body> 
 
    </html>

答えて

0

一つの方法は、特定の値、すなわち75%、及び自動水平に中央に「0自動車」であるとマージンのdivの幅を設定することです。あなたの場合は、あなたの体の幅を100%にする必要があります。これは、divが中心に置かれている要素です。あなたの体を100%にしたくない場合は、あなたの体にも0の自動マージンがあるので、ページの中央に配置されます。しかし、これを行うことによって、あなたは他の要素と一緒に遊んで、今のところに戻す必要があります。 .group-内容のマージンは「75px自動」に設定されているか

body { 
    background-color: #323232; 
    width:100%; 
    padding: 0; 
    margin: 0; 
    font-family: Lato; 
} 

.group-content { 
    max-width: 960px; 
    text-align: center; 
    width: 75%; 
    margin: 75px auto; 
    display: flex; 
    flex-wrap: wrap; 
    justify-content: space-evenly; 
} 

お知らせ...以下のCSSを使用して対応するCSSを交換してみてください。これはnavbarとfooterのために75pxの上下のマージンを加えることによって.group-contentがすべて見えることを確かめます。

+0

おかげで、解決策がうまく働いた、しかし、私は100%に幅を変更しました。 –

0

body { 
 
    background-color: #323232; 
 
    width:100%; 
 
    padding: 0; 
 
    margin: 0; 
 
    font-family: Lato; 
 
} 
 
     nav a { 
 
     color: #fff; 
 
     text-decoration: none; 
 
     padding: 20px 25px; 
 
     display: inline-block; 
 
     } 
 

 
     .fixed-header, .fixed-footer { 
 
     background: #333; 
 
     color: #fff; 
 
     width: 100%; 
 
     position: fixed; 
 
     text-align: center; 
 
     z-index: 10; 
 
     background-color: #202020; 
 
     } 
 

 
     .fixed-header { 
 
     top: 0; 
 
     } 
 

 
     .fixed-footer { 
 
     bottom: 0; 
 
     padding: 20px 0px; 
 
     } 
 

 
     .fixed-header a:hover { 
 
     color: #c1c1c1; 
 
     } 
 

 
     .fixed-footer a { 
 
     color: #fff; 
 
     font-weight: lighter; 
 
     text-decoration: none; 
 
     } 
 

 

 
    
 

 
    .group-content { 
 
    max-width: 960px; 
 
    text-align: center; 
 
    width: 75%; 
 
    margin: 75px auto; 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
    justify-content: space-evenly; 
 
} 
 

 
     .group-content h3 { 
 
     margin-top: 10px; 
 
     font-weight: normal; 
 
     font-size: 20px; 
 
     color: white; 
 
     } 
 

 
     .group-content p { 
 
     margin-top: 3px; 
 
     font-weight: lighter; 
 
     font-size: 20px; 
 
     color: white; 
 
     } 
 

 
     .content { 
 
     width: 30%; 
 
     background-color: #202020; 
 
     display: flex; 
 
     flex-direction: column; 
 
     padding: 20px 0 20px 0; 
 
     align-items: center; 
 
     margin-top: 20px; 
 
     } 
 

 
     .content >* { 
 
     max-width: 200px; 
 
     text-align: center; 
 
     margin: 0; 
 
     }
<!DOCTYPE html> 
 

 
    <html lang="en"> 
 

 
    <head> 
 
     <title>Kumo99.cf</title> 
 
     <meta charset="UTF-8"> 
 
     <link rel="stylesheet" type="text/css" href="css/style.css"> 
 
     <link rel="icon" href="favicon.ico"> 
 
    </head> 
 

 
    <body> 
 

 
    <div class="fixed-header"> 
 
     <nav> 
 
     <a href="index.html">HOME</a> 
 
     <a href="projects.html">PROJECTS</a> 
 
     <a href="about.html">ABOUT</a> 
 
     </nav> 
 
    </div> 
 

 
    <div class="fixed-footer"> 
 
    <a href="https://steamcommunity.com/id/kumo99">Made by Kumo © 2018</a> 
 
    </div> 
 

 
    <div class="group-content"> 
 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Arma 3: Exile Server</h3> 
 
     <p>A project for improving the exile mod.</p> 
 
     </div> 
 

 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Reserved Space</h3> 
 
     <p>Reserved space for future projects</p> 
 
     </div> 
 

 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Reserved Space</h3> 
 
     <p>Reserved space for future projects</p> 
 
     </div> 
 

 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Reserved Space</h3> 
 
     <p>Reserved space for future projects</p> 
 
     </div> 
 

 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Reserved Space</h3> 
 
     <p>Reserved space for future projects</p> 
 
     </div> 
 

 
     <div class="content"> 
 
     <img src="https://i.imgur.com/KPHMNie.png"> 
 
     <h3>Reserved Space</h3> 
 
     <p>Reserved space for future projects</p> 
 
     </div> 
 
    </div> 
 

 
    </body> 
 
    </html>

+0

このセンターはわずかですが、まだ完全ではありません。ここでは、下半分に大きなギャップがあることがわかります。 http://prntscr.com/hto43r –

0
  1. あなたは100%
  2. マージン
  3. メイク基含有量マージンにあなたの幅を960ピクセル幅作るために体幅を固定している:自動;

CSS:

body { 
     background-color: #323232; 
     padding: 0; 
     margin: 0; 
     font-family: Lato; 
    } 
    .group-content { 
     max-width: 960px; 
     text-align: center; 
     margin: auto; 
     display: flex; 
     flex-wrap: wrap; 
     justify-content: space-evenly; 
    } 

ワーキングJSFiddle:それは正しく中央にための情報のためHERE

関連する問題