Skip to content

Instantly share code, notes, and snippets.

@vitkarpov
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vitkarpov/9908836 to your computer and use it in GitHub Desktop.
Save vitkarpov/9908836 to your computer and use it in GitHub Desktop.
block img inside inline-block
<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>
.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