0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ヘッダーを追従させるcss

Posted at

ヘッダーを追従させるcss

・position: fixedを使って位置を固定する
・ヘッダーの後ろに他の要素が回り込まないようにbodyにヘッダーの高さだけmarginを入れる

body {
  margin: 50px 0 0 0;
}

.header {
    background-color: coral;
    position: fixed;
    width: 100%;
    height: 50px;
    top: 0;
    left: 0;
}

.dummy {
    width: 250px;
    height: 250px;
    margin-bottom: 30px;
    background-color: wheat;
}
import React from 'react'
import './Hoge.css'

export const Hoge = () => {
    return (
        <>
            <div className="header">
            </div>
            <div className="dummy">dummy</div>
            <div className="dummy">dummy</div>
            <div className="dummy">dummy</div>
            <div className="dummy">dummy</div>
            <div className="dummy">dummy</div>
            <div className="dummy">dummy</div>
            <div className="dummy">dummy</div>
            <div className="dummy">dummy</div>
            <div className="dummy">dummy</div>
        </>
    )
}

結果
ezgif.com-gif-maker (1).gif

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?