15 replies [Last post]
Morrile
Offline
newbie
Last seen: 13 years 46 weeks ago
Joined: 2007-09-22
Posts: 9
Points: 0

Hello,

I have two print questions which are causing me a real headache :curse: I am in need of help in creating a print.css file which doesn’t override the main styles.css sheet. In my test website I have the following line of code;

However if I include the following line of code after the above it changes the text layout, overriding the “styles.css”, so how can I prevent this from happening? :shrug:

Next is blocking items. My test website is a 2 column hybrid, left sidebar. The side bar is set to EM and the main page is % to fit to screen size. The site is mainly text within the main window and graphics, menu is set within the side bar. So how can I block everything within

so that if someone wishes to print the page they only get the main contents? :shrug:

I am using Dreamweaver CS3 and I will admit that I am very green when it comes to CSS.

Many thanks in advance

Morrile

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 1 week 2 days ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5344
Points: 2965

Hi Morrile, I think what you

Hi Morrile,
I think what you want is to specify the media value of styles.css to all.

To block sidebar1 in print.css:

#sidebar1{ display:none;} 
#main{width:100%;}

Morrile
Offline
newbie
Last seen: 13 years 46 weeks ago
Joined: 2007-09-22
Posts: 9
Points: 0

Hello Tony,Can't test it

Hello Tony,

Can't test it until the weekend, but that looks like it will resolve the second part of my question. Now I have to try and find a solutionto the first

Thanks,

Lee

Stomme poes
Stomme poes's picture
Offline
Elder
Netherlands
Last seen: 10 years 41 weeks ago
Netherlands
Timezone: GMT+2
Joined: 2008-02-04
Posts: 1854
Points: 378

Funny, the second stylesheet

Funny, the second stylesheet clearly says medai="print" so there's no reason it should be overriding the normal styles.css even if styles.css doesn't specify media. Default should be media="all" when you don't mention it, meaning print.css has to undo everything styles.css says, but only when the browser is printing. Not other way around. Something else is going on.

I'm no expert, but I fake one on teh Internets

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 7 years 43 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

<link href="print.css"

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

If that's exactly as it is in your page, then my guess it's cos the “ ” around print are invalid characters and so the media type's not actually being interpreted by the browser which means it thinks the rules in it apply to all media types.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 1 year 22 weeks ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

Ooooh, good eye, T. What do

Ooooh, good eye, T. What do they call it, smart quotes?

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 30 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

gary.turner wrote:Ooooh,

gary.turner wrote:

Ooooh, good eye, T. What do they call it, smart quotes?

cheers,

gary

No, 'abomination'

Interestingly these invalid characters have been cropping up a lot recently.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Stomme poes
Stomme poes's picture
Offline
Elder
Netherlands
Last seen: 10 years 41 weeks ago
Netherlands
Timezone: GMT+2
Joined: 2008-02-04
Posts: 1854
Points: 378

There's a guy on another

There's a guy on another forum who always uses ` or ′ for an apostrophe. I think on some machines they are on the keyboard as quotes.

I'm no expert, but I fake one on teh Internets

Morrile
Offline
newbie
Last seen: 13 years 46 weeks ago
Joined: 2007-09-22
Posts: 9
Points: 0

well spotted I will try

well spotted :bigoops: I will try that and see this weekend as I am working away from home. Many thanks for all the help, it's much appreciated.

Morrile
Offline
newbie
Last seen: 13 years 46 weeks ago
Joined: 2007-09-22
Posts: 9
Points: 0

loosing it completly

:curse: I know I am doing something wrong, but I don't know what. So let's give you a bigger picture using a blank site;

I have created within Dreamweaver CS3 a single page 2 column hybrid, left sidebar. The sidebar is set to EM and the main column to %.

Within the index.html we have the following code;

Untitled Document

Now I created a print.css with the following code;

@charset "utf-8";
{color : #000000;
background : #ffffff;
font-family : "Times New Roman", Times, serif;
font-size : 12pt;}
a {text-decoration : underline;
color : #0000ff;}
#sidebar1{display:none;}
#main{width:100%;}

So far, so good. However if I make an entry for print and place this as below I then get a new problem.

This then completely removes sidebar1

So how do I get the dam things to view correctly but prints the page without sidebar1?

Please help before insanity sets in

Morrile

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 1 year 22 weeks ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

Morrile wrote: I know I am

Morrile wrote:

:curse: I know I am doing something wrong, but I don't know what. So let's give you a bigger picture using a blank site;

Can you post a link? Or, at least post the entire example.

Quote:

I have created within Dreamweaver CS3 a single page 2 column hybrid, left sidebar. The sidebar is set to EM and the main column to %.

Try to wean yourself off DW. It will only stunt your growth.

It is generally a bad idea to mix metrics, i.e. em and %

Quote:

Within the index.html we have the following code;

Now I created a print.css with the following code;

@charset "utf-8";
<span style="color:red">???</span>{color : #000000; 
  background : #ffffff; 
  font-family : "Times New Roman", Times, serif;
  font-size : 12pt;}
a {text-decoration : underline;
  color : #0000ff;}
#sidebar1{display:none;} 
#main{width:100%;}

So far, so good. However if I make an entry for print and place this as below I then get a new problem.

This then completely removes sidebar1

So how do I get the dam things to view correctly but prints the page without sidebar1?

I think we need to see all your code. Can you post a link?

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Morrile
Offline
newbie
Last seen: 13 years 46 weeks ago
Joined: 2007-09-22
Posts: 9
Points: 0

Hello Gary,it's still in

Hello Gary,

it's still in design mode and not on the web yet. However this is what I have on a test site to try and resolve this problem;

index.html

Untitled Document

/* place css fixes for all versions of IE in this conditional comment */
.twoColHybLt #sidebar1 { padding-top: 30px; }
.twoColHybLt #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it may need to avoid several bugs */

sidebar1 Content

The background color on this div will only show for the length of the content. If you'd like a dividing line instead, place a border on the left side of the #mainContent div if the #mainContent div will always contain more content than the #sidebar1 div.

Donec eu mi sed turpis feugiat feugiat. Integer turpis arcu, pellentesque eget, cursus et, fermentum ut, sapien. Fusce metus mi, eleifend sollicitudin, molestie id, varius et, nibh. Donec nec libero.

Main Content

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam, justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio. Donec et ipsum et sapien vehicula nonummy. Suspendisse potenti. Fusce varius urna id quam. Sed neque mi, varius eget, tincidunt nec, suscipit id, libero. In eget purus. Vestibulum ut nisl. Donec eu mi sed turpis feugiat feugiat. Integer turpis arcu, pellentesque eget, cursus et, fermentum ut, sapien. Fusce metus mi, eleifend sollicitudin, molestie id, varius et, nibh. Donec nec libero.

H2 level heading

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam, justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio.

TwoColHybLt.css

@charset "utf-8";
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #666666;
margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
color: #000000;
}
.twoColHybLt #container {
width: 80%; /* this will create a container 80% of the browser width */
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
border: 1px solid #000000;
text-align: left; /* this overrides the text-align: center on the body element. */
}

