2016-10-10 7 views
0

私は、すべての画面を中心にしたいテキストセクションを持っています。しかし、画面サイズが大きくなると、画面の一番上にとどまり、画面の一番下が空のままになり、見栄えが悪くなります。さまざまな画面サイズで、ブートストラップでHTMLテキストセクションを中央に配置できません。

どのように上に置かれ、センタリングされていないかのコードとスクリーンショットを貼り付けています。

また、ページのパディングを上から上に調整するコードにその部分をマークしました。すべての画面サイズの中心にする方法を知らないdiv要素の内側を中心おかげ

body { 
 
    width: 100%; 
 
    height: 100%; 
 
    font-family: Lora,"Helvetica Neue",Helvetica,Arial,sans-serif; 
 
    color: #fff; 
 
    background-color: #000; 
 
} 
 

 
html { 
 
    width: 100%; 
 
    height: 100%; 
 
} 
 

 
h1, 
 
h2, 
 
h3, 
 
h4, 
 
h5, 
 
h6 { 
 
    margin: 0 0 35px; 
 
    text-transform: uppercase; 
 
    font-family: Montserrat,"Helvetica Neue",Helvetica,Arial,sans-serif; 
 
    font-weight: 700; 
 
    letter-spacing: 1px; 
 
} 
 

 
p { 
 
    margin: 0 0 23px; 
 
    font-size: 18px; 
 
    line-height: 1.5; 
 
} 
 

 
@media(min-width:768px) { 
 
    p { 
 
     text-align: justify; 
 
     text-justify: inter-word; 
 
     margin: 0 0 20px; 
 
     font-size: 20px; 
 
     line-height: 1.6; 
 
    } 
 
} 
 

 
a { 
 
    color: #3bc692; 
 
    -webkit-transition: all .2s ease-in-out; 
 
    -moz-transition: all .2s ease-in-out; 
 
    transition: all .2s ease-in-out; 
 
    outline: 0!important; 
 
} 
 
@media(min-width:768px) { 
 
    .adjust-this { 
 
     padding-left: 55px; padding-right: 55px; 
 
    } 
 
} 
 

 
.content-section { 
 
    padding-top: 85px; 
 
} 
 

 
@media(min-width:767px) { 
 
    .content-section { 
 
     padding-top: 50px; /*This is where you can adjust padding for the section*/ 
 
     width: 100%; 
 
     height: 100%; 
 
    } 
 
} 
 

 
.content-section p { 
 
    opacity: 0.9; 
 
    font-family: 'Domine'; 
 
    font-size: 19px; 
 
    font-weight: 500; 
 
} 
 

 
a:hover, 
 
a:focus { 
 
    text-decoration: none; 
 
    color: #1d9b6c; 
 
} 
 

 
.greeting { 
 
    padding-top: 5px; 
 
    margin-bottom: 20px; 
 
}
<head> 
 

 
    <meta charset="utf-8"> 
 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    <meta name="description" content=""> 
 
    <meta name="author" content=""> 
 

 
    <title>About</title> 
 

 
    <!-- Bootstrap Core CSS --> 
 
    <link href="css/bootstrap.min.css" rel="stylesheet"> 
 

 
    <!-- Custom CSS --> 
 
    <link href="about.css" rel="stylesheet"> 
 

 
    <!-- Custom Fonts --> 
 
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"> 
 
    <link href="http://fonts.googleapis.com/css?family=Open Sans:400,700,400italic,700italic" rel="stylesheet" type="text/css"> 
 

 
</head> 
 

 

 
<body> 
 
<!-- About Section --> 
 
    <article id="about" class="content-section"> 
 
     <div class="container"> 
 
      <div class="row"> 
 
       <div class="col-sm-10 col-sm-offset-1 text-left adjust-this"> 
 
        <h2 class="text-center greeting">Hi there!</h2> 
 
        <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 
 
        </p> 
 
        <p> 
 
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
 

 
        </p> 
 
        <p> 
 
        It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.      
 
        </p> 
 

 
        <p> 
 
         It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc. 
 
         </p> 
 
       </div> 
 
      </div> 
 
     </div> 
 
    </article> 
 
    </body>
Small screen size

See how big screen bottom is empty

+0

はあなたが求めているものについて、より明確にすることができます。また、これは簡単なGoogleの質問のように思えます。 – Ale

+0

このテキストを大きな画面の中央に配置し、空の底面の上部に留まらないようにします。 – tsaebeht

+1

ここでいくつかのセンタリング方法を確認できます:https://css-tricks.com/centering-css-complete-guide/ – Alvaro

答えて

2

垂直は、ブートストラップ付きのボックスの外にあるものではありません。これは、トップパディングのために配置するルールに従います。今すぐあなたはpadding-top: 85px;を設定しています。異なるサイズの画面では柔軟性がありません。コンテナの高さを指定することなく、vertical-align: middle;またはフレックスボックスのセンタリングを利用することはできません。しかし、あなたが高さを宣言した場合、それらは素晴らしい解決策になります。

@media(min-width: /*Specify screen size here*/) { 
    .content-section { 
     padding-top: 200px; /*add required top padding here*/ 
    } 
} 

別のより複雑な解決策はjqueryのを使用して、ウィンドウの高さを計算し、トップのパディングを追加することです:あなたはちょうどあなたが画面サイズをオフに基づいて適用しているトップのパディングを更新することができ、あなたの現在の方法を継続して使用する

それはその窓の高さのパーセンテージだった。 <body>タグの上部に次のコードを挿入します。

<script> 
$(document).ready(function() { 
    var getPadding = function() { 
     $("#about").css("padding-top",function() { 
      return (window.innerHeight*.15 + "px"); 
     }); 
    }; 
    getPadding(); 
    $(window).resize(function() { 
     getPadding(); 
    }); 
}); 
</script> 

そして、ここで働いてcodepenへのリンクです:

http://codepen.io/egerrard/pen/BLxBBw

+0

それは効果がないので、このコードを配置する場所を取得していません。あなたは答えを受け入れるように助けてくれるのですか – tsaebeht

+0

どのソリューションを使用しようとしていますか?あなたは高さを宣言できますか?もしそうなら、おそらく実装するのが最も簡単でしょう。いろいろなビューポートの上部のパディングを追加しない場合は、2番目に簡単です。これはちょうどあなたのCSSに追加されます。 –

+0

2番目の部分はあなたに言った.. jquery one – tsaebeht

関連する問題