Sign in to follow this  
Kristian Gorenc

Change CSS for included files

Recommended Posts

Hello!

I'm not a skilled web-programmer (as it's obvious from the question [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]).
My problem is the following:
I have a "New Page" into which I included two files (with PHP include function). One of them is [u]html[/u] and one of them is [u]txt[/u].
The page into which I included the two files has different design than the html document included, so I want to change the CSS of the included part on my new page. The result would be that included html file on its own has it's own CSS design and on the "new page" into which the html is included it has different design. Huh, I hope I didn't complicate to much [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Another question related to the included txt file:
The data in my txt file is organized so one word is in each row. When included (because it's raw data) the parsed result is that all words are in one row. How can I put the output in my "new page" (with txt included) so it's one word in each row?

Thanks a bunch!

Share this post


Link to post
Share on other sites
Antheus    2409
[quote]The page into which I included the two files has different design than the html document included, so I want to change the CSS of the included part on my new page. The result would be that included html file on its own has it's own CSS design and on the "new page" into which the html is included it has different design.[/quote]

There is no completely reliable way, since styles may clash. A simple way is to include the section inside a div:[code]<div class='inserted'> ... </div>[/code]Then prefix rules in that CSS with 'inserted'. It might be necessary to manually tweak a thing or two.

[quote]The data in my txt file is organized so one word is in each row. When included (because it's raw data) the parsed result is that all words are in one row. How can I put the output in my "new page" (with txt included) so it's one word in each row?[/quote]

Some formatting needs to be applied to the txt file. Ideally, it would be formatted as <ul> to preserve semantic meaning.

Depending on where the txt comes from, it might be simpler to modify that or modify whatever generates it.

Share this post


Link to post
Share on other sites
[quote name='Antheus' timestamp='1329661039' post='4914502']
[quote]The data in my txt file is organized so one word is in each row. When included (because it's raw data) the parsed result is that all words are in one row. How can I put the output in my "new page" (with txt included) so it's one word in each row?[/quote]

Some formatting needs to be applied to the txt file. Ideally, it would be formatted as <ul> to preserve semantic meaning.

Depending on where the txt comes from, it might be simpler to modify that or modify whatever generates it.
[/quote]

What if it's hard to modify the source that generates the txt file? Is there a way to format the output with CSS?

Thanks!

Share this post


Link to post
Share on other sites
Antheus    2409
[code]$string = get_include_contents('file.txt');

$tok = strtok($string, " ");
echo "<ul>";
while ($tok !== false) {
echo "<li>$tok</li>";
$tok = strtok(" ");
}
echo "</ul>";[/code]
Or something similar.

Share this post


Link to post
Share on other sites
jbadams    25677
[quote name='Antheus' timestamp='1329661039' post='4914502']
There is no completely reliable way, since styles may clash. A simple way is to include the section inside a div:
...

Then prefix rules in that CSS with 'inserted'. It might be necessary to manually tweak a thing or two.
[/quote]
To avoid any clashes with the existing styles, you could first apply a "[url="http://meyerweb.com/eric/tools/css/reset/"]reset css[/url]" to the 'inserted' section and then proceed as per your suggestion to apply new styles only to the inserted content using an 'inserted' prefix.


If it's possible to do so it would be better to design avoid to the problem all together by not having existing styles in the inserted content.

Share this post


Link to post
Share on other sites
Hidden
Thanks everybody! For text file I used arrays and it works like a charm:

<?PHP
$file_handle = fopen("n1.txt", "rb");
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts = explode('=', $line_of_text);
print $parts[0] . $parts[1]. "<BR>";
}
fclose($file_handle);
?>

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this