Change css value with php

后端 未结 3 1811
天命终不由人
天命终不由人 2021-01-03 03:19

how can I change css of a div displaying some text on my home page from the admin are. I want when I enter a color code in my plugin admin page, the code is updated in the c

3条回答
  •  醉酒成梦
    2021-01-03 03:57

    Putting out a CSS file through PHP will add overhead to the server as you will have dynamic HTML and CSS to create. Given the 'cascading' nature of CSS, any inline style served in the HTML pages will override the CSS, so it's quite likely that you can simply add some inline styles into the pages already being served by PHP. Another option is to update the CSS using Javascript, here is one way to do this, but I don't believe this works in all browsers (I use this in Webkit on iOS):-

    var cssStyle = getCSSRule('#styleName');
    cssStyle.style.background = redfinedColour;
    

    ...using getCSSRule from here:-

    http://www.hunlock.com/blogs/Totally_Pwn_CSS_with_Javascript

提交回复
热议问题