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.
<svg id="svg" width="400" height="500" viewBox="138 34 3 3">
<title>流山の輪郭</title>
<polygon id="nagareyama" fill="#33aa33" stroke="black" stroke-width="0.4%" ></polygon>
</svg>
svg {
border: solid 1px black;
transform: scaleY(-1);
}
// path data by https://gadm.org/download_country_v3.html
const coodsStr = `
139.894180297852,35.8254623413086 139.893783569336,35.8283271789552 139.892517089844,35.8373336791993 139.898101806641,35.8476142883302 139.898910522461,35.8493919372559 139.903839111328,35.8601684570312 139.902236938477,35.8647155761718 139.900024414063,35.8709754943848 139.896774291992,35.8819999694824 139.891708374023,35.8917503356934 139.887405395508,35.8968696594238 139.884201049805,35.9006767272949 139.883636474609,35.9015197753907 139.885635375977,35.9027595520021 139.893020629883,35.90673828125 139.898147583008,35.9089698791504 139.9033203125,35.9110412597657 139.907165527344,35.9121627807618 139.911880493164,35.9130287170411 139.918334960938,35.9144134521485 139.925552368164,35.9149398803711 139.931671142578,35.9157257080079 139.937637329102,35.9160842895508 139.934280395508,35.909278869629 139.93293762207,35.9053268432618 139.932662963867,35.9032745361328 139.932235717774,35.8969841003419 139.931488037109,35.8935661315919 139.931243896484,35.8914947509766 139.931259155273,35.8887100219728 139.931594848633,35.8866806030273 139.93212890625,35.885383605957 139.933883666992,35.8825645446777 139.935394287109,35.880844116211 139.936553955078,35.8789176940919 139.937286376953,35.877986907959 139.938339233399,35.8772621154785 139.940200805664,35.8762397766114 139.943298339844,35.8747062683107 139.94612121582,35.8727264404296 139.946868896484,35.8717155456543 139.946975708008,35.8705635070801 139.946472167969,35.8694725036622 139.946029663086,35.8690338134766 139.941970825195,35.8660774230958 139.940719604492,35.8643188476564 139.940399169922,35.8633346557618 139.940704345703,35.8624534606934 139.941436767578,35.8618659973145 139.942520141602,35.8614616394044 139.945297241211,35.8609161376953 139.946258544922,35.8603820800781 139.946624755859,35.8599395751954 139.946929931641,35.8589057922363 139.946624755859,35.8552284240724 139.946823120117,35.8525428771973 139.947280883789,35.8512077331544 139.949035644531,35.8481674194336 139.949951171875,35.8470458984375 139.951843261719,35.8456802368164 139.958877563477,35.8426322937013 139.960205078125,35.8417854309082 139.961318969727,35.840732574463 139.962112426758,35.8396224975587 139.963562011719,35.837287902832 139.964004516602,35.8360061645508 139.96403503418,35.8347434997559 139.963668823242,35.8335418701172 139.963302612305,35.8329963684082 139.962280273438,35.8321762084962 139.959701538086,35.8308258056641 139.956085205078,35.8294143676759 139.952224731445,35.8277282714844 139.949432373047,35.8263206481934 139.948165893555,35.8264198303224 139.946990966797,35.8266983032227 139.944900512695,35.8276481628418 139.942428588867,35.8284034729004 139.941848754883,35.8286590576173 139.938110351562,35.8309707641602 139.936645507813,35.8322486877441 139.935852050781,35.8332328796387 139.935256958008,35.8343505859376 139.934432983398,35.8367309570312 139.933822631836,35.8376579284669 139.933090209961,35.8382949829102 139.932495117188,35.8386421203614 139.931243896484,35.8391151428223 139.929870605469,35.8393821716309 139.929153442383,35.8393478393554 139.928482055664,35.839168548584 139.927871704102,35.8388328552247 139.927429199219,35.8383750915528 139.926986694336,35.8373374938966 139.92658996582,35.8349876403809 139.926177978516,35.8337593078613 139.925506591797,35.8327102661133 139.924133300781,35.8313331604004 139.919876098633,35.8286170959473 139.916259765625,35.8273468017578 139.914688110352,35.8265380859376 139.913345336914,35.8261604309082 139.911010742188,35.825912475586 139.898956298828,35.8258171081544 139.896438598633,35.8256874084474 139.894180297852,35.8254623413086
`.trim();
const coods = coodsStr.split(" ").map((latlng) => latlng.split(","));
// 最先端(最{東西南北}端)
const lons = coods.map((v) => v[0]);
const lats = coods.map((v) => v[1]);
// console.log(lons.length) // 420
const max = (a, b) => Math.max(a, b);
const min = (a, b) => Math.min(a, b);
const e = lons.reduce(max, 0);
const w = lons.reduce(min, 999);
const n = lats.reduce(max, 0);
const s = lats.reduce(min, 999);
// console.log({n, s, e, w})
const polygon = document.getElementById("nagareyama");
polygon.setAttribute("points", coodsStr);
const ns = n - s
const ew = e - w
const $svg = document.getElementById("svg");
$svg.setAttribute("viewBox", `${w} ${s} ${ew} ${ns}`);
// polygon.node.points(...coods.flat())
// // 正規化
// const coods2 = coods.map(([lon, lat]) => [
// (lon - w) / ew,
// (n - lat) / ew,
// ])
// const polygon2 = document.getElementById("nagareyama2");
// polygon2.setAttribute("points", coods2.map(cood => cood.join(',')).join(' '));
// const $svg2 = document.getElementById("svg2");
// $svg2.setAttribute("viewBox", `0 0 1 1`);
// // 丸め込み
// const resolution = 1000
// const coods3 = coods2.map((cood) => cood.map(v => Math.round(v * resolution)))
// const $svg3 = document.getElementById("svg3");
// $svg3.setAttribute("viewBox", `0 0 ${resolution} ${resolution}`);
// const polygon3 = document.getElementById("nagareyama3");
// polygon3.setAttribute("points", coods3.map(cood => cood.join(',')).join(' '));
Also see: Tab Triggers