Skip to content

Instantly share code, notes, and snippets.

@mmcguff
Created May 11, 2020 15:59
Show Gist options
  • Save mmcguff/afad1089fa79a238cdc00b5271e623df to your computer and use it in GitHub Desktop.
Save mmcguff/afad1089fa79a238cdc00b5271e623df to your computer and use it in GitHub Desktop.
This Gist will demonstrate a simple of way o toggling between different style sheets.
body {
background-color: blue;
}
body {
background-color: green;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link id="pagestyle" rel="stylesheet" type="text/css" href="default.css">
<title>css example</title>
<!-- Placing the logic for style swapping in the head of my html so its be available for toggling style -->
<script>
function swapStyle(sheet) {
document.getElementById('pagestyle').setAttribute('href', sheet);
}
</script>
</head>
<body>
<h1>CSS Example Style Sheet</h1>
<button onclick="swapStyle('blue.css')">Blue</button>
<button onclick="swapStyle('red.css')">Red</button>
<button onclick="swapStyle('default.css')">Green</button>
</body>
</html>
body {
background-color: red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment