2016-03-31 11 views
0

固定幅と高さを持つborder-radius: 50%のアンカータグがあります。子要素は画像タグで、固定高さは30pxですが、width: autoです。動的画像ソースは常に横向きの画像になるため、30pxよりも幅が広いためです。親のボーダー半径50%は角を丸めません

アンカータグがborder-radius: 50%overflow: hiddenの場合でも、画像がコンテナの外に表示されています。

私はopacity: 0.99background-color: #FFFFFFをアンカータグに追加しようとしましたが、画像が背景色の背後にあるようにするだけです。私はz-indexを設定しようとしましたが、絶対に何もしません。

誰にも解決策がありますか?役立つなら、私はサイト上でBootstrap 3.3.2を使用しています。

.name { 
    position: relative; 
    border-radius: 50%; 
    overflow: hidden; 
    width: 30px; 
    height: 30px; 
    display: inline-block; 
} 

.profile-img { 
    position: absolute; 
    top: 0; 
    left: -30px; 
    right: -30px; 
    width: auto; 
    height: 30px; 
    margin: 0 auto; 
} 

<a href="/" class="name"> 
    <img src="imageSource" class="profile-img"> 
</a> 
+0

見た目には見えないかもしれませんが、画像は[間違いなく]コンテナの外にあります(https://jsfiddle.net/58e8ce6k/2/)。明らかにしてください:意図した動作は何ですか? – mmgross

答えて

0

私はtに答えを見つけました彼はかなり汚いですが、私が必要とするもののために働いています...

オリジナルの問題は、モバイルデバイス、特にAndroid Chromeにのみ影響するように見えました。上記のコードを使用して

.profile-img__wrapper { 
    border: 2px solid #d0d0d0; 
    width: 30px; 
    height: 30px; 
    display: block; 
    border-radius: 50%; 
    overflow: hidden; 
    -moz-box-sizing: content-box; 
    -webkit-box-sizing: content-box; 
    box-sizing: content-box; 
} 

.profile-img { 
    width: 30px; 
    height: 30px; 
    background-size: cover; 
    display: block; 
    background-position: 50% 0; 
} 

<span class="profile-img__wrapper"> 
    <span class="profile-img" style="background-image: url('imageSource')"></span> 
</span> 

背景画像を許可する:画像は、必ずより小さい60個のピクセルではなかったかまたは、なぜこれが起こったが、私の仕事は周りの下にある場合、いくつかの理由で、画像はブラウザにそれ自身を隠すだろうそのイメージ比を維持し、それが座っている要素の中心に置くようにします。

0

以下のコードが正常に動作することがわかります。

.name { 
 
    position: relative; 
 
    border-radius: 50%; 
 
    overflow: hidden; 
 
    width: 30px; 
 
    height: 30px; 
 
    display: inline-block; 
 
    border : 1px solid black; 
 
} 
 

 
.profile-img { 
 
    position: absolute; 
 
    top: 0; 
 
    left: -30px; 
 
    right: -30px; 
 
    width: auto; 
 
    height: 30px; 
 
    margin: 0 auto; 
 
}
<a href="/" class="name"> 
 
    <img src="http://justvidit.co.uk/wp-content/uploads/2015/03/yellow-orange-summer-sun-light-burst-1.jpg" class="profile-img"> 
 
</a>

+0

これは答えではありません。 – Roy

+0

@Roy私はちょうどあなたが何を見ているのか教えてください –

+0

私は質問の一つではありません。 – Roy

-1

私には罰金だけでなく、その作品

しかし、あなたはあなたの背景透明利用RGBA値を作るために

0

をしたい場合は、この試すことができます:

<a href="/" class="name"> 
    <img src="http://placehold.it/350x150" class="profile-img"> 
</a> 

.name { 
    position: relative; 
    border-radius: 50%; 
    overflow: hidden; 
    width: 100px; 
    height: 100px; 
    display: inline-block; 
    border: 1px solid #000; 
} 

.profile-img { 
    position: absolute; 
    top: 0; 
    left: -30px; 
    right: -30px; 
    width: auto; 
    overflow: hidden; 
    height: 100px; 
    margin: 0 auto; 
} 
関連する問題