HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<body>
<div class="container">
<select onChange="onSelect(this)" class="topRightCorner" >
<option value="0">English</option>
<option value="1">中文(Chinese)</option>
</select>
<div class="boxLeft">
<h2 id = '0' class="boxLeftH2">Information</h2>
<div id='1' >Input two positive integer numbers and get the result of multiplication of those two numbers.</div>
<br />
<div id='2'>It will calculate any big numbers and there is no overflow!</div>
</div><!-- boxLeft-->
<div class="boxRight">
<h2 id='3' class="boxRightH2">
Enter two <b style="font-size: 150%">BIG</b> integer numbers (till your sore fingers)</h2>
<div><span id='4'>First number: </span><input type="text" id="v1" class="inputNum" value="1234567899876543210" />
</div>
<div><span id='5'>Second number:</span><input type="text" id="v2" class="inputNum" value="987654321123456789" />
</div>
<div><input id='0b' type="button" class="button" onclick="calculate()" value="Calculate" /> <input id='1b' type="button" class="button" onclick="clearResult()" value="Clear" />
</div>
<br />
<div id="result">
</div>
</div><!-- boxRight -->
</div><!-- container -->
</body>
body {
font-size: 20px;
}
input {
font-size: 100%;
}
.button {
font-size : 20px;
width: 140px;
height: 35px;
background-color: #004990;
color: #e6e5e5;
border-radius: 8px;
}
textarea {
font-size: 90%;
}
.container {
border:2px solid;
width:100%;
float:left;
}
select.topRightCorner {
position: fixed;
top: 20px;
right: 20px;
width: 110px;
border: 3px solid #004990;
}
.boxLeft {
float:left;
width:20%;
border:1px solid;
padding: 0 1% 1% 1%;
margin:1% 0 1% 1%;
color:green;
}
.boxLeftH2 {
margin:0.5% 0% 5%;
}
.boxRight {
float:right;
margin: 1% %1 1% 1%;
width:75%
}
.boxRightH2 {
color: #004990;
background-color: #e6e5e5;
}
.inputNum {
width: 98%;
}
.result {
width:98%;
height:100%;
}
let textArray = [
['Information', '信息解釋'],
['Input two positive integer numbers and get the result of multiplication of those two numbers.','輸入兩個正整數,得到這兩個數的乘積結果。'],
['It will calculate any big numbers and there is no overflow!', '這個計算的結果可以是任何兩個大數的乘積結果,將不會出現溢出!'],
['Enter two <b style="font-size: 150%">BIG</b> integer numbers (till your sore fingers)', '輸入兩個<b style="font-size: 150%">大</b>正整數(敲到你手發酸)'],
['First number:', '第一個數字:'],
['Second number:', '第二個數字:'],
];
let buttonCaption = [
['Calculate', '計算'],
['Clear', '清除']
];
let resultLabels = [
['Calculated result:', '計算的結果:'],
['Infinity(overflow)','無法確定(溢出)'],
['Verified result:', '驗算的結果:']
]
var lanIndex = 0;
function debug(msg) {
//if (!window.console) {
console.log(msg);
//}
}
function onSelect(elm) {
lanIndex = elm.value;
for (var i = 0; i < textArray.length; i++) {
var e = document.getElementById(i + '');
e.innerHTML = textArray[i][lanIndex];
}
for (var i = 0; i < buttonCaption.length; i++) {
var e = document.getElementById(i + 'b');
e.setAttribute('value', buttonCaption[i][lanIndex]);
}
}
function addCommas(nStr) {
nStr += "";
x = nStr.split(".");
x1 = x[0];
x2 = x.length > 1 ? "." + x[1] : "";
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, "$1" + "," + "$2");
}
return x1 + x2;
}
function adjustHeight() {
let list = document.getElementsByTagName("textarea");
for (let elm of list) {
var sh = elm.scrollHeight;
var h = elm.offsetHeight;
if (h < sh) {
elm.style.height = sh + "px";
}
}
}
function clearResult() {
let elmID = 'result';
var elm = document.getElementById(elmID);
elm.innerHTML = '';
}
function showResult(elmID, text) {
var fieldNameElement = document.getElementById(elmID);
if (fieldNameElement) {
fieldNameElement.innerHTML += text;
}
}
function v1timesv2(v1, v2) {
var x = ""; // result
var i = 0;
var j = 0;
var r;
var r1;
var r2;
var k;
var tempVal;
var preTempVal = "";
debug("v1: " + v1);
debug("v2: " + v2);
for (
i = v2.length - 1;
i >= 0;
i-- // v2
) {
r2 = 0;
tempVal = "";
k = preTempVal.length;
for (
j = v1.length - 1;
j >= 0;
j-- // v1
) {
if (k-- > 0) {
r2 += Number(preTempVal[k]);
}
r = v1[j] * v2[i] + r2;
r1 = r % 10;
r2 = 0;
if (r > 9) {
r2 = (r - r1) / 10;
}
tempVal = r1 + tempVal;
}
if (r > 9) {
tempVal = r2 + tempVal;
}
debug("intermediate calculated result: " + tempVal);
// Get the last char as result
x = tempVal[tempVal.length - 1] + x;
debug("intermediate result: " + x);
// Get the remaining as previous val
if (tempVal.length > 1) {
preTempVal = tempVal.substr(0, tempVal.length - 1);
} else {
preTempVal = "";
}
debug("== carry forward result: " + preTempVal + " ==");
}
x = preTempVal + x;
debug(">>final result: " + x);
debug(
">>verified result: " +
Number(v1) * Number(v2) +
" (" +
v1 +
" x " +
v2 +
")"
);
return x;
}
function calculate() {
var x1 = document.getElementById("v1").value;
var x2 = document.getElementById("v2").value;
if (x1 == null || x1 == "" || x2 == null || x2 == "") {
alert("nubmers must be filled out");
} else {
x1 = (x1 + "").replace(/^\s+|\s+$/g, "");
x2 = (x2 + "").replace(/^\s+|\s+$/g, "");
var x = v1timesv2(x1, x2);
const textarea = '<textarea class="result" readonly>';
const textareaEnd = "</textarea>";
var i = 0;
var content = resultLabels[i++][lanIndex] + "<br />" + textarea;
content += addCommas(x + "");
content += textareaEnd + "<br />";
content +=
textarea +
"(" +
x1 +
" x " +
x2 +
") = \n" +
x +
textareaEnd +
"<br />";
var x1x2;
if ((x1 * x2) === Infinity) {
x1x2 = resultLabels[i][lanIndex];
} else {
x1x2 = (x1 * x2) + '';
}
i++;
content += resultLabels[i][lanIndex] + "<code>" + x1x2 + "</code></><br /><br />";
showResult("result", content);
adjustHeight();
}
}
Also see: Tab Triggers