CLG Logo

The Source

Coding has always been my passion and I think it is a really great idea to share code snippets that I find useful and apply to website design.


Centering an element in a div

Using Flexbox to position an element in the Center of a div. For This exercise we use a responsive image as the element.

example image

<div class="mybox">
    <img src="images/flexbox.jpg" alt="example image" class="responsive" >
</div>


.mybox {
height: 35vh; // height of div responsive to 35% of viewport
width: 70%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
border: 1px dashed black;
}

.responsive {
      width: 100%;
  max-width: 360px;
  height: auto;
}

Customizing the scroll bar

Creating a custom scroll bar can augment the website identity to match to company apprentice.

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.

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.



<div class="mywindow">
    <p>Lorem Ipsum is simply dummy text of the printin...</p>
</div>


.mywindow {
height: 25vh;
width: 70%;
  border: 1px dashed black;
  margin: auto;
  overflow: hidden;
  overflow-y: scroll;

}

/* width */
.mywindow::-webkit-scrollbar {
  width: 20px;
cursor: pointer;

}

/* Track */
.mywindow::-webkit-scrollbar-track {
  box-shadow: inset 0 0 5px grey;
  border-radius: 10px;
}

/* Handle */
.mywindow::-webkit-scrollbar-thumb {
  background-color: #569dcc;
  border-radius: 10px;
   box-shadow: inset 0 0 5px black;
}

/* Handle on hover */
.mywindow::-webkit-scrollbar-thumb:hover {
   background-color: #569dcc;
}


Ontario Land Transfer Tax Calculator 2023

Calculate the land transfer tax in Ontario. (html, css and Javascript) Implement the calculator on a commercial website for $25 lifetime license.


I used the latest JQuery library when I wrote this calc in this in September 2023...
<script src="https://code.jquery.com/jquery-latest.min.js"></script>

 Price: $   

Ontario

Prov Tax

 $_ _ _

1st time buyer

 $_ _ _

Toronto

Prov + Muni Tax

 $_ _ _

1st time buyer

 $_ _ _

Ontario Prov Tax

First $55,000

$55,000 - $250,000

$250,000 - $400,000

$400,000 - $2,000,000

Over $2,000,000

1st time rebate

MARG TAX %

0.5%

1%

1.5%

2%

2.5%

$4,000

Toronto Muni Tax

First $55,000

$55,000 - $250,000

$250,000 - $400,000

$400,000 - $2,000,000

Over $2,000,000

1st time rebate

MARG TAX %

0.5%

1%

1.5%

2%

2.5%

$4,475


Javascipt

  var $ = jQuery;
  	$(document).ready(function() {
  	$("#result").toggleClass("result");
  	$("#Ontario").click(function() {
  		var a_ltt = $("#sellingprice").val();
  		var b_ltt;
  		var c_ltt;
  		var pc_ltt;
  		var mc_ltt;
  		var tor_ltt;

  		if (a_ltt < 55001) { b_ltt = a_ltt * 0.005;}
  		if ((a_ltt > 55000) && (a_ltt < 250001)) { b_ltt = 275 + ((a_ltt - 55000) * 0.01);}
  		if ((a_ltt > 250000) && (a_ltt < 400001)) { b_ltt = 2225 + ((a_ltt - 250000) * 0.015);}
  		if ((a_ltt > 400000) && (a_ltt < 2000001)) { b_ltt = 4475 + ((a_ltt - 400000) * 0.02);}
  		if (a_ltt > 2000000)  { b_ltt = 36475 + ((a_ltt - 2000000) * 0.025);}

  		pc_ltt = (b_ltt - 4000);

  		if (pc_ltt < 0) { pc_ltt = 0;}
  		if (a_ltt < 55001) { c_ltt = a_ltt * 0.005;}
  		if ((a_ltt > 55000) && (a_ltt < 250001)) { c_ltt = 275 + ((a_ltt - 55000) * 0.01);}
  		if ((a_ltt > 250000) && (a_ltt < 400001)) { c_ltt = 2225 + ((a_ltt - 250000) * 0.015);}
  		if ((a_ltt > 400000) && (a_ltt < 2000001)) { c_ltt = 4475 + ((a_ltt - 400000) * 0.02);}
  		if (a_ltt > 2000000)  { c_ltt = 36475 + ((a_ltt - 2000000) * 0.025);}

  		mc_ltt = ((b_ltt - 4000) + (c_ltt - 4475));
  		if (mc_ltt < 0) { mc_ltt = 0;}
  		tor_ltt = (b_ltt + c_ltt);

  		// Create our number formatter.
  		const formatter = new Intl.NumberFormat('en-US', {
  			style: 'currency',
  			currency: 'USD'
  		});
  				$("#ltresult").html(formatter.format(+b_ltt));
  				$("#stltresult").html(formatter.format(+pc_ltt));
  				$("#torresult").html(formatter.format(+tor_ltt));
  				$("#sttorresult").html(formatter.format(+mc_ltt));
  		});
  	});


