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

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

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

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

CSS

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

Q&A

解決済

1回答

1472閲覧

画像とテキストの左右振り分けでうまく反映されません

kkbeams

総合スコア17

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

CSS

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

0グッド

0クリップ

投稿2019/05/03 07:44

どっとインストールの「左右振り分け」の章で写経しながら勉強していたのですが、いざ自分で打ってプレビューすると画像とテキストがずれてしまいます。

どこが原因でしょうか??
ご教授いただければ幸いですm(__)m

イメージ説明

html

1<!doctype html> 2<html lang="ja"> 3<head> 4<meta charset="utf-8"> 5<title>Dotinstall Pane</title> 6<link rel="shortcut icon" href="dotinstall 素材/avicon.ico"> 7<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous"> 8<link rel="stylesheet" href="css/styles.css"> 9</head> 10 11<body> 12<header class="orange-bg"> 13 <div class="container"> 14 <h1>Dotinstall Pane</h1> 15 <p>どっとインストールを見ながら<br/> 16 コーディングできるAtomパッケージ</p> 17 <a href="#" target="_blank" class="btn">詳細を見る <i class="fas fa-external-link-alt"></i></a> 18 <img src="dotinstall 素材/top.png" width="480" height="270" alt="Dotinstall Pane"> 19 </div> 20</header> 21<section class="features"> 22 <div class="container"> 23 <h1 data-subtitle="-Features-" class="section-title">Dotinstall Paneの特徴</h1> 24 <section class="feature"> 25  <img src="dotinstall 素材/feature1.png" width="420px" height="270px" alt="特徴1"> 26 <div class="desc"> 27 <h1>スゴイ特徴</h1> 28 <p>いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。</p> 29 </div> 30 </section> 31 <section class="feature"> 32  <img src="dotinstall 素材/feature2.png" width="420px" height="270px" alt="特徴2"> 33 <div class="desc"> 34 <h1>スゴイ特徴</h1> 35 <p>いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。</p> 36 </div> 37 </section> 38 <section class="feature"> 39  <img src="dotinstall 素材/feature3.png" width="420px" height="270px" alt="特徴3"> 40 <div class="desc"> 41 <h1>スゴイ特徴</h1> 42 <p>いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。</p> 43 </div> 44 </section> 45 </di v> 46</section> 47</body> 48</html> 49

css

