Skip to content

Instantly share code, notes, and snippets.

@ishank-dev
Created October 10, 2020 15:24
Show Gist options
  • Save ishank-dev/6cb605c00a0af99c26bdb95347b21c2d to your computer and use it in GitHub Desktop.
Save ishank-dev/6cb605c00a0af99c26bdb95347b21c2d to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS only -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<br>
<br>
<br>
<div class = 'container'>
<div class="row">
<div class="col-sm-3">
<div>
<legend>Text</legend>
<hr>
<div>
<label for="family">Font: </label>
<select autocomplete="off" name="font-family" id="family" onchange="applyCSS()">
<option value="serif">Serif</option>
<option selected value="Georgia, serif">Georgia</option>
<option value="'cursive">Cursive</option>
<option value="'Times New Roman', Times, 'Roboto Slab', serif">Times New Roman</option>
<option value="sans-serif">Sans-serif</option>
<option value="Arial, Helvetica, sans-serif">Arial</option>
<option value="monospace">monospace</option>
<option value="'Courier New', Courier, monospace">Courier</option>
</select>
</div>
<label for="size">Font Size: </label>
<select autocomplete="off" name="font-size" id="size" onchange="applyCSS()">
<option value="xx-small">Smallest</option>
<option value="x-small">Smaller</option>
<option value="small">Small</option>
<option selected value="medium">Medium</option>
<option value="large">Large</option>
<option value="x-large">Larger</option>
<option value="xx-large">Largest</option>
</select>
</div>
<div>
<label for="color">Color: </label>
<input autocomplete="off" type="color" name="color" id="color" onchange="applyCSS()" value="#000000">
</div>
<div>
<label for="background">Background Color: </label>
<input autocomplete="off" type="color" name="background-color" id="background" onchange="applyCSS()" value="#ffffff">
</div>
<div>
<label for="lineheight">Line Spacing: </label>
<select autocomplete="off" name="lineheight" id="lineheight" onchange="applyCSS()">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
<div>
<label for="margin">Margin: </label>
<select autocomplete="off" name="margin" id="margin" onchange="applyCSS()">
<option selected value="1em">1</option>
<option value="2em">2</option>
<option value="3em">3</option>
<option value="4em">4</option>
</select>
</div>
</div>
<div class="col-sm-6">
<legend>Controlling CSS attributes with javascript </legend>
<hr>
<div id = 'css' ;>
<strong>font-family</strong>:Georgia, serif;<br>
<strong>font-size</strong>:medium;<br>
<strong>color</strong>:#000000;<br>
<strong>background-color</strong>:#ffffff;<br>
<strong>lineheight</strong>:3;<br>
<strong>margin</strong>:1em;<br>
</div>
</div>
</div>
<div id = 'canvas'>
<h3>Heading</h3>
<h4>SubHeading</h4>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum a paragraph</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum a paragraph</p>
</div>
</div>
</body>
</html>
<script>
calcID = function(i) {
return document.getElementById(i);
}
cssDict = {
'font-family': calcID("family"),
'font-size': calcID("size"),
'color': calcID("color"),
'background-color': calcID("background"),
'line-height': calcID("lineheight"),
'margin': calcID("margin")
}
applyCSS = function() {
var str = ''
canvas = document.getElementsByClassName('canvas');
for (var i in cssDict) {
document.getElementById('canvas').style.cssText+= cssDict[i].name+':'+cssDict[i].value;
console.log(cssDict[i].name+':'+cssDict[i].value+';' );
str += '<strong>'+cssDict[i].name+'</strong>'+':'+cssDict[i].value+';'+'<br>'+'</h5>'
}
document.getElementById('css').innerHTML = str
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment