2017-04-15 6 views
0

私はhtmlコーディングに慣れていないので、いくつかの助けをすることができます。とにかく、 私はブートストラップでカルーセルを作りました。カルーセル自体は問題なく動作します。しかし、カルーセルにボタンを置いた後(top:(px)とright:(px)を使用して、それを配置する方法が分からないので)、それでも問題なく動作します。私はウィンドウのサイズを変更するまで。背景は小さくなりますが、ボタンの種類は同じサイズのままです。それで、動き始めていて、2つのボタンはお互いに隣り合っていて、2つのボタンは2つのボタンの間にスペースがあります。ここで、私のコードを見て: HTMLウィンドウのサイズを変更するときにボタンが動かないようにするには

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta name="viewport" content="width = device-width, initial-scale = 1"> 
     <title>Galaxy</title> 
     <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
     <link rel="stylesheet" type="text/css" href="css/bootstrap.css"> 
     <link rel="stylesheet" type="text/css" href="css/style.css"> 
     <style type="text/css"> 
</style> 
    </head> 
     <body> 
      <div id="theCarousel" class="carousel slide" data-ride="carousel"> 
       <ol class="carousel-indicators"> 
        <li data-target="#theCarousel" data-slide-to="0" class="active"></li> 
        <li data-target="#theCarousel" data-slide-to="1"></li> 
       </ol> 
       <div class="carousel-inner"> 
        <div class="item active"> 
         <img src="galaxy3.jpg"> 
         <div class="slide1"></div> 
         <div class="carousel-caption"> 
          <div class="bannertext"> 
           <h1>Santorodesign</h1> 
           <p>A website made by Michael</p> 
           <div class="mobileHide"> <button id="headerbutton-nederlands">Nederlands</button></div> 
           <div class="mobileHide"> <button id="headerbutton-english">English</button></div> 
          </div>        
         </div> 
       </div> 
       <div class="item"> 
        <div class="slide2"></div> 
        <img src="galaxy2.jpg"> 
        <div class="carousel-caption"> 
         <div class="bannertext2"> 
          <h1>Explore the galaxy<h1> 
        </div> 
       </div>   
      </div> 

       <a class="left carousel-control" href="#theCarousel" data-slide="prev"> 
        <span class="glyphicon glyphicon-chevron-left"></span> 
       </a> 

       <a class="right carousel-control" href="#theCarousel" data-slide="next"> 
        <span class="glyphicon glyphicon-chevron-right"></span> 
       </a>    
      </div> 
     </div> 
     <div id="firstrow"> 
      <div class="planet col-lg-4 col-md-4 col-sm-6 col-xs-12"> 
       <img id="mercury" src="mercury.png"> <br> 
       (text) <br> 
       <a href="#"><button type="submit" class="btn-primary btn-lg">Learn more about Mercury</button></a> 
      </div> 
      <div class="planet col-lg-4 col-md-4 col-sm-6 col-xs-12"> 
       <img id="earth" src="earth.png"> <br> 
       (text)<br> 
       <a href="#"><button type="submit" class="btn-primary btn-lg">Learn more about the Earth</button></a> 
      </div> 
      <div class="planet col-lg-4 col-md-4 col-sm-6 col-xs-12"> 
       <img id="venus" src="venus.png"> <br> 
       (text) <br> 
       <a href="#"><button type="submit" class="btn-primary btn-lg">Learn more about Venus</button></a> 
      </div> 
     </div>   
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
     <script src="js/bootstrap.min.js"></script> 
    </body> 
</html> 

CSS

.carousel-control.left, .carousel-control.right { 
    background-image: none 
} 
#firstrow { 
    font-size: 2em; 
    padding: 100px 0 0 0; 
    width: 100%; 
    height: 550px; 
    text-align: center; 
    color: black; 
    background: #DCDCDC; 
    position: relative; 
} 
@media all and (max-width: 900px) { 
    #headerbutton-nederlands { display: none; } 
    #headerbutton-english { display: none; } 
} 
.planet { 
    margin-bottom: 30px; 
    position: relative; 
} 
    .planet img { 
     height: 300px; 
     max-width: none; 
    } 

    .bannertext { 
     font-size: 1.3em; 
     line-height: 15px; 
    } 
    .bannertext h1 { 
     font-size: 2em; 
    } 
    .bannertext2 { 
     font-size: 2em; 
    } 
.mobileShow { display: none;} 
.mobileHide { display: inline;} 
    /* Smartphone Portrait and Landscape */ 
    @media only screen 
     and (max-device-width : 480px){ 
     .mobileShow { display: inline;} 
     .mobileHide { display: none;} 
     .planet img{ 
      height: 200px; 
     } 
     } 
#headerbutton-nederlands { 
    position: absolute; 
    font-weight: bold; 
    bottom: 35px; 
    right: -90px; 
    -webkit-border-radius: 5px; 
    line-height: 50px; 
    color: white; 
    background-color: #778899; 
    width: 13%; 
    text-align: center; 
    border: white 2px solid ;  
} 
#headerbutton-english { 
    position: absolute; 
    font-weight: bold; 
    bottom: 35px; 
    right: 100px; 
    -webkit-border-radius: 5px; 
    line-height: 50px; 
    color: white; 
    background-color: #778899; 
    width: 13%; 
    text-align: center; 
    border: white 2px solid ; 
} 

は基本的に私が何をしたいウィンドウが小さくなったときにボタン+ボタンの内のテキストもサイズを変更ということです。ボタンがイメージの一部であるかのように。

ありがとうございます。 -Michael

+0

は、それがありますhttp://codepen.ioまたはhttp://jsfiddle.netのデモであなたの質問を明確にすることをお勧めします – ryantdecker

+0

[この質問と可能な重複(http://stackoverflow.com/questions/1495407/maintain-the -aspect-ratio-of-a-div-with-css)を指定します。純粋なCSSの代わりにSCSSを書く予定がある場合は、[this mixin](https://css-tricks.com/snippets/sass/maintain-aspect-ratio-mixin/)もチェックすることができます。 – andreim

答えて

0

ボタンを画面のサイズに合わせて縮尺させるには、ピクセルではなく相対単位でスタイルを設定する必要があります。 %を使用して、親要素の相対的なサイズをemまたはremに設定して、フォントのサイズに合わせてサイズを変更するか、必要に応じて - vhまたはvwを使用して高さと幅ビューポートのそれぞれに表示されます。

あなたの最初のスタイルがワイドビューポート1140px(単に任意の出発点)上で動作すると仮定すると、以下のCSSは、あなたが正しい方向に向かっれるかもしれません:2つの非常に異なった答えによって判断

#headerbutton-nederlands { 
    position: absolute; 
    font-weight: bold; 
    bottom: 3vw; 
    right: -8vw; 
    -webkit-border-radius: .5vw; 
    line-height: 4.3vw; 
    color: white; 
    background-color: #778899; 
    width: 13%; 
    text-align: center; 
    border: white 2px solid ;  
} 
0

.bannertext要素には、position: relative;プロパティを追加する必要があります。これが行うのはです。子要素が相対的に配置された親の中に絶対配置されている場合、子要素が親の境界から相対的にとどまるようにします。だからあなたのCSSの.bannertextを次のように変更すればうまくいくはずです。

.bannertext { 
    font-size: 1.3em; 
    line-height: 15px; 
    position: relative; 
} 

ので、それはあなたが再びたかっ正しい場所に戻っていてもあなたはtoprightプロパティを更新する必要があるかもしれません。

関連する問題