Last active
August 29, 2015 13:57
-
-
Save vitkarpov/9908836 to your computer and use it in GitHub Desktop.
block img inside inline-block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="image-container"> | |
<span class="image-wrapper"> | |
<img class="image" src="http://festival.1september.ru/articles/594478/presentation/23.jpg"> | |
</span> | |
</div> | |
<p class="info"> | |
<b>Задача:</b> Отцентрировать иконку относительно тянущейся картинки. <br /> | |
<b>Решение:</b> Обернуть картинку в блок, который будет повторять размеры картинки и спозиционировать иконку относительно него. <br /> | |
<b>В чем проблема:</b> При первой отрисовке обертка соответствует размерам картинки, однако при ресайзе все портится — по высоте блок соответствует, а по ширине нет. | |
</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.image-container | |
{ | |
position: absolute; | |
left: 0; | |
right: 0; | |
top: 0; | |
bottom: 50%; | |
background: lightyellow; | |
} | |
.image-wrapper | |
{ | |
position: relative; | |
display: inline-block; | |
height: 100%; | |
background: yellow; | |
} | |
.image-wrapper:after | |
{ | |
content: "Я"; | |
position: absolute; | |
left: 50%; | |
top: 50%; | |
margin-left: -20px; | |
margin-top: -20px; | |
width: 40px; | |
height: 40px; | |
border: 4px solid white; | |
background: darkred; | |
border-radius: 100%; | |
color: white; | |
font-weight: bold; | |
line-height: 40px; | |
text-align: center; | |
} | |
.image | |
{ | |
display: block; | |
max-height: 100%; | |
width: auto; | |
} | |
.info | |
{ | |
position: absolute; | |
padding: 10px; | |
top: 0; | |
right: 0; | |
left: 50%; | |
border: 1px dotted lightgray; | |
font-size: 14px; | |
line-height: 1.5; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment