2017-08-22 4 views
-1

これはthis question,と非常によく似ていますが、その答えは私のためには機能しません。画像のリンクは、幅の幅を受け取ります

私は画像がある行があり、画像をクリックできるようにしたい。ここに私のコードです:

<div class="row"> 
     <div class="col-lg-4"> 
      <h2 align="center"><a href="#">Education and Outreach</a></h2> 
      <a href="#" style="width:225px;"><img class="img-responsive center-block" src="../img/outreach_small.JPG" style="width:225px;height:228px;" alt="Several remote-sensing-related words on a black background."></a> 
      <br></br> 
     </div> 
     <div class="col-lg-4"> 
      <h2 align="center"><a href="#">Imagery</a></h2> 
      <a href="#" style="width:225px;"><img class="img-responsive center-block" src="../img/earth.png" style="width:225px;height:228px;" alt="A satellite image of the Earth."></a> 
      <br></br> 
     </div> 
     <div class="col-lg-4"> 
      <h2 align="center"><a href="#">Remote Sensing Resources</a></h2> 
      <a href="#" style="width:225px;"><img class="img-responsive center-block" src="../img/dataresources.jpg" style="width:225px;height:228px;" alt="stylized stream of zeroes and ones emanating from a central globe."></a> 
      <br></br> 
     </div> 
    </div> 

私はそれが私のように見えるようにしたいです。赤色の線は、リンク境界がどこにあるべきか、すなわち画像上のみであるべきである(画像がクリック可能になるように)。

enter image description here

しかし、その代わりリンクは各画像の全体の列幅を占有しています。これは、リンクが現在(赤い線なしを除く)のように見えるものです:

enter image description here

私は、様々な "表示" スタイルで

<a href="#" style="width:225px; display=block;"><img class= ... [etc.] 

をやってみました。しかし、私は、画像が列内の中心にくるようにすることはできず、画像上にリンクがあふれないようにすることができませんでした。

+0

あなたはインライン幅とはどういう意味ですかインライン幅を削除するか、代わりに、最大幅 –

+0

を使うのか?私は自分のコードのどこにもそれが見えません。 'style =" width:225px; "' code? – ale19

答えて

1

imgH2をクリック可能にし、各セルに「セル」を含むようにしてテキストが画像の幅を超えないようにすることができます。

aを削除し、h2imgの両方を残りのaの内側に配置しました。 amax-widthdisplay:inline-blockを設定することで、コンテンツが展開されないようにすることができます。

.col-lg-4 {display:inline-block;} 
 

 
a { 
 
    display:inline-block; 
 
    text-align:center; 
 
    max-width:225px; 
 
}
<div class="row"> 
 
     <div class="col-lg-4"> 
 
      <a href="#"> 
 
       <h2 align="center">Education and Outreach</h2> 
 
       <img class="img-responsive center-block" src="http://via.placeholder.com/225x228" style="width:225px;height:228px;" alt="Several remote-sensing-related words on a black background."> 
 
      </a> 
 
      <br /> 
 
     </div> 
 
     <div class="col-lg-4"> 
 
      <a href="#"><h2 align="center">Imagery</h2> 
 
      <img class="img-responsive center-block" src="http://via.placeholder.com/225x228" style="width:225px;height:228px;" alt="A satellite image of the Earth."></a> 
 
      <br /> 
 
     </div> 
 
     <div class="col-lg-4"> 
 
      <a href="#"><h2 align="center">Remote Sensing Resources</h2> 
 
      <img class="img-responsive center-block" src="http://via.placeholder.com/225x228" style="width:225px;height:228px;" alt="stylized stream of zeroes and ones emanating from a central globe."></a> 
 
      <br /> 
 
     </div> 
 
    </div>

+0

ありがとうございます!しかし、これは私が望んでいたものを私に得ることはできません。それは列のすべてを左に揃えるよう強制します:http://imgur.com/0TOuFS3.jpg間違ったCSSファイルを編集したのでしょうか?私はbootstrap.min.cssを変更しました、別のCSSファイルを変更するはずでしたか? – ale19

関連する問題