1@charset "utf-8"; 2/* CSS Document */ 3body{ 4 font-size: 15px; 5 color:#333; 6 font-family: Verdana, Geneva, "sans-serif"; 7 margin: 0; 8} 9 10.container{ 11 width: 820px; 12 margin: 0 auto; 13 padding: 60px 0; 14} 15 16.orange-bg{ 17 color:#FFF; 18 background: url("../dotinstall 素材/bg.png"); 19 background-size:cover; 20} 21 22.section-title{ 23 text-align: center; 24 font-weight:normal; 25 font-size:24px; 26 margin-bottom: 60px; 27 margin-top: 0; 28} 29/*header*/ 30 31header h1{ 32 margin-top: 0; 33 font-weight:normal; 34 font-size:36px; 35 margin-bottom: 8px; 36} 37 38header p{ 39 margin-top: 0; 40 margin-bottom: 50px; 41} 42 43header .container{ 44 45 position: relative; 46} 47 48header img{ 49 position:absolute; 50 bottom: 0; 51 right:0; 52} 53 54.btn{ 55 display:inline-block; 56 width:290px; 57 background: #fff; 58 color:#DE864E; 59 text-align: center; 60 opacity: 0.9; 61 border-radius: 5px; 62 text-decoration: none; 63 padding: 8px 0; 64 65} 66 67.btn:hover{ 68 opacity:1.0; 69} 70 71 72.features h1::after{ 73 content: attr(data-subtitle); 74 display:block; 75 font-size:16px; 76 color:#AAAAAA; 77 padding-top: 10px; 78} 79 80.feature h1{ 81 font-style:normal; 82 font-size:18px; 83} 84 85.feature .desc{ 86 width:360px; 87} 88 89.feature:nth-of-type(odd) .desc{ 90 float:right; 91 padding-left: 40px; 92} 93 94.feature:nth-of-type(even) .desc{ 95 float:left; 96 padding-right: 40px; 97}

リンク内容

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

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

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

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

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

guest

回答1

0

ベストアンサー

下記でいかがでしょうか、、

</section>前の</div>も変な形になっています。。
<!doctype html> <html lang="ja"> <head> <meta charset="utf-8"> <title>Dotinstall Pane</title> <link rel="shortcut icon" href="dotinstall 素材/avicon.ico"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous"> <link rel="stylesheet" href="css/styles.css"> </head> <body> <style> @charset "utf-8"; /* CSS Document */ body{ font-size: 15px; color:#333; font-family: Verdana, Geneva, "sans-serif"; margin: 0; } .container{ width: 820px; margin: 0 auto; padding: 60px 0; } .orange-bg{ color:#FFF; background: url("https://images.pexels.com/photos/2225213/pexels-photo-2225213.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"); background-size:cover; } .section-title{ text-align: center; font-weight:normal; font-size:24px; margin-bottom: 60px; margin-top: 0; } /*header*/ header h1{ margin-top: 0; font-weight:normal; font-size:36px; margin-bottom: 8px; } header p{ margin-top: 0; margin-bottom: 50px; } header .container{ position: relative; } header img{ position:absolute; bottom: 0; right:0; } .btn{ display:inline-block; width:290px; background: #fff; color:#DE864E; text-align: center; opacity: 0.9; border-radius: 5px; text-decoration: none; padding: 8px 0; } .btn:hover{ opacity:1.0; } .features h1::after{ content: attr(data-subtitle); display:block; font-size:16px; color:#AAAAAA; padding-top: 10px; } .feature h1{ font-style:normal; font-size:18px; } .feature .desc{ width:360px; } .feature:nth-of-type(odd) .desc{ float:right; /*padding-left: 40px;*/ } .feature:nth-of-type(even) .desc{ float:left; /*padding-right: 40px;*/ } /*section.feature{ display: flex; }*/ </style> <header class="orange-bg"> <div class="container"> <h1>Dotinstall Pane</h1> <p>どっとインストールを見ながら<br/> コーディングできるAtomパッケージ</p> <a href="#" target="_blank" class="btn">詳細を見る <i class="fas fa-external-link-alt"></i></a> <img src="https://images.pexels.com/photos/2225213/pexels-photo-2225213.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" width="480" height="270" alt="Dotinstall Pane"> </div> </header> <section class="features"> <div class="container"> <h1 data-subtitle="-Features-" class="section-title">Dotinstall Paneの特徴</h1> <section class="feature">  <img src="https://images.pexels.com/photos/2225213/pexels-photo-2225213.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" width="420px" height="270px" alt="特徴1"> <div class="desc"> <h1>スゴイ特徴</h1> <p>いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。</p> </div> </section> <section class="feature">  <img src="https://images.pexels.com/photos/2225213/pexels-photo-2225213.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" width="420px" height="270px" alt="特徴2"> <div class="desc"> <h1>スゴイ特徴</h1> <p>いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。</p> </div> </section> <section class="feature">  <img src="https://images.pexels.com/photos/2225213/pexels-photo-2225213.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" width="420px" height="270px" alt="特徴3"> <div class="desc"> <h1>スゴイ特徴</h1> <p>いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。いろいろありますよ。</p> </div> </section> </div> </section> </body> </html>

投稿2019/05/03 09:13

編集2019/05/03 13:58
wataame

総合スコア302

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

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

kkbeams

2019/05/03 09:32

ご回答ありがとうございます。 divも修正したのですが、直りません、、 エディタに問題があるのでしょうか、、
wataame

2019/05/03 09:33

添付したコードでもダメでしょうか。。自分の方では再現できています。もし反映されない場合はブラウザにキャッシュが残っている場合がありますので一度ブラウザを閉じる、キャッシュを削除する、再度開いて確認してみてください。
wataame

2019/05/03 09:41

あとcssに下記のコードを追記してください。 section.feature{ display: flex; }
kkbeams

2019/05/03 09:56

cssコード追加しました! そしたら、テキスト部分のずれは直りました! しかし偶数番目のfeatureが画像とテキストで逆にならないです、、 どうしてですかね??
wataame

2019/05/03 13:57

大変失礼しました。再修正したのを添付します。(ご希望通りかはわかりません。)
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問