Changing media specific CSS properties from Javascript -
I have a CSS property that I should be able to replace with javascript (a pulldown). However, this font should only be used during printing (@ media print).
Therefore, the javascript can not change the font's value, as it will affect the view of the screen. Is there a way to change only the print version of the font?
Alternatively, does any CSS property refer to another property?
In this way, in print css, I can say font: printfonts, and in the screen css font: 12 and then change the value of the printfonts, and when printing, only the font will be changed.
Thank you. Edit: The issue is that I should be able to change the font size that the document is printed from the pulldown, but I do not want to change the font size on which the document is displayed.
This is an interesting dilemma that you are going there. From the top of my head, the only thing I can think is to add a new tag to the header where your font-size has been declared! For example, in your head tag:
& lt; Style type = "text / css" media = "print" & gt; .printfont {font-size: 16px! Important; } & Lt; / Style & gt; This will ensure that there will be a new font-size preference.
The following is a quick example of how you can complete it with Javascript
& lt; Script type = "text / javascript" & gt; Var Inline MediaStyle = Faucet; Change the function MediaStyle () {var head = document.getElementsByTagName ('head') [0]; Var newStyle = document.createElement ('style'); NewStyle.setAttribute ('type', 'text / css'); NewStyle.setAttribute ('Media', 'Print'); NewStyle.appendChild (document.createTextNode ('. Printfonts {font-size: 16px! Important;}')); If (inline media style! = Null) {head.replaceChild (new style, inline media style)} other {head.appendChild (newStyle); } Inline MediaSite = New Style; } & Lt; / Script & gt; Make sure that you have onchange = "changeMediaStyle ()" as a feature on your dropdown. Also, in my example as a disclaimer, I am not accounting for things like memory leaks, so you have to do these types of issues on your own.
As for your alternative question, as far as I know, there is no way to use what is essentially CSS variables. However, currently it has been recommended for: < / P>
Comments
Post a Comment