I currently have a problem, which I first though is trivial (it may is), but I don't have any idea, how to get this done. I have a span, which is just a wrapper for an image, and the span should actually have the width and height of the child element. By default, the width is fine, but the height of the span does not fit the height of the image. If I change it to block, the height is fine, but it's at 100% width (which is kinda expected, since it is a block element). The child image is of unknown width and height.
Edit:
I acutally tried inline-block, but it does not work as expected. I added a toggle for this in the snippet below, please give it a try.
$('#toggleInline').click(function() {
$('#removed').removeAttr("style");
});
$('#toggleBlock').click(function() {
$('#removed').removeAttr("style");
$('#removed').css('display', "block");
});
$('#toggleInlineBlock').click(function() {
$('#removed').removeAttr("style");
$('#removed').css('display', "inline-block");
});
img {
/* just because the sample image is too large */
width: 50%;
}
span.removed {
border: 3px solid #f00;
background: repeating-linear-gradient(
45deg,
#f00,
#f00 10px,
#fff 10px,
#fff 20px
);
}
span.removed img {
opacity: 0.85;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="removed" id="removed">
<img src="https://images.pexels.com/photos/1036371/pexels-photo-1036371.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
</span>
<div style="margin-top: 15px">
<button id="toggleInline">
display: inline (default)
</button>
<button id="toggleBlock">
display: block
</button>
<button id="toggleInlineBlock">
display: inline-block
</button>
</div>
This is what I expected it to look like:
