Forum Moderators: not2easy
Using a PHP if/else statement the user fills in a form and when the submit button is selected the form with the completed fields appears ready for printing.
The problem is that I'd like to set change things like the header and navigation bar to display:none, but not sure how to do it.
What I've tried is duplicating the main.css and changing everything but those elements specific to the form to print to display:none, which has been unsuccessful to this point.
How can the stylesheet be changed from main.css to print.css (BTW the print.css has media set to both screen and print)?
I've tried to load print.css after the else statement--no luck there using <link href="styles/print.css" rel="stylesheet" type="text/css" media="screen, print" />
Also, tried using @import after the else statement with:
<style type="text/css" media="screen, print">
@import "styles/print.css";
</style>
What I need to know is how to replace the main.css with print.css. (One thing I'd like to avoid is any javascript).
Alan
[sitepoint.com...]
Thanks for the link. Maybe I missed it, but didn't see anything about stylesheet switching other than by javascript.
One thing that the article points out that addresses the issue is that some browsers will give the first stylesheet dominance, while other browsers will give the last stylesheet dominance.
The tutorials I've looked at store the selected stylesheet to a cookie or use sessions and call it as a variable as to which stylesheet to use when loading the <head> section.
Basically this is what I've got:
My Page:
----------------------------------------------
<head>
<link href="styles/main.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
// If the submit button has not been clicked then show this
<?php if (!$_POST['submit']) {?>
<Content goes here>
<Form goes here>
// Do this when the submit button has been clicked
<?php } else {?>
<This is the problem area. What needs to happen is that main.css needs to be over ridden by print.css. What print.css does is to change most of the ID and classes to display:none>
<Is there a way to use import to over ride a previously loaded stylesheet?>
<Form displays with information submitted by user.>
<head>
<link ... />
</head>
<?php
if...else determined output
?>
Have it like this...
<?php
//if...else output that includes one .css file <link> for when there is a $_POST['submit'] and another for when there isn't
?>
cEM