I have an image blog, where I would like to disable simple right-click image downloads. For this, I have set the images to be a div element's background.
My website is responsive and I added background-size: contain
to the div elements, so if they get resized, the background image adopts to the width.
The problem is, that I don't know how to get the div height to adopt to the background image's height so there isn't a whole lot of space under the image when it is resized.
Is it possible to implement using e.g. jQuery?
Try shrinking the div here:
.ui-resizable-helper {
border: 2px dotted #00F;
}
.resizable {
background: url('http://www.ancestry.com/wiki/images/archive/a/a9/20100708215937!Example.jpg') no-repeat;
background-size: contain;
width: 400px;
height: 267px;
border: 2px solid gray;
}
<div class="resizable"></div>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/start/jquery-ui.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(function () {
$(".resizable").resizable({
animate: true,
});
});
</script>