2016-11-29 5 views
2

私はさまざまなサービスのリストを提供していますが、各サービスにはイメージ、見出し、説明があります。私はそれを設定して、画像をマウスのホバーで1.3倍の大きさにするようにしました。スケーリングは機能しますが、スケーリングは親の境界を無視します。画像が親の枠の外に拡大するのを防ぐにはどうすればいいですか?

私は実際にどのように見えるのGIFをキャプチャしました。ここで

Example of image scaling outside of parent's borders

私が働いているコードです。

.cleaningservices { 
 
    max-width: 250px; 
 
    max-height: 250px; 
 

 
} 
 

 
    /* Default state of the image */ 
 
    .hover01 img { 
 
     -webkit-transform: scale(1); 
 
     transform: scale(1); 
 
     -webkit-transition: .3s ease-in-out; 
 
     transition: .3s ease-in-out; 
 
    } 
 

 
    /* Scale the image to 1.3 it's size on mouse hover */ 
 
    .hover01:hover img { 
 
     -webkit-transform: scale(1.3); 
 
     transform: scale(1.3); 
 
    }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet"/> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/css/bootstrap-select.min.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<div class="row"> 
 
    <div class="cleaningservices"> 
 
    <div class="col-sm-6 col-md-4"> 
 
     <div class="thumbnail hover01"> 
 
     <img src="https://bosworthco.com/wp-content/uploads/2016/10/cleaning-268134_960_720.jpg" alt="deep house cleaning"> 
 
     <div class="caption"> 
 
      <h3>Deep Cleaning</h3> 
 
      <p>Usually, on our first visit we will most likely have to complete a deep cleaning. It is a far more intensive cleaning that our regular cleaning. After first deep cleaning we will continue with one of our regularly scheduled cleanings below.</p> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div>

どのような変更は、私は画像をマウスのホバーに親の国境の内側に拡張するために作成する必要がありますか?

+2

'overflow:hidden; on parent? –

+0

倍率を小さくします。 – connexo

+0

オーバーフローを与える:隠し;親に –

答えて

1

を使用してdivのoverflow:hidden;

.hover01 img { 
 
    -webkit-transform: scale(1); 
 
    transform: scale(1); 
 
    -webkit-transition: .3s ease-in-out; 
 
    transition: .3s ease-in-out; 
 
    width:100%; 
 
} 
 
.hover01:hover img { 
 
    -webkit-transform: scale(1.3); 
 
    transform: scale(1.3); 
 
} 
 

 
.img-parent{ 
 
    overflow:hidden; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet"/> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/css/bootstrap-select.min.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="row"> 
 
    <div class="cleaningservices"> 
 
     <div class="col-sm-6 col-md-4"> 
 
\t <div class="thumbnail hover01"> 
 
\t  <div class="img-parent"> 
 
\t   <img src="http://fiusms.fiu.edu/wp-content/uploads/Residential-Cleaning-Watauga-TX.jpg" alt="deep house cleaning"> 
 
      </div> 
 
\t  <div class="caption"> 
 
\t \t <h3>Deep Cleaning</h3> 
 
\t \t <p>Usually, on our first visit we will most likely have to complete a deep cleaning. It is a far more intensive cleaning that our regular cleaning. After first deep cleaning we will continue with one of our regularly scheduled cleanings below.</p> 
 
\t  </div> 
 
\t </div> 
 
     </div> 
 
    </div> 
 
</div>
を与えます3210

+0

これはおそらく、後続のテキストをズームすることを避けるため、これを行う最もクリーンな方法です。私はクラス '.noverflow'を呼び出します。 – connexo

+0

はい..あなたはイメージを含む別のdivが必要です – Chiller

+0

あなたの答えをありがとう、それは確かに私が欲しかったものを達成するのを助けました。 – raimond

1

overflow: hidden;を設定したimgコンテナを作成します。私はbodyに背景色を追加しました。

body { 
 
    background-color: #f0f0f0 !important; 
 
    padding: 50px; 
 
} 
 
.noverflow { 
 
    overflow: hidden; 
 
} 
 
.thumbnail { 
 
    background-color: #fff; 
 
} 
 
.hover01 img { 
 
    -webkit-transform: scale(1); 
 
    transform: scale(1); 
 
    -webkit-transition: .3s ease-in-out; 
 
    transition: .3s ease-in-out; 
 
} 
 
.hover01:hover img { 
 
    -webkit-transform: scale(1.1); 
 
    transform: scale(1.1); 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet" /> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/css/bootstrap-select.min.css" rel="stylesheet" /> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="row"> 
 
    <div class="cleaningservices"> 
 
    <div class="col-sm-6 col-md-4"> 
 
     <div class="thumbnail hover01"> 
 
     <div class="noverflow"><img src="http://fiusms.fiu.edu/wp-content/uploads/Residential-Cleaning-Watauga-TX.jpg" alt="deep house cleaning"></div> 
 
     <div class="caption"> 
 
      <h3>Deep Cleaning</h3> 
 
      <p>Usually, on our first visit we will most likely have to complete a deep cleaning. It is a far more intensive cleaning that our regular cleaning. After first deep cleaning we will continue with one of our regularly scheduled cleanings below.</p> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div>

+0

これは本当にあなたの答えに感謝します。 – raimond

1

ちょうどあなたがdiv要素に画像を追加することができoverflow: hidden;

.hover01 img { 
    -webkit-transform: scale(1); 
    transform: scale(1); 
    -webkit-transition: .3s ease-in-out; 
    transition: .3s ease-in-out; 
    overflow: hidden; 
} 
関連する問題