質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

Q&A

解決済

2回答

229閲覧

CSSで背景画像の指定がしたいが反映されない

Kinako0626

総合スコア14

CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

0グッド

0クリップ

投稿2019/05/18 15:07

編集2019/05/18 15:46

前提・実現したいこと

現在Youtubeにてtech academy様の初めてのCSS入門講座7-2 背景の指定の応用(CSSの背景)をみて独学しているものです。
動画の受講内容の流れとして概要→コードのサンプル→講師の方の解説しながら自分で入力してみるという流れなのですが背景画像がサンプル通りに作成しているはずなのに反映されなくて調べてみたり間違いないか確認してみたがサンプル通りに入力しています。
画像が表示されないのを解決したいです
大変お手数おかけしますがご協力をお願い申し上げます。

発生している問題・エラーメッセージ

CSSの背景画像が標示されない

エラーメッセージ

該当のソースコード

index.html

<html> <head> <title>Background Properties</title> <link rel="stylesheet" href="page-styles.css"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="box"></div> </body> </html> ```##HTML2 index-2.html ```<!DOCTYPE html> <html> <head> <title>Background Properties</title> <link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="page-styles.css"> </head> <body> <div class="scroll attch"> <h2>Scroll</h2> <p> The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. </p> <p> There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. </p> </div> <div class="fixed attch"> <h2>Fixed</h2> <p> There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. </p> <p> There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. </p> </div> <div class="local attch"> <p> There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. </p> <p> There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. </p> </div> </body> </html> ```##CSS style.css

box{
background-color: #E4E4E4;
background-image: url('ta.png');
background-repeat: repeat;
}

.scroll{
background-attachment: scroll;/This is the default value/
}

.fixed{
background-attachment: fixed;
}

.local{
background-attachment: local;
}

### 試したこと ファイルパスをダブルクォーテーションで囲んでみたり、クォーテーション無しで読み込みしてみたりしました。 ### 補足情報(FW/ツールのバージョンなど) ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kei344

2019/05/18 15:24

(質問文は編集できます)質問文のコードはそれぞれコードブロックで囲んでいただけませんか? ```(バッククオート3つ)で囲み、前後に改行をいれるか、コードを選択して「<code>」ボタンを押すとコードブロックになります。
kei344

2019/05/18 15:32

バッククオート3つの前後には改行を入れてください。PCであれば記入エリアの右部分あたりにリアルタイムに結果が表示されていると思うので、そこを見ながら調整してください。
Kinako0626

2019/05/18 15:32

畏まりました。 ご迷惑おかけして申し訳ございません。ただいま完了致しました。 よろしくお願いいたします!
guest

回答2

0

ベストアンサー

質問文が切れてしまっているのでCSSがおかしいし、index-2.htmlはなぜかかれているかもわかりませんが、<div class="box"></div>に高さが無いから画像が表示されていないのではないでしょうか。

HTML

1<div class="box">ここに何か文字を入れてみる</div>

投稿2019/05/18 15:37

kei344

総合スコア69400

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Kinako0626

2019/05/18 22:49

文字入れてみたのですが画像の表示はされませんでした。 それとindex-2.htmlについては、CSSに書いてあるboxから下の要素?を反映させるために2つ作ったみたいです。 なので恐らく一つのCSSで二種類のHTMLを反映させようとしてるのではないかと思います。 一つ目がCSSでrepeatの練習、二つ目のHTMLではスクロールさせて背景画像がどうなるか見せたいということだと思います 情報不足で分かりづらく申し訳ございません。
kei344

2019/05/19 02:47

動くサンプル: https://jsfiddle.net/o190rtLc/ では画像ファイル名かファイルパス、もしくは編集するファイルを間違っていないかを確認してください。
Kinako0626

2019/05/20 03:15

ありがとうございました!無事解決できました。
guest

0

質問の意図が今ひとつ読み取れませんが、<div class="box"></div>のCSSが反映されていないのは、セレクタの記述に誤りがあるのと、「kei344」さんの回答のとおり、高さが無いのが原因と思われます。

投稿2019/05/19 01:33

yoshinavi

総合スコア3523

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問