/* Tips for sidebar1:
1. Since we are working in relative units, it's best not to use padding on the sidebar. It will be added to the overall width for standards compliant browsers creating an unknown actual width.
2. Since em units are used for the sidebar value, be aware that its width will vary with different default text sizes.
3. Space between the side of the div and the elements within it can be created by placing a left and right margin on those elements as seen in the ".twoColHybLt #sidebar1 p" rule.
*/
.twoColHybLt #sidebar1 {
float: left;
width: 12em; /* since this element is floated, a width must be given */
background: #EBEBEB; /* the background color will be displayed for the length of the content in the column, but no further */
padding: 15px 0; /* top and bottom padding create visual space within this div */
}
.twoColHybLt #sidebar1 h3, .twoColHybLt #sidebar1 p {
margin-left: 10px; /* the left and right margin should be given to every element that will be placed in the side columns */
margin-right: 10px;
}

/* Tips for mainContent:
1. The space between the mainContent and sidebar1 is created with the left margin on the mainContent div. No matter how much content the sidebar1 div contains, the column space will remain. You can remove this left margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends.
2. Be aware it is possible to cause float drop (the dropping of the non-floated mainContent area below the sidebar) if an element wider than it can contain is placed within the mainContent div. WIth a hybrid layout (percentage-based overall width with em-based sidebar), it may not be possible to calculate the exact width available. If the user's text size is larger than average, you will have a wider sidebar div and thus, less room in the mainContent div. You should be aware of this limitation - especially if the client is adding content with Contribute.
3. In the Internet Explorer Conditional Comment below, the zoom property is used to give the mainContent "hasLayout." This may help avoid several IE-specific bugs.
*/
.twoColHybLt #mainContent {
margin: 0 20px 0 13em; /* the right margin can be given in percentages or pixels. It creates the space down the right side of the page. */
}

/* Miscellaneous classes for reuse */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
float: right;
margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page */
float: left;
margin-right: 8px;
}
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}

Print.css

@charset "utf-8";
{color : #000000;
background : #ffffff;
font-family : "Times New Roman", Times, serif;
font-size : 12pt;}
a {text-decoration : underline;
color : #0000ff;}
#sidebar1{display:none;}
#main{width:100%;}

That's all folks; but the print.css is taking control of over twoColHybLt.css which is the annoying part. I used Dreamweaver as I thought it was the best.

Many thanks

Morrile

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 1 year 22 weeks ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

I am unable to replicate

I am unable to replicate your issue. Both print and screen views are as expected.

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Morrile
Offline
newbie
Last seen: 13 years 46 weeks ago
Joined: 2007-09-22
Posts: 9
Points: 0

Thanks

Gary,

Many thanks for taking the time checking this out; I really appreciate that. Bowing down to your knowledge I can only assume it's my Dreamweaver which has developed a bug, so I will try and install it on another PC to see if that resolves the problem. I am hoping it’s just that, else it’s a complete PC rebuild and that does take time.

Many thanks once again

Morrile

Morrile
Offline
newbie
Last seen: 13 years 46 weeks ago
Joined: 2007-09-22
Posts: 9
Points: 0

Eureka!

Now I know it's not me that losing my marbles Smile I can confirm it's my Dreamweaver which has acquired a bug; and without my permission. Testing it on another PC the bug doesn't manifest and the code behaves as it should.

Many thanks to those who helped. :thumbsup:

Morrile

Stomme poes
Stomme poes's picture
Offline
Elder
Netherlands
Last seen: 10 years 41 weeks ago
Netherlands
Timezone: GMT+2
Joined: 2008-02-04
Posts: 1854
Points: 378

Never never never ever test

Never never never ever test things in dreambeaver.

It's not a browser, though it has a rendering engine (what was it with CS3, Presto??) so always always test with real browsers. Cause first, real browsers have their own crapola bugs that DW can't replicate (like, FF has issues printing floats between page breaks, so try not to have long floats), and second, nobody browses the web or prints with DW (that I know of...).

Though I suppose now someone will come out of the woodwork and say "I do!" ... : )

I'm no expert, but I fake one on teh Internets