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 id="container" />
<script>const mountNode = document.getElementById('container');</script>
.container {
padding: 80px 20px;
}
.flex {
display: flex;
justify-content: flex-start;
flex-direction: row;
align-items: center;
column-gap: 10px;
p.link-text {
> a {
font: {
size: 18px;
weight: 500;
}
line-height: 1.75;
letter-spacing: 0.1em;
color: #333;
text-decoration: underline;
&:hover {
text-decoration: none;
}
}
}
}
.icon-wrap {
display: flex;
justify-content: flex-start;
flex-direction: row;
align-items: center;
column-gap: 5px;
.ant-typography {
margin-bottom: 0;
}
.icon {
font-size: 18px;
display: grid;
place-content: center;
width: 45px;
height: 45px;
border-radius: 50%;
background: #eee;
overflow: hidden;
}
}
.ant-list-item {
column-gap: 30px;
}
const { createRoot } = ReactDOM;
const { LinkOutlined, SnippetsOutlined, CheckOutlined } = icons;
const { Typography, Avatar, List, Radio, Space } = antd;
const { Paragraph, Text } = Typography;
const data = [
{
title: 'ページトップへ戻るボタンの作り方【JavaScript】',
postUrl: "https://sinpe-pgm.com/pagetop-button-js/",
description: "JavaScriptで作るにはどうしたらいいんだろう?"
},
{
title: '【コピペOK】複数のモーダルを同じクラス名で設置する方法',
postUrl: "https://sinpe-pgm.com/multiple-modals/",
description: "複数のモーダルを実装するの難しい。これまで2~3個だったから#modal01、#modal02とかしていたけど、今回10個以上あるから全部にid割り振ってられないよ、、"
},
{
title: 'OpenAIとNext.jsでAIチャットボットを30分で作る方法',
postUrl: "https://sinpe-pgm.com/openaiapi_nextjs_firststep/",
description: "ChatGPTのAPIで何ができるの?"
},
{
title: 'IntersectionObserverを使うときのテンプレート',
postUrl: "https://sinpe-pgm.com/intersectionobserver_text-illate/",
description: "スクロールして見出しが表示されると、文字がランダムに表示されるようにしています。今回はTextillateというライブラリを使用していますが、独自でCSSを書いてでふわっと表示させたり色々応用できると思います。"
},
{
title: 'remodal.jsがブラウザバックで再表示されるときは、hashTracking: false,にします【使い方・オプション】',
postUrl: "https://sinpe-pgm.com/fixed_remodal/",
description: "ブラウザの戻るボタン押すとモーダル開くのなおしたい。"
},
{
title: '【React】オプショナルチェイニング派?AND演算子派?',
postUrl: "https://sinpe-pgm.com/chain_or_and/",
description: "Reactで同じような処理をオプショナルチェーンで記述しているものと、AND演算子で記述しているものがありました。どちらが良いのでしょうか?"
},
{
title: '静的なHTMLでReactを使う|BabelによるJSXのコンパイル',
postUrl: "https://sinpe-pgm.com/react_html/",
description: "静的なHTMLでReactを使用してみます。"
},
{
title: '【JavaScript】プログレスバー|シンプルなデザイン',
postUrl: "https://sinpe-pgm.com/js_progressbar/",
description: "プログレスバーを実装するのに、ProgressBar.jsを使ったけど、Barが角丸にできなかったり使い勝手わるいなぁ。シンプルなデザインだし自分で作れないかな?"
},
{
title: '【入門】Reactとは?コンポーネントベースの映画リスト作成をわかりやすく解説',
postUrl: "https://sinpe-pgm.com/react_movie_component/",
description: "映画情報のリストを作成したので、その情報を画面に表示させてみましょう。"
},
{
title: 'Next.js × Notionを活用したブログ構築のステップバイステップガイド',
postUrl: "https://sinpe-pgm.com/notionblog_nextjs/",
description: "Next.js、Notionを使ってブログを構築して行きたいと思います。"
},
{
title: 'Reactの基礎を学ぼう: コンポーネントとデータ表示の手法を解説',
postUrl: "https://sinpe-pgm.com/react-component-data-display-explained/",
description: "Reactの基礎的な書き方を学びたいです。"
},
{
title: 'CodePenでReactを使用する方法',
postUrl: "https://sinpe-pgm.com/react-codepen/",
description: "Reactハンズオンラーニング"
},
{
title: '【コピペOK】FAQなどにある、アコーディオンのサンプル(jQuery)矢印やアイコンもつけれます',
postUrl: "https://sinpe-pgm.com/jquery-faq-accordion/",
description: "よくあるアコーディオンを作成したいけど、使い回しやすい良いサンプルないかな?"
},
{
title: '【コピペOK】自動でPDFのアイコンをつけるCSS(Excelファイルや、Wordファイルも)',
postUrl: "https://sinpe-pgm.com/file-icon/",
description: "PDFとかExcelファイルある時に自動でアイコン付けれないかな?"
},
{
title: 'Day.jsで日付のフォーマットを整える|React Next.js microCMS',
postUrl: "https://sinpe-pgm.com/react-dayjs/",
description: "日付が2023-01-29T00:30:00.000Zこんな感じなんだけど、見やすく整えれないかな。"
},
{
title: 'HTMLで角丸のテーブルを作る|overflow-hidden以外の方法',
postUrl: "https://sinpe-pgm.com/table-border-radius/",
description: "角丸テーブルはoverflow-hiddenで実装してたけど、今回のテーブルはoverflow-hiddenできないんだよね。"
},
];
const firstItem = data[0];
const url = firstItem.postUrl;
const name = firstItem.title;
const encodedUrl = encodeURI(url);
const handleCopyToClipboard = async (richText) => {
const blob = new Blob([richText], { type: 'text/html' });
const blobPlain = new Blob([richText], { type: 'text/plain' });
const item = [new ClipboardItem({ 'text/html': blob, 'text/plain': blobPlain })];
try {
await navigator.clipboard.write(item);
message.success('コピーされました');
} catch (error) {
console.error('Error copying rich text to clipboard:', error);
}
};
const App = () => {
const handleCopyToClipboardRichText = (postUrl, title) => {
const richText = `<a href="${postUrl}" target="_blank">${title}</a>`;
handleCopyToClipboard(richText);
};
const renderItem = (item, index) => (
<List.Item>
<List.Item.Meta
avatar={<Avatar src={`https://api.dicebear.com/7.x/miniavs/svg?seed=${index}`} />}
title={<a target="_blank" href={item.postUrl}>{item.title}</a>}
description={item.description}
/>
<div className="icon-wrap">
<Paragraph
className="icon"
copyable={{
text: item.postUrl,
icon: [<LinkOutlined key="copy-icon" />, <CheckOutlined key="copied-icon" />],
tooltips: ['テキスト', 'clicked!!'],
}}
></Paragraph>
<Paragraph
className="icon"
copyable={{
icon: [<SnippetsOutlined key="copy-icon" />, <CheckOutlined key="copied-icon" />],
tooltips: ['リッチテキスト', 'clicked!!'],
onCopy: () => {
handleCopyToClipboardRichText(item.postUrl, item.title);
},
}}
></Paragraph>
</div>
</List.Item>
);
return (
<>
<Typography.Title level={2}>リッチテキストをクリップボードにコピーするサンプル</Typography.Title>
<Space
direction="vertical"
style={{
marginBottom: '20px',
}}
size="middle"
>
</Space>
<List
pagination={{
defaultPageSize: 5
}}
dataSource={data}
renderItem={renderItem}
/>
</>
);
};
const ComponentDemo = App;
createRoot(mountNode).render(<ComponentDemo />);
Also see: Tab Triggers