Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWeb Content Preparation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

A Gotcha When Importing Content Into a Web Page

When importing content into web pages obtained from the internet, CSS in the imported content could mess with your page design.

A client had a related question, which is why this article got written. I thought you may be interested in it, also.

Regardless where the content comes from — a script on your site, a web page on your site, content from an affiliate site URL — if the content contains CSS (other than inline CSS) it may have an effect on the styles used in your entire page.

If the content is displayed in an iframe, then the CSS of the web page and the CSS of the content in the iframe don't affect each other. An iframe keeps the content separate even though it may appear like it's part of the page.

But importing content directly into the normal flow of the web page, perhaps into a div, can indeed affect your page's CSS.

This is why.

CSS cascades. The selectors merge. During the merging, the latest declarations for a selector overwrites the value of previous declarations with the same property.

In other words, something like this can happen:

Your web page may have a rule like

h1 { font-size:18pt; color:red; }

The CSS of the imported content may have a rule like

h1 { text-align:center; color:#333; }

Because CSS cascades, the latest h1 selector merges with the previous one. During the merging, property values in the latest rule overwrite values in the earlier rule. You'll end up with

h1 { text-align:center; font-size:18pt; color:#333; }

The font size declaration wasn't in the CSS of the imported content, so that declaration carried through. But the color value changed. And the text-alignment declaration was added.

Whatever CSS rules the browser ends up with applies to the entire page.

And that's the gotcha. Whenever the browser encounters a new CSS rule (other than inline), it re-renders the entire page with the new rule.

Importing content into web pages obtained from URLs can be hazardous to your style :-)

(This article first appeared in Possibilities ezine.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC