简体   繁体   中英

Javascript stylesheet changer changes size of elements on website

So I've added a dark mode theme that I can turn on with a click of a button. A have a javascript that changes the stylesheet with a press of a button:

function nightmode(sheet,sheet2) {
  document.getElementById('light1').setAttribute('href', sheet);
  document.getElementById('light2').setAttribute('href', sheet2);
}

And buttons which can change the stylesheet

<li> <a onclick="nightmode('/cdn/about/css/main_dark.css','/cdn/about/css/bootstrap_dark.css')"  alt="nightmode"> <i class="far fa-moon "></i> </a></li>
<li> <a onclick="nightmode('/cdn/about/css/main.css','/cdn/about/css/bootstrap.css')"  alt="nightmode"> <i class="fas fa-moon "></i> </a></li>

But the problem is when I click one of the button the stylesheet changes size of different elements, for example my icon on the website changes. This can be tested on https://swedcraft.net/Game_Hub/ by pressing on the moons. The difference between the two stylesheets are only colors, no sizes. Thank you!

css file has changed the size.For example, this navbar
在此处输入图片说明 .
First, you do nothing,see the css properties,
在此处输入图片说明 .
Next,click the moon button and see,padding size has changed,
在此处输入图片说明 .
So,the stylesheet changes size of different elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM