I am wondering whether it’s possible to take an existing element - let’s say the orange in the code that I have written - and instead of having the background orange - instead, fill the element with a snippet of the same dimensions taken from an image?
Thanks very much for the response - yes that approach does work - sort of - in that I do get a part of the image where previously I only had the orange background. But what I am really after is being able to crop a part of an existing image to fill in the element. For example, I would like to be able to select the exact part of the image that I want by moving the pink rectangle. So - not the whole image - just the precise part that I want. Of course, this part would have to have the exact dimensions of the orange element. Can this be done?
@ttibsen If you need to crop an image use an image editor like the Gimp.
The following code may help you achieve your goal. Change the values to suit your needs. Here is what I use to create a background image.
You can use a background-size greater than 100% to “zoom” into the picture, and then use the background-position to decide which part of the image should be visible.
the orange element has 200 X 600 dimensions - i.e. a 1 /3 ratio - so it should be a simple matter to alter the above code so that the existing orange element gets replaced by the kid in the image. So could someone write the code for that because I am at a loss.
OK - for sure the URL that I have this time is valid in that it does link to an online image - but again, as far as filling in the white element in my layout as a background, well - that’s still not working. The white element has 200 X 600 dimensions and the online image had a 1 / 3 aspect ratio so it should have fit perfectly (OK maybe with some tweaking by scaling) into the area - but no, that didn’t happen.
It’s important to understand the difference between a page showing an image and the image itself. The link you have in the url is a page with an image, not the actual image.
Do what @jsdisco explained to get to the image link (or just copy the link he posted).
Duh … … what am I missing here? The above url opens up a webpage that shows ONLY the image so it should be a valid url. The following from lasjorg
" It’s important to understand the difference between a page showing an image and the image itself. The link you have in the url is a page with an image, not the actual image"
was very helpful in that it made me realize the difference between a link and an image address. The former takes you to a webpage that has among other things, the image that you want. The latter has ONLY the image and nothing else. So for
<div style="background-image: url();">
you want the image address to go between the parentheses NOT the link - correct? But please comment on “Not a valid image URL…” because I don’t get that.
Since we are already on the topic of valid url’s to use when placing a background image, could someone tell me why - when I have a perfectly valid image address for my url - I still don’t get a background image for my div ?
I’m repeating myself but this is not a valid image URL. When I copy that address and open it in a browser, I get an error message. I’ve never used dropbox but if that URL is valid for you, it might be because you’re logged into your account or whatever.
I already pasted the valid URL above, you could try that instead. Here it is again: https://uc5eaf414123e6808cdd9abdf28e.previews.dropboxusercontent.com/p/thumb/ABBAOe1w4xEFRVuh6ciOK6P1f0IyUmcmTr4O_KkIJHuHmyi0x0zgosXHKhduEW_DwBQexUMi4HR0gbB9AR86CziU42yMvJUFgp6PWBxY00j-2C_8qpvGhuWOxJBJY0TDsD_HOqx_SviwUybtLE3vFyohR1s6k3fM0849AqtaJXTz2haama3D0cxUdrvuTpmguQGXzrEXcGteD5OznJhgSEiduagYQZPaFsdx4L0riyPPR5TNi8mjbOoGo_nHAYvIO9HvbnPd_5NC80lmBgYRKol9JkdTqph-48fwZH9pw2sQV3_rZE1AWldlaIQkr43-RfuoesQae_GaGpurdT9P-ts_cggxhBc7cS70MqkPbkzsIrTluYXqVn7r2AjssSIOwiJWxnTkfVUcSBzyxIBkxTRJ/p.jpeg