CSS

  .mycol-envelope {
  	display: table;
  	width: 100%;
  }
  .ltt_envelope {
  	border-collapse: collapse;
  	display: table-cell;
  	vertical-align: middle;
  	width: 33%;
  	padding-top: 1em;
  	padding-left: .5em;
  	padding-right: .5em;
  	text-align: center;
  }
  .mycol_calc-container {
  	display: table;
  	width: 100%;
  }
  .ltt_col_container {
  	display: table;
  	width: 100%;
  }
  .mynewcell {
  	border-collapse: collapse;
  	display: table-cell;
  	vertical-align: top;
  	width: 50%;
  	text-align: center;
  	padding-top: 1em;
  }
  .mynewcell-2r {
  	border-collapse: collapse;
  	display: table-cell;
  	vertical-align: top;
  	width: 60%;
  	padding-top: 1em;
  	padding-bottom: 1em;
  }
  .mynewcell-2l {
  	border-collapse: collapse;
  	display: table-cell;
  	vertical-align: top;
  	width: 40%;
  	padding-top: 1em;
  	padding-bottom: 1em;
  }
  #Ontario:hover {
  	background-color: rgb(205,35,54);
  }
  .mynewcell-2l p {
  	font-size: .9em;
  	padding-bottom: 2px;
  	padding-top: 2px;
  	margin-bottom: auto;
  }
  .mynewcell-2l p:nth-child(odd) {
  	background-color: rgba(205,35,54,.1);
  }
  .mynewcell-2l p:nth-child(even) {
  	background-color: rgba(211,211,211,.2);
  }
  .mynewcell-2r p:nth-child(even) {
  	background-color: rgba(211,211,211,.2);
  }
  .mynewcell-2r p:nth-child(odd) {
  	background-color: rgba(205,35,54,.1);
  }
  .mynewcell-2r p {
  	font-size: .9em;
  	padding-bottom: 2px;
  	padding-top: 2px;
  	margin-bottom: auto;
  }
  .mynewcell-2l h5 {
  	color: #c8181e;
  	margin-bottom: 1em;
  	font-size: 1em;
  	padding-bottom: 0;
  }
  .mynewcell-2r h5 {
  	color: #c8181e;
  	margin-bottom: 1em;
  	font-size: 1em;
  	padding-bottom: 0;
  }
  .result {
  	font-size: xx-large;
  	color: blue;
  }
  .ltt_container {
  	margin: auto 1em 2em 1em;
  	border: 1px solid #ccc;
  	padding: 0;
  	background-color: white;
  	max-width: 1788px;
  	margin: 0 auto;
  }
  .mytaxtitle {
  	margin-top: 1em;
  	margin-bottom: 0;
  	padding-bottom: 0;
  }
  .mytaxdesc {
  	margin-top: -.8em;
  	padding-top: 0;
  	padding-bottom:.2em;
  	font-size: .9em !important;
  }
  .currencyinput {
  	border: 1px inset #ccc;
  	font-size: 1.5em;
  }
  .currencyinput input {
  	border: 0;
  	font-size: 1.5em;
  	border: 1px solid red;
  }
  body > div > div > span {
  	font-size: 1.5em; color: #c8181e;
  }
  #sellingprice {
  	font-size: 1.3em;
  	width: 14ch;
  	border: 1px solid #c8181e !important;
  	background-color: white;
  	color: #707070;
  }
  #sellingprice input:active {
  	font-size: 1.5em;
  	width: 10ch;
  	border: 1px solid #c8181e !important;
  }

  @media(max-width:768px) {
  	.ltt_envelope {
  		display: block;
  		width: 100%;
  		margin-top: 0;
  	}
  	.mynewcell {
  		width: 50%;
  		margin-top: 0;
  		padding-top:0;
  		padding-bottom:0;
  	}
  	.mycol-envelope {
  		display: block;
  		width: 100%;
  	}
  	.mycol_calc-container {
  		width: 100%;
  		margin-top: 1em;
  	}
  	ltt_col_container {
  		display: block;
  		width: 100%;
  	}
  	.ltt_container {
  		margin: auto 0 2em 0;
  		border: 1px solid #ccc;
  		padding: 1em .2em 1em .2em;
  	}
    .mynewcell-2l {
  		border-collapse: collapse;
  		display: table-cell;
  		vertical-align: top;
  		width: 40%;
  		padding-top: 1em;
  		padding-bottom: 1em;
  		border: 0;
  	}
  	.mynewcell-2r h5 {
  		padding-bottom: unset;
  		font-size: 1em;
  	}
  	.mynewcell-2l h5 {
  		padding-bottom: unset;
  		font-size: 1em;
  	}
  }

  @media only screen and (max-width: 1025px) and (min-width: 769px)  {
    .mynewcell-2l p {
  		font-size: .9em;
  	}
    .mynewcell-2r p {
  		font-size: .9em;}
    .ltt_envelope {padding-top: 1em;
  	}
    #Ontario {
  		margin-top: 1em;
  	}
  }

