0
0

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

今回は作成中のポートフォリオの背景が、
色をつけるだけでは寂しいので景色の画像を貼って見ました。
その時の貼る方法の備忘録を書いて行きます。
  

背景に画像を貼る

(例)

form__wrapper {
  background-image: url("sea.jpg");
  background-image: no-repeat;
  background-position: 50% 50%;
}

これで背景が変わりました。
urlの中身は(貼りたい画像の名前を記入)
**・**assetsのimagesファイルに画像を保存しておく必要がある。

repeat:背景画像を縦方向、横方向双方に繰り返し表示する(初期値)
repeat-x:背景画像を横方向に繰り返し表示する
repeat-y:背景画像を縦方向に繰り返し表示する
no-repeat:背景画像を繰り返さず1つだけ表示する
  

marginを使うと背景の画像が微妙にズレていくので、
background-positionで調整してあげる。

 
 

こんなのもありました。↓↓

background:

上記のプロパティーを使えば
background-color
background-image
background-repeat
background-position
background-size
background-origin
background-clip
background-attachment

を、まとめて1行で指定するそうです。
めちゃくちゃ便利ですね。
最初からこれでもよかったってのが
結論でした。

  

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?