IN THE NAME OF GOD hello all imagine that i have 1 website that design in vs2008. i have 1 page. i have 1 theme and 3 css in that. i will apply 2 css but one of 3 css dont apply. css1 and css2 apply and css3 dont apply. i can apply theme but cant choose favorite css in theme to apply. i will choose my favorite css in one theme and apply that to my site. how can i do that? thankful. Goodbye.

1 answer

Mottie 1134
0
points

If you add multiple CSS styles to your page, the lowest one on the page will get highest priority. So if you want to add a theme selector to your page, you will have to disable all the additional stylesheets. I found a script a long time ago that should do the trick

Here is the HTML, the stylesheet needs a title attribute.

<link rel="stylesheet" type="text/css" media="screen" href="black.css" title="default" />
<link rel="alternate stylesheet" type="text/css" media="screen" href="green.css" title="green" />
<link rel="alternate stylesheet" type="text/css" media="screen" href="blue.css" title="blue" />

<div align="center">
 <select id="setStyle" class="StyleBox" onchange="setActiveStyleSheet(this.value)">
  <option value="default">Black</option>
  <option value="green">Green</option>
  <option value="blue">Blue</option>
 </select>
</div>

Script

var cookie = readCookie("style");
var cssName = cookie ? cookie : "default";
setPassiveStyleSheet(cssName);
document.getElementById('setStyle').value = cssName;

function createCookie(name,value,days) {
 if (days) {
  var date = new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();
 }
 else expires = "";
 document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
 var nameEQ = name + "=";
 var ca = document.cookie.split(';');
 for(var i=0;i < ca.length;i++) {
  var c = ca[i];
  while (c.charAt(0)==' ') c = c.substring(1,c.length);
  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
 }
 return null;
}
function setActiveStyleSheet(title) {
 var i, a, main;
 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
   a.disabled = true;
   if(a.getAttribute("title") == title) {
    a.disabled = false;
    createCookie("style", title, 365);
   }
  }
 }
}
function setPassiveStyleSheet(title) {
 var i, a, main;
 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  if(a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
   a.disabled = true;
    if(a.getAttribute("title") == title) a.disabled = false;
  }
 }
}
Answered about 9 years ago by Mottie