HTML

<div class="ltt_container">
  <div class="mycol-envelope">
  	<div class="ltt_envelope">
  		<span class="curencyinput">  Price: $ <input type="number" id="sellingprice"  pattern="^\$\d{1,3}(,\d{3})*(\.\d+)?$">  <button type="button" id="Ontario"> Calculate </button></span><br>
  			<div class="mycol_calc-container">
  				<div class="mynewcell">
  					<h3 class="mytaxtitle"> Ontario </h3>
  					<p class="mytaxdesc">Prov Tax</p>
  					<p id="ltresult"> $_ _ _</p>
  					<h4> 1st time buyer </h4>
      			<p id="stltresult"> $_ _ _</p>
      		</div>
  				<div class="mynewcell">
  				    <h3 class="mytaxtitle"> Toronto </h3>
  						<p class="mytaxdesc">Prov + Muni Tax</p>
  						<p id="torresult"> $_ _ _</p>
  						<h4> 1st time buyer </h4>
  						<p id="sttorresult"> $_ _ _</p>
    				</div>
  				</div>
  			</div>
  			<div class="ltt_envelope">
  				<div class="ltt_col_container">
  					<div class="mynewcell-2r">
  						<h5>Ontario Prov Tax</h5>
  						<p>First $55,000</p>
  						<p>$55,000 - $250,000</p>
  						<p>$250,000 - $400,000</p>
  						<p>$400,000 - $2,000,000</p>
  						<p>Over $2,000,000</p>
  						<p>1st time rebate</p>
  					</div>
  					<div class="mynewcell-2l">
  						<h5>MARG TAX %</h5>
  						<p>0.5%</p>
  						<p>1%</p>
  						<p>1.5%</p>
  						<p>2%</p>
  						<p>2.5%</p>
  						<p>$4,000</p>
  				</div>
  			</div>
  		</div>
  		<div class="ltt_envelope">
  			<div class="ltt_col_container">
  				<div class="mynewcell-2r">
  					<h5>Toronto Muni Tax</h5>
  					<p>First $55,000</p>
  					<p>$55,000 - $250,000</p>
  					<p>$250,000 - $400,000</p>
  					<p>$400,000 - $2,000,000</p>
  					<p>Over $2,000,000</p>
  					<p>1st time rebate</p>
  				</div>
  				<div class="mynewcell-2l">
  					<h5>MARG TAX %</h5>
  					<p>0.5%</p>
  					<p>1%</p>
  					<p>1.5%</p>
  					<p>2%</p>
  					<p>2.5%</p>
  					<p>$4,475</p>
  				</div>
  		</div>
  	</div>
  </div>
</div>


Farenheit to Celsius Coverter

A simple temp converter.

Temperature Converter

Type a value in the Fahrenheit field to convert the value to Celsius:

Celcius:

JAVASCRIPT

function temperatureConverter(valNum) {
  valNum = parseFloat(valNum);
  valNum = (valNum-32)/1.8;
  document.getElementById("outputCelcius").innerHTML=valNum.toFixed(1);
}

HTML

<h2>Temperature Converter</h2>
<p>Type a value in the Fahrenheit field to convert the value to Celsius:</p>

<p>
  <label>Fahrenheit</label>
  <input id="inputFahrenheit" type="number" placeholder="Fahrenheit" oninput="temperatureConverter(this.value)" onchange="temperatureConverter(this.value)">
</p>
<p>Celcius: <span id="outputCelcius"></span></p>



Javascript Download

A simple script can be used with php to download anyfile.


PHP
<?php
$new_file_name = 'mickey.jpg';
?>


JAVASCRIPT

function javadown(java_file_name) {
	const downloadLink = document.createElement('a');
	downloadLink.href = 'images/'+java_file_name;
	downloadLink.download = java_file_name;
	document.body.appendChild(downloadLink);
	downloadLink.click();
}

HTML

<input type="submit" name="submit" onclick="javadown('<?php echo $new_file_name; ?>')" value="DOWNLOAD">


Video Background

Show a video as background.

Example can be seen here: View Example
CSS
  
#background-video {
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: -1;
}

HTML

<video id="background-video" autoplay loop muted poster="https://domainaname.com/images/filename.png">
   <source src="https://domainname.com/filename.mp4" type="video/mp4">
</video>

CLOSE (X)

Send us a message...

On-line Email Web Form