问题
I want to print a html page in a specific way under css. But all the @media print examples seem to have an external .css file I want to be able to do it without an external file which means there will be no link rel tag:
<LINK REL="stylesheet" MEDIA="print...
How do I do this?
回答1:
I would suggest using an external stylesheet but you can how ever do this on the same page as your HTML if you really want to, an example of this would be like so,
HTML / CSS
<!DOCTYPE html>
<html>
<head>
<style>
@media print {
/* changes the display property to none on all
p elements when printed */
p { display: none}
}
</style>
</head>
<body>
<p>I'm here when the page isn't printed</p>
</body>
</html>
回答2:
Use the @media print
query in a CSS style block:
<style>
@media print {
/* print css here */
}
</style>
回答3:
Make sure your closing style tag () has a space between the end of the @media print query and the closing tag. Like so:
@media print {
stuff {more stuff;}
} </style>
Right curly bracket, space, then closing tag.
来源:https://stackoverflow.com/questions/19533186/css-media-print-without-external-css-file