9cubed
ブログ | Tailwind | Vite | Python | Node.js | Linux | PowerShell | その他 | 将棋ウォーズ | 歌の練習
HTML・CSS・JavaScript

ヘッダーの固定と背景の半透明化

公開日:2020-10-24
更新日:2020-10-24

1. 概要

ヘッダーを画面上部に固定にして、ヘッダーの背景を半透明にします。

ヘッダーの固定は、
position:fixed;
top:0px;
とします。

ヘッダーの半透明化は、
background-color: rgba(255, 255, 255, 0.8); /* 背景のみ半透明 */

または、

opacity:0.5; /* 文字も半透明 */
とします。

2. サンプル

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>HTML・CSS・JavaScript</title>
    <style>
      .header {
        position: fixed;
        top: 0px;
        width: 100%;
        height: 30px;
        border:1px solid #ccc;
        background-color: rgba(255, 255, 255, 0.8); /* 背景のみ半透明 */
        /* opacity:0.5; 文字も半透明 */
      }
    </style>
  </head>
  <body style="margin:0px; background-color:#fff; color:#000;">
    <div class="header">
      ヘッダー
    </div>
    <div style="background-color:#e0e0e0;">
      <br /><br />
      ああああああああああ<br />
      いいいいいいいいいい<br />
      うううううううううう<br />
      ええええええええええ<br />
      おおおおおおおおおお<br />
      かかかかかかかかかか<br />
      きききききききききき<br />
      くくくくくくくくくく<br />
      けけけけけけけけけけ<br />
      ここここここここここ<br />
      ささささささささささ<br />
      しししししししししし<br />
      すすすすすすすすすす<br />
      せせせせせせせせせせ<br />
      そそそそそそそそそそ<br />
    </div>
  </body>
</html>


実行結果:

YouTube X

新着一覧

  • SCSS のインストールVite
  • Tailwind CSS のプロジェクトの作成Tailwind
  • TypeScriptのプロジェクトの作成Vite
  • Flask のインストールと動作確認Python
  • 簡易Webサーバーの作成Python
  • pipeline で文章の生成Python
  • pipeline で文章の要約Python
  • 音声から文字起こしPython
  • Node.js のインストールNode.js
  • .ps1(PowerShellスクリプト)を実行可能にするPowerShell

アーカイブ

  • 2025/12
  • 2025/11
  • 2025/10
  • 2025/09
  • 2025/08

以前のカテゴリー一覧

  • CakePHP3
  • CentOS7
  • HTML・CSS・JavaScript
  • Haskell
  • JavaScript
  • Kotlin
  • Laravel5
  • PHP
  • Python
  • Ruby
  • RubyOnRails5
  • TypeScript
  • Vue.js
  • Webサーバ講座
  • Webプログラミング講座
  • jQuery
  • linux
  • パソコン講座
  • ブログ
  • プログラミング講座
  • メモ帳作成講座
  • 数学

Copyright © 9cubed. All Rights Reserved.

プライバシーポリシー 利用規約
▲