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.
<p>Recharger la page pour changer les couleurs des formes</p>
<div class="conteneur-flexbox">
<svg width="683px" height="527px" viewBox="0 0 683 527" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="Custom-Preset-2" transform="translate(-53.000000, -26.000000)" fill="#D8D8D8" stroke="#232121" stroke-width="4">
<polygon class="forme" id="Path" points="121.488281 57.96875 81.4921875 99.5195312 137.242188 177.785156 236.167969 127.503906 220.085938 68.90625 174.355469 68.90625 158.830078 30"></polygon>
<polygon class="forme" id="Path-2" points="361.597656 36 321 102.359375 376.117188 191.058594 400.441406 124.90625"></polygon>
<polygon class="forme" id="Path-3" points="561.84375 39.0351562 492.117188 51.6953125 485.273438 166.558594 614.109375 191.503906 715.976562 134.332031 733.082031 62.4140625 614.109375 102.296875"></polygon>
<polygon class="forme" id="Path-4" points="97.796875 249.230469 249.394531 249.230469 227.140625 367.035156 173.595703 377.773438 141.882812 284.433594"></polygon>
<polygon class="forme" id="Path-5" points="344.660156 238.417969 344.660156 375.507812 525.285156 375.507812 489.390625 293.605469 434.972656 326.210938 429.933594 247.136719 400 260.535156"></polygon>
<polygon id="Path-6" points="625.59375 279.210938 620.550781 343.355469 648.257812 371.636719 704.316406 332.375 704.316406 297.328125 685.480469 290.871094 680.460938 267.59375 662.433594 274.347656 640.230469 256"></polygon>
<polygon class="forme" id="Path-7" points="101.445312 490.980469 282.367188 444.871094 273.90625 538.640625 238.683594 482.046875 72.7109375 550.148438 56.453125 497.509766"></polygon>
<polygon class="forme" id="Path-8" points="388.8125 459.335938 373.183594 514.734375 403.609375 550.507812 490.757812 527.636719 517.453125 473.300781 470.097656 496.179688 470.097656 437.730469 445.318359 429 445.318359 473.300781 398.121094 429 368 437.730469"></polygon>
<polygon class="forme" id="Path-9" points="624.234375 446.902344 594 504.34375 656.289062 550.378906 717.4375 504.34375 710.339844 425"></polygon>
</g>
</svg>
</div>
body {
text-align:center;
font-family:verdana;
}
/*le positionnement du svg dans la page*/
.conteneur-flexbox {
height: 90vh;
width: 100%;
display: flex;
}
svg {
margin:auto;
}
/*la class appliquée à chaques formes*/
.forme {
fill: red;
}
/*les class de différentes couleurs*/
.change-color1 {
fill: orange;
}
.change-color2 {
fill: green;
}
.change-color3 {
fill: pink;
}
.change-color4 {
fill: yellow;
}
.change-color5 {
fill: grey;
}
.change-color6 {
fill:#651FFF;
}
(function($){
$(document).ready(function() {
var classes = [ 'change-color1', 'change-color2', 'change-color3', 'change-color4', 'change-color5', 'change-color6' ]; // les class que vous voulez ajouter
$('.forme').each(function(i) { // l'élément auquel vous voulez ajouter ces class
$(this).addClass(classes[ Math.floor( Math.random()*classes.length ) ] );
});
});
})(jQuery);
Also see: Tab Triggers