I have a CC-BY image that I'm using as a background, brought in by CSS. This image is purely there for its looks, and definitely not content. I need to put attribution on this image somewhere, and obviously it would be nicest to make this attribution a link to the kind person who provided the image. However, I don't really want to put link text into my HTML as that breaks the separation of actual content and presentation (the attribution link is really part of the presentation, I would say, since if you viewed the page without the background image, you wouldn't really want to see it).
Is there any way I can get my separation of presentation and content right here?
My current code for this looks something like
<div class='backgrounded'>
<div class='content'><h1>Some stuff here</h1></div>
<div class='attribution'>
Image from <a href='http://example.com/image'>Lovely CC-BY person</a>
</div>
</div>
And the CSS:
div.backgrounded {
background: url(/images/an_image.jpg);
}
div.attribution {
color: #ffffff;
float: right;
}
This has the attribution in the content, where I'd rather not have it.
Other things I've considered include:
Putting the attribution in the image itself. This solves the code separation problem, but my image is a nice wide one positioned to the left so there is enough background for a wide browser window. The bottom right of the image is almost always out of view. I don't see how I can make this attribution a link.
Making an image containing the attribution text and putting that where the current attribution is, again in the background, but on top I guess I could make it a link using JavaScript. This seems like a lot of fiddling about.
Is there a way out of this where my image is only referred to in the CSS? Or failing that, what's the best way to keep things nicely separated, so that, for instance, the image could be replaced without editing the HTML?
How to Insert a Background Image in HTML. If you'd like to set an image as the background of a web page or an HTML element, rather than simply inserting the image onto the page, you'll need to use the CSS background-image property. This CSS property replaced the background-image attribute in previous versions of HTML.
This image is added using CSS background-image Property. This property does not have an option to add an alt attribute to the image. So as an alternative to the alt attribute, we can add a title attribute to the div. This will act as an alt text in the background-image property.
Go to Style -> Background type. Select “Image”. You'll now see an image that you can replace with your own. When you click on the image you'll be prompted to a screen where you can select an image from the WordPress media gallery, or you can upload another image.
You can leave a comment in the CSS itself:
div.backgrounded {
background: url(/images/an_image.jpg); /*Image provided by [name]*/
}
Then the attribution is in the CSS, but it won't be visible on the actual page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With