今回は、Web開発者にとって非常に便利なライブラリ「clipboard.js」を使って、テキストをクリップボードにコピーする方法をご紹介します。 これは、ボタンをクリックするだけで簡単にテキストをクリップボードにコピーできるツールで、ユーザーの利便性を向上させるために非常に役立ちます。 この記事では、CSS、HTML、およびJavaScriptのコードサンプルを使って、具体的な実装方法を解説していきます。 CSSの設定 まず、ボタンやテキストエリアを見やすくするために、基本的なCSSスタイルを設定しましょう。 クリックするボタン(button)とコピーするテキストエリア(#dvtxt、input)のCSS記述です。 以下のコードを参考にしてください。スタイルは必要に応じてカスタマイズできます。 <style> body{ padding: 0; margin: 0; text-align: