Change CSS for included files

Started by
3 comments, last by jbadams 12 years, 2 months ago
Hello!

I'm not a skilled web-programmer (as it's obvious from the question smile.png).
My problem is the following:
I have a "New Page" into which I included two files (with PHP include function). One of them is html and one of them is txt.
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 smile.png

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!
Advertisement
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:<div class='inserted'> ... </div>Then prefix rules in that CSS with 'inserted'. It might be necessary to manually tweak a thing or two.

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.

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?


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!
$string = get_include_contents('file.txt');

$tok = strtok($string, " ");
echo "<ul>";
while ($tok !== false) {
echo "<li>$tok</li>";
$tok = strtok(" ");
}
echo "</ul>";

Or something similar.

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.

To avoid any clashes with the existing styles, you could first apply a "reset css" 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.

- Jason Astle-Adams

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);
?>

This topic is closed to new replies.

Advertisement