Forum How do I...?

Assign a stylesheet to cascade css properties.

ssperandeo
Hello,

How should I be including an external stylesheet so that it's as if it's being included last in the document?

I'm interested in buying a server license and was trying to get this code working before I committed. I was wondering if you could help. I think I'm doing something wrong.

Everything's working fine except I can't get the css properties to override the ones in the page being curled. I can specify new properties that haven't been defined yet with the same selectors and they work. But whenever I try to override properties, it seems to be using the other style sheets, regardless of the selector type.

This is my code

<?php

require_once( 'Prince.class.php' );


header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="myfile.pdf"');

$prince = new Prince( '/usr/bin/prince' );

$base_url = 'BASEURL OF SERVER';
$url = $base_url . '/view.php';

$prince->setBaseURL( $base_url );
$prince->addStyleSheet( $base_url . '/css/listing_feature_sheet_pdf.css' );

ob_start();
$ch = curl_init( $url );
curl_exec($ch);
curl_close($ch);

$prince->convert_string_to_passthru( ob_get_clean() );




If needed, I can supply the entire source for this.

Thanks a bunch,

Steve
mikeday
You probably need to use the !important modifier to override properties that are specified in the document, like this:
h1 { color: red !important }
ssperandeo
Hi Mike,

Thanks for your reply. I'll give that a shot. However, I was trying to find out if you knew how to use the php class written by YesLogic to include a pdf stylesheet as the last external stylesheet reference.

For example, I think the php class usage that I post is producing this:

<head>

<meta name="title" content="Listing Feature Sheet" />
<meta name="robots" content="index, follow" />
<meta name="description" content="Listing Management from Borran Software" />
<meta name="keywords" content="listing management" />
<meta name="language" content="en" />

<title>Listing Feature Sheet</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="screen,print" href="/css/listing_feature_sheet_print_pdf.css" />

<link rel="stylesheet" type="text/css" media="screen,print" href="/css/public_html_layout.css" />

<link rel="stylesheet" type="text/css" media="print" href="/css/public_html_layout_print.css" />

<link rel="shortcut icon" href="/favicon.ico?v=2" />


<link rel="stylesheet" type="text/css" media="screen" href="/css/main.css" />
<link rel="stylesheet" type="text/css" media="screen,print" href="/css/listing_feature_sheet.css" />
<link rel="stylesheet" type="text/css" media="print" href="/css/listing_feature_sheet_print.css" />
</head>



when I'd like the class to produce something like this:


<head>

<meta name="title" content="Listing Feature Sheet" />
<meta name="robots" content="index, follow" />
<meta name="description" content="Listing Management from Borran Software" />
<meta name="keywords" content="listing management" />
<meta name="language" content="en" />

<title>Listing Feature Sheet</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="screen,print" href="/css/public_html_layout.css" />

<link rel="stylesheet" type="text/css" media="print" href="/css/public_html_layout_print.css" />

<link rel="shortcut icon" href="/favicon.ico?v=2" />


<link rel="stylesheet" type="text/css" media="screen" href="/css/main.css" />
<link rel="stylesheet" type="text/css" media="screen,print" href="/css/listing_feature_sheet.css" />
<link rel="stylesheet" type="text/css" media="print" href="/css/listing_feature_sheet_print.css" />

<link rel="stylesheet" type="text/css" media="screen,print" href="/css/listing_feature_sheet_print_pdf.css" />

</head>


In this example, I think "listing_feature_sheet_print_pdf.css" is being included first, yet I'd like it to be included last.

I could be totally wrong, though. Also, I'll try what you said and get back to you. In the meantime, is there a way to ensure it's being included last in the external styles with the php class, or does it not work that way at all?

Thanks a bunch,

Steve
mikeday
User style sheets and author style sheets are different. User style sheets will not be included in the document as such, but applied afterwards. They also have a lower priority than author style sheets, unless that priority is raised with the !important modifier.