Force browser to render webpage's Print stylesheet - html

A lot of web pages use a Print stylesheet to format things better for printing. My question is, is it possible to force the browser to render a page using the print stylesheet without actually printing it?

In Chrome (version 78), you can force the browser to render the webpage's print stylesheet using Chrome DevTools by going to More Tools > Rendering
then selecting the Print option in the Emulate CSS Media dropdown

usually the print css has a media type of print. simply remove the media definition and use it in replace of the main style sheet
<link rel="stylesheet" type="text/css" media="print" href="print.css" />
change to
<link rel="stylesheet" type="text/css" media="all" href="print.css" />

Related

CSS file works in Safari but not in Google Chrome or Firefox

When I open my index.html file in Safari, it shows everything, styled with my CSS file. When I open my index.html with Google Chrome, it appears to only show the HTML. I do not use webkits, and I only pair my HTML to my CSS using this in my head tag in my index.html file:
CSS:
<link rel=stylesheet type="html/css" href="stylesheet.css">
Does anyone know how I can open this in Google Chrome so it uses my CSS file like Safari does?
Thanks in advance!
First clear cache of browser and disable some html/css validation extension.It will be sure that it will work. and just follow the css attachment syntax below.<link rel="stylesheet" type="text/css" href="stylesheet.css">
Try using
<link rel="stylesheet" type="text/css" href="stylesheet.css">
The rel tag should have some quotation marks and the type should be text/css for compatibility.
I had the same problem with updating CSS, try ctrl + f5.
It also forces to reload the cache.
And if this is the problem, you can try to clear the cache in the browser.

What will be the best way to load CSS async?

I have nine different CSS files. My website will not load until browser downloads all the CSS files. Most of CSS not even needed for home page. In JavaScript you can do like <script async>,
but for stylesheets, what will be best solution?
I have searched found following articles
Code Pen
keithclark.co.uk
They recommend to use
<link rel="stylesheet" href="css.css" media="none" onload="if(media!='all')media='all'">
or
<head>
<!-- head content -->
<link rel="stylesheet" href="style.css" media="bogus">
</head>
<body>
<!-- body content -->
<link rel="stylesheet" href="style.css">
</body>
By default, CSS is treated as a render blocking resource, which means
that the browser won't render any processed content until the CSSOM is
constructed. Make sure to keep your CSS lean, deliver it as quickly as
possible, and use media types and queries to unblock
rendering.
-- Google Developers
By default, CSS is treated as a render blocking resource.
Media types and media queries allow us to mark some CSS resources as non-render
blocking.
The browser downloads all CSS resources, regardless of
blocking or non-blocking behavior.
CSS is a render blocking resource. Get it to the client as soon and as quickly as possible to optimize the time to first render.
However, what if we have some CSS styles that are only used under certain conditions, for example, when the page is being printed or being projected onto a large monitor? It would be nice if we didn’t have to block rendering on these resources.
CSS "media types" and "media queries" allow us to address these use cases:
<link href="style.css" rel="stylesheet">
<link href="print.css" rel="stylesheet" media="print">
<link href="other.css" rel="stylesheet" media="(min-width: 40em)">
By using media queries, we can tailor our presentation to specific use cases, such as display versus print, and also to dynamic conditions such as changes in screen orientation, resize events, and more. When declaring your style sheet assets, pay close attention to the media type and queries; they greatly impact critical rendering path performance.
Let's consider some hands-on examples:
<link href="style.css" rel="stylesheet">
<link href="style.css" rel="stylesheet" media="all">
<link href="portrait.css" rel="stylesheet" media="orientation:portrait">
<link href="print.css" rel="stylesheet" media="print">
The first declaration is render blocking and matches in all conditions.
The second declaration is also render blocking: "all" is the default type so if you don’t specify any type, it’s implicitly set to "all". Hence, the first and second declarations are actually equivalent.
The third declaration has a dynamic media query, which is evaluated when the page is loaded. Depending on the orientation of the device while the page is loading, portrait.css may or may not be render blocking.
The last declaration is only applied when the page is being printed so it is not render blocking when the page is first loaded in the browser.
Source - Render blocking CSS -

Chrome Print stylesheet not working

I have a stylesheet that is working perfectly in IE, removing headers and footers and displaying my content in a more easy-to-print way. however when printing in chrome, it does not work. If i emulate a print media query in the developer tools it does.
I suspect this is because Chrome converts the document into a pdf before printing. Is there any way around this?
in my html code, my css files are linked as follows:
<link href="/css/form.css" rel="stylesheet" type="text/css" />
<link href="../content/PrintConfirmation.css" rel="stylesheet" media="print"/>
as i said, this works perfectly in IE when printing, but in chrome when going to print, it doesnt.
Duplicate question, See answer: Chrome: Print preview differs from simulate CSS media print
Particularly transition: none !important;

media query - can I use seperate, independant stylesheet?

I was only introduced to media queries yesterday while researching building my mobile optimized pages. I have found that contrary to my initial interpretation a media query directs to a stylesheet that is used in addition to and overrides the existing stylesheet.
Is that right? Is there a way to tell the visitors browser to ignore the original stylesheet and just use the one for mobile?
Here is existing code:
<link href="styles_mobile.css" media="screen and (max-device-width: 480px)" type="text/css" rel="stylesheet">
<link type="text/css" href="styles.css" rel="stylesheet">
It's perfectly acceptable to do so.

printing issue in IE and Firefox

I'm trying to print this page under the link graded fabric ArcCom in IE and Firefox. However, the first page that I printed out appears blank and it is not a complete content. Does anybody know how to fix this by editing the HTML or any other code?
I reccomend creating a print stylesheet.
<link rel="stylesheet" type="text/css" href="print.css" media="print">