Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML CSS

Apply CSS to imported text/html

Questions and tutorials related to Cascading Style Sheets *all versions*

Moderators: macek, egami, gesf

Apply CSS to imported text/html

Postby jogoland » Sun Jun 08, 2014 7:51 am

Hey everyone,

There is some text I want to use repeatedly on several webpages. Rather than insert the text into each webpage's code, I created a separate document (info.html) and then used <object type="text/html" data="info.html"></object> to import the text into the other pages. I do this so I can edit or update the text just once on the info.html page. But I want to apply CSS to the text on each page (i.e., one webpage might have the text in large red sans-serif, another webpage might have the same text in small blue italics). Is there a way to do this? I've tried creating object classes for the <object>, the <div>, the <everything imaginable>, but the browser ignores all that and renders the font in whatever style is set for info.html (i.e., the default, since I don't have any CSS on that page, which would defeat the purpose).

Any ideas? Thanks! :help:
jogoland
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Jun 28, 2011 7:54 am

Re: Apply CSS to imported text/html

Postby WebOutGateway » Mon Jun 09, 2014 7:47 pm

Hi, jogoland!

There are actually three (3) ways to do it:

(1) External Style Sheet when applied to many pages:

Code: Select all
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>


(2) Internal Style Sheet when applied to a single document:

Code: Select all
<head>
<style>
hr {color: sienna;}
p {margin-left: 20px;}
body {background-image: url("images/background.gif");}
</style>
</head>


and (3) Inline Style:

Code: Select all
<p style="color:sienna;margin-left:20px;">This is a paragraph.</p>


For the first one, you should create a file with the extension .css and link it in your HTML file. To learn more about CSS, you can visit this site: http://www.w3schools.com/css/default.asp

I hope this helps. Thank you.
User avatar
WebOutGateway
New php-forum User
New php-forum User
 
Posts: 34
Joined: Mon Jun 13, 2011 9:25 pm
Location: Pasig City, Philippines

Re: Apply CSS to imported text/html

Postby jogoland » Sat Jun 14, 2014 11:45 am

Heya WebOut,

I'm afraid none of those methods work: they don't seem to work on text from imported objects. For example:

http://jogoland.com/csstests/index1.html (inline CSS--green font)
http://jogoland.com/csstests/index2.html (internal style sheet--yellow font)
http://jogoland.com/csstests/index3.html (linked CSS style sheet--red font)

Here's the link to the page where the text is coming from:

http://jogoland.com/csstests/info

If I use CSS on the info page, then the style will apply to all pages to which it's imported. I'm trying to figure out how to import text but have it in a different style for index1, index2, and index3. Thank you! :)
jogoland
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Jun 28, 2011 7:54 am


Return to CSS

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron