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.
<div class="card">
<p>Convert RGB/RGBA/HEX to HEXA <span class="info">(Beta / by onigetoc)</span></p>
<!-- COLOR PICKER -->
<!-- <span class="color-picker">
<label for="colorPicker">
<input type="color" value="#1DB8CE" id="colorPicker">
</label>
</span> -->
<div class="item">
<input type="color" id="colorPicker" value="#246DBC">
<input type="" id="colorInput" class="rgb-input" type="text" value="" placeholder="rgba(36, 109, 188, 0.5) OR #246dbc">
<!-- <button>Convert</button> -->
</div>
<div class="container" style="display:none">
Opacity:
<input type="range" id="my-slider" min="0" max="1" value="1" step="0.01" oninput="slider()">
<div id="slider-value">1</div>
</div>
Hex: <span class="result"></span>
<div></div>
HexA: <span class="result2"></span>
<div></div>
Synthedit: <span class="result3"></span>
<div></div>
SE flip Hex: <span class="result4"> </span>
<div></div>
</div>
<!-- hexA table here: https://codepen.io/chriscoyier/pen/XjbzrW -->
@import url(https://fonts.googleapis.com/css?family=Open+Sans:300,600);
body {
font-family: "Open Sans", sans-serif;
background-color: #246dbc;
}
.card {
display: inline-block;
padding: 20px;
background-color: rgba(255, 255, 255, 0.5);
p {
margin: 0;
}
.info {
font-size: 10px;
padding: 1px 5px;
background-color: yellow;
}
}
.item {
margin-bottom: 20px;
}
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
transition: background-color 5000000s ease-in-out 0s;
}
#colorInput {
height: 40px;
width: 270px;
font-size: 16px;
padding: 0;
padding-left: 5px;
margin-top: 5px;
background-color: transparent;
border: none;
border-bottom: 2px solid;
&:focus {
outline: none;
}
}
button {
cursor: pointer;
height: 43px;
font-size: 14px;
}
.result,
.result2,
.result3,
.result4{
font-size: 30px;
text-transform: uppercase;
//text-transform: lowercase;
}
.container {
background-color: transparent;
width: 320px !important;
display: flex;
align-items: center;
justify-content: space-around;
padding: 0px;
border-radius: 5px;
margin-bottom: 25px;
}
input[type="range"] {
position: relative;
-webkit-appearance: none;
-moz-appearance: none;
display: block;
width: 80%;
height: 8px;
background-color: #d5d5d5;
border-radius: 8px;
outline: none;
background: linear-gradient(to right, rgb(50, 100, 254) 100%, rgb(213, 213, 213) 100%);
}
input[type="range"]::-webkit-slider-runnable-track {
-webkit-appearance: none;
height: 8px;
}
input[type="range"]::-moz-track {
-moz-appearance: none;
height: 8px;
}
input[type="range"]::-ms-track {
appearance: none;
height: 8px;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
height: 20px;
width: 20px;
background-color: #3264fe;
border-radius: 50%;
cursor: pointer;
margin-top: -6px;
border: none;
}
input[type="range"]::-moz-range-thumb {
-webkit-appearance: none;
height: 20px;
width: 20px;
background-color: #3264fe;
border-radius: 50%;
cursor: pointer;
margin-top: -6px;
border: none;
}
input[type="range"]::-ms-thumb {
appearance: none;
height: 20px;
width: 20px;
background-color: #3264fe;
border-radius: 50%;
cursor: pointer;
margin-top: -6px;
border: none;
}
input[type="range"]:active::-webkit-slider-thumb {
background-color: #ffffff;
border: 3px solid #3264fe;
}
#slider-value {
width: 40px;
position: relative;
background-color: #3264fe;
color: #ffffff;
text-align: center;
font-family: "Roboto Mono", monospace;
padding: 2px 2px;
border-radius: 5px;
}
// COLOR PICKER
code {
padding: 5px 8px;
border-radius: 10px;
background-color: #f8f9f9;
color: #cc0066;
}
[type="color"] {
// -moz-appearance: none;
// -webkit-appearance: none;
// appearance: none;
padding: 0;
width: 35px;
height: 35px;
border: none;
background-color: transparent;
position: relative;
top: 8px;
}
// [type='color']::-webkit-color-swatch-wrapper {
// padding: 0;
// }
// [type='color']::-webkit-color-swatch {
// border: none;
// }
// .color-picker {
// padding: 10px 15px;
// border-radius: 10px;
// border: 1px solid #ccc;
// background-color: #f8f9f9;
// }
//Function to convert hex format to a rgb color
var hexAlpha,
hexAlphaSE,
hex,
gethex,
opacity,
opaslider = 1;
function rgb2hex(rgba) {
var rgb = validDigits(rgba);
rgb = rgb.match(/^[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
return rgb && rgb.length === 4
? "#" +
("0" + parseInt(rgb[1], 10).toString(16)).slice(-2) +
("0" + parseInt(rgb[2], 10).toString(16)).slice(-2) +
("0" + parseInt(rgb[3], 10).toString(16)).slice(-2)
: "";
}
// $('button').click(function(){
// var hex = rgb2hex($('input').val());
// $('.result').html(hex);
// $('body').css('background-color', hex);
// });
$(".rgb-input").on("input", function () {
getrgb2hex();
});
function getrgb2hex(opaslider) {
//alert(opaslider);
var hexvalue = trim($("#colorInput").val());
var rgba = validDigits(hexvalue);
opacityval = getOpacity(rgba);
trim(hexvalue);
if (hexvalue.indexOf("#") > -1) {
$(".container").show();
// //opaslider
// newhexvalue = hexvalue.substr(0, hexvalue.lastIndexOf(","));
// //alert(newhexvalue);
hex = hexvalue;
hex2 = addAlpha(hexvalue, opaslider);
hex3 = addAlphaSE(hexvalue, opaslider);
hex4 = addFlipSE(hexvalue);
} else if (hexvalue.indexOf(",") > -1) {
$(".container").hide();
hex = rgb2hex(rgba);
hex2 = addAlpha(hex, opacityval);
hex3 = addAlphaSE(hex, opacityval);
hex4 = addFlipSE(hex);
} else {
$(".container").show();
hexvalue = "#" + hexvalue;
hex = hexvalue;
hex2 = addAlpha(hexvalue, opaslider);
hex3 = addAlphaSE(hexvalue, opaslider);
hex4 = addFlipSE(hexvalue);
}
//var hex = rgb2hex($("input").val());
$("#colorPicker").val(hex);
$(".result").html(hex);
$(".result2").html(hex2);
$(".result3").html(hex3);
$(".result4").html(hex4);
$("body").css("background-color", hex2);
}
function validDigits(n) {
return n.replace(/[^\d,.]+/g, "");
}
function addAlpha(color, opacity) {
var opacity;
// coerce values so ti is between 0 and 1.
const _opacity = Math.round(Math.min(Math.max(opacity || 1, 0), 1) * 255);
return color + _opacity.toString(16).toUpperCase();
}
function addAlphaSE(color, opacity) {
// coerce values so ti is between 0 and 1.
color = color.substring(1);
const _opacity = Math.round(Math.min(Math.max(opacity || 1, 0), 1) * 255);
return _opacity.toString(16).toUpperCase() + color;
}
function addFlipSE(colorcode){
colorcode = colorcode.slice(colorcode.length - 6);
const colorlasttwo = colorcode.slice(- 2);
const colorcenter = colorcode.slice(2,-2);
const colorfirsttwo = colorcode.slice(0,2);
return '#'+colorlasttwo+colorcenter+colorfirsttwo;
}
function getOpacity(colorcode) {
var opacity = colorcode.split(",");
// Accessing individual values
return opacity[3];
}
function trim(str) {
return str.replace(/^\s+|\s+$/gm, "");
}
const mySlider = document.getElementById("my-slider");
const sliderValue = document.getElementById("slider-value");
function slider() {
valPercent = (mySlider.value / mySlider.max) * 100;
var slideropacity = mySlider.value;
getrgb2hex(slideropacity);
mySlider.style.background = `linear-gradient(to right, #3264fe ${valPercent}%, #d5d5d5 ${valPercent}%)`;
sliderValue.textContent = mySlider.value;
}
//slider();
///////////// COLOR PICKER
document.querySelectorAll("input[type=color]").forEach(function (picker) {
picker.addEventListener("change", function () {
let color_input = document.getElementById("colorInput");
color_input.value = picker.value;
getrgb2hex();
});
});
Also see: Tab Triggers