How to Include External Images From a Remote Location with CSS

By eHow Internet Editor

Rate: (6 Ratings)

With Cascading Style Sheets (CSS), you can include an image from outside your Web site on one of your pages. The three ways to give an element attributes in CSS are inline styles, internal style sheets and external style sheets. Follow these steps to include external images from a remote location with CSS.

Instructions

Difficulty: Moderately Challenging

Things You’ll Need:

  • Internet access
  • Computer

In-line Styles

Step1
Find the code for the element you wish to place an image in. In this case, it is
.
Step2
Insert the following code between the end of the opening tag of the element and the closing square bracket:

style = “background-image: url(image_url); width: X px; height: Y px;”

Where image_url is the URL of your remote image, X is the width of your image in pixels and Y is the height. So, in our example, our div would become:


Internal Style Sheet

Step1
Find the tag in the code of your Web page. It should be toward the top of the code.
Step2
Move the tag down one line. If the tag is situated on a line with other code, move it to its own line, and then move it down one more.
Step3
Insert the following code on the line above the tag:


Step4
Insert the following code between the end of the opening tag of the element and the closing square bracket:

class = “bri”

So, in our example, our div would become


Tips & Warnings

  • Use internal style sheets to fill a number of elements with the same image. In this case, you would give the class = “bri” attribute to every element you wanted filled. This way, you can add other CSS tags to the "bri" class elements without changing at each element, just at the top of your document.
  • You can use external style sheets by putting the code from inside your internal sheet (that is, the tags ) in a separate document. Then, instead of putting those tags before your tag, put: You can put this where FILENAME.css is the filename of your new sheet file. This allows you to use the same sheet for a number of pages, which is great if you wish to use the same styles in all your pages.
  • When you display a remote image on your page, viewers will be downloading it from the remote location. This will eat up the bandwidth of that remote location. Other Webmasters may not take kindly to this; they might cut you off from including images from their domain, or they may complain to your Web host about your abuse of their images. Obtain permission first.

Comments

| View All Comments

webmiser said

Flag This Comment

on 1/14/2008 I know several laswsuit have come up from people linking to sites and using images illegally.

webzarus said

Flag This Comment

on 8/24/2007 Permission or not, Better check YOUR TOS from YOUR hosting company. If it violates YOUR TOS(Terms of Service), you can not only lose your website, but you can lose any fees associated with the site.

Many hosting companies have monitoring in place to see this almost immediately and will shut YOUR site down without asking YOUR permission.

They do not want to be hit with DMCA(Digital Millenium Copyright Act) lawsuits.

View All

Post a Comment

POST A COMMENT

Request a New How-To Article

Looking for more How To information? Chances are there’s an eHow member who knows how to do what you’re looking to do. Submit an article request now!

eHow Article:  How to Include External Images From a Remote Location with CSS

eHow Internet Editor

eHow Internet Editor

Category: Internet

Articles: See my other articles

Related Ads

Internet

Veesites
Meet Virginia DeBolt eHow’s Internet Expert.