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

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

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

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

HTML

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

CSS

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

Q&A

解決済

1回答

732閲覧

headerにfixedを設定している状況で、スムーススクロールのずれを改善したい

sakaseteotome

総合スコア2

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

HTML

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

CSS

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

0グッド

1クリップ

投稿2021/11/10 15:23

編集2021/11/10 15:34

headerにfixedを設定しているため、スムーススクロールをしようとすると、headerの高さも一緒に含まれてスクロールがずれてしまいます。
headerの高さも一緒に含めないようにするにはどうしたらよいでしょうか。

↓一番最初の「特徴」のページのスクロールは上手くいくのですが、

<li><a href="#features-link">特徴</a></li>

↓2番目の「価格」、3番目の「お問い合わせ」のページのスクロールがずれてしまいます。

<li><a href="#price-link">価格</a></li> <li><a href="#contact-link">お問い合わせ</a></li>

・padding-top: 94px;
・margin-top: -94px;
↑以上のようにネガティブマージンを使ってもずれてしまいます。

ネガティブマージンを2番目の「価格」、3番目の「お問い合わせ」に適用させると、何故かpadding-top: 94px;だけ適用されるのも気になります。

以上になります。
よろしくお願い致します。

javascript

1jQuery(function(){ 2 var headerHight = 80; //ヘッダーの高さをpx指定 3 //*ページ内リンクの指定 4 jQuery('a[href^=#]').click(function(){ 5 var href= jQuery(this).attr("href"); 6 var target = jQuery(href == "#" || href == "" ? 'body' : href); 7 var position = target.offset().top-headerHight; 8 jQuery("html, body").animate({scrollTop:position}, 550, "swing"); 9 return false; 10 }); 11 //*ページ外リンクの指定*/ 12 var url = jQuery(location).attr('href'); 13 if (url.indexOf("?id=") == -1) { 14 // ほかの処理 15 }else{ 16 var url_sp = url.split("?id="); 17 var hash = '#' + url_sp[url_sp.length - 1]; 18 var target2 = jQuery(hash); 19 var position2 = target2.offset().top-headerHight; 20 jQuery("html, body").animate({scrollTop:position2}, 550, "swing"); 21 } 22 });

html

1<header class="header"> 2 <div class="header-content"> 3 <div class="header-logo"> 4 <img src="img/logo.png"> 5 </div> 6 <a class="header-title" href="index.html"> 7 <h1>ユアコーディング</h1> 8 </a> 9 <nav class="header-menu"> 10 <li><a href="#features-link">特徴</a></li> 11 <li><a href="#price-link">価格</a></li> 12 <li><a href="#contact-link">お問い合わせ</a></li> 13 </nav> 14 <div class="header-contact"> 15 <a href="#contact-link" class="header-contact-color">お問い合わせ</a> 16 </div> 17 </div> 18 </header> 19 <section class="main" data-aos="fade-down"> 20 <div class="main-maru-img"> 21 <img src="img/maru.png"> 22 </div> 23 <div class="main-visual"> 24 <div class="main-visual-text-box"> 25 <div class="main-visual-text-1"> 26 コーディングの手間を<br> 最小に、デザインに注力<br>する助けに 27 </div> 28 <div class="main-visual-text-2"> 29 ユアコーディングはコーディングに<br>特化したフリーランス<br>デザインに注力されたい方の<br>助けになります 30 </div> 31 <div class="main-visual-text-contact"> 32 <a href="" class="main-visual-text-contact-background">お問い合わせ</a> 33 </div> 34 </div> 35 <div class="main-visual-img-box"> 36 <div class="main-visual-img"> 37 <img src="img/manager.png"> 38 </div> 39 </div> 40 </section> 41 42 <section class="features" data-aos="fade-up" id="features-link"> 43 <h2 class="features-head">ユアコーディング3つの特徴</h2> 44 <h4 class="features-Eng">FEATURES</h4> 45 <h3 class="features-kousoku-code">高速コーディング</h3> 46 <section class="features-item"> 47 <div class="features-kousoku-code-img"><img src="img/cto.png"></div> 48 <div class="features-kousoku-code-text-box"> 49 <div class="features-kousoku-code-text-head">コーディングに特化したフリーランスのため、<br>スピード感を持った開発が可能。</div> 50 <div class="features-kousoku-code-text">開発は常にスピードとの勝負です。<br>ユアコーディングはコーディングに特化しているため、<br>素早く納品することで、クライアントがデザインに注力<br>する助けとなります。</div> 51 </div> 52 </section> 53 <h3 class="features-kouhinshitu">高品質</h3> 54 <section class="features-item-2"> 55 <div class="features-kouhinshitu-text-box"> 56 <div class="features-kouhinshitu-text-head">正しいマークアップで、<br>内部SEOに強いコーディングを<br>デフォルトで行います。</div> 57 <div class="features-kouhinshitu-text">ユアコーディングでは、「予測しやすい」「再利用しやすい」<br>「保守しやすい」「拡張しやすい」と言った設計をもとに<br>きちんとコーディングを行うため、納品後も安心です。</div> 58 </div> 59 <div class="features-kouhinshitu-img"><img src="img/building_website.png"></div> 60 </section> 61 <h3 class="features-zinsoku">迅速なレスポンス</h3> 62 <section class="features-item3"> 63 <div class="features-zinsoku-img"><img src="img/new_message.png"></div> 64 <div class="features-zinsoku-text-box"> 65 <div class="features-zinsoku-text-head">原則いただいたメッセージは、<br>業務時間内であれば6時間以内に<br>お返しいたします。</div> 66 <div class="features-zinsoku-text">連絡を返さないフリーランスが多い中、<br>ユアコーディングでは定期的な進捗報告など、<br>社会人としての基本を踏まえて仕事を行なって<br>おります。</div> 67 </div> 68 </section> 69 </section> 70 <section class="price" data-aos="fade-up" id="price-link"> 71 <h2 class="price-head">価格</h2> 72 <h4 class="price-ing">PRICE</4> 73 <div class="price-table"> 74 <table border="1"> 75 <tr> 76 <td>HTMLコーディングトップページ</td><td>30.000円〜</td> 77 </tr> 78 <tr> 79 <td>HTMLコーディング下層1ページ</td><td>10.000円〜</td> 80 </tr> 81 <tr> 82 <td>HTML+WordPressトップページ</td><td>55.000円〜</td> 83 </tr> 84 <tr> 85 <td>HTML+WordPress下層1ページ</td><td>15.000円〜</td> 86 </tr> 87 </table> 88 </div> 89 <div class="price-syousai">*詳細な価格はページや仕様によって異なります</div> 90 </section> 91 92</div> 93</section> 94<section class="contact" data-aos="fade-up" id="contact-link"> 95 <h2 class="contact-head">お問い合わせ</h2> 96 <h4 class="contact-ing">CONTACT</h4> 97 <h4 class="contact-text">コーディングの人出が足りないとき、<br>あなたの力になります</h4> 98 <div class="contact-form"> 99 <form action="#" method="post"> 100 <ul class="contact-box"> 101 <li> 102 <lavel class="form-label">お名前</lavel> 103 <div><input type="text" name="name" class="contact-nyuuryoku" placeholder="お名前"></div> 104 </li> 105 <li> 106 <lavel class="form-label">メールアドレス</lavel> 107 <div><input type="text" name="male" class="contact-nyuuryoku" placeholder="メールアドレス"></div> 108 </li> 109 <li> 110 <lavel class="form-label">お問い合わせ内容</lavel> 111 <div><textarea name="contact" class="contact-nyuuryoku-naiyou" placeholder="お問い合わせ内容"></textarea></div> 112 </li> 113 <li class="privacy-policy"> 114 <input type="checkbox" class="checkbox" id="confirmation"> 115 <label for="confirmation" class="privacy-text"> 116 プライバシーに同意する 117 </label> 118 </li> 119 </ul> 120 <div class="sousin-btn"><input type="submit" value="送信"></div> 121 </form> 122 </div> 123</section>

scss

1 2.price { 3width: 100%; 4background-color: #EEFBFB; 5.price-head { 6 width: 100%; 7 padding-top: 55px; 8 text-align: center; 9 font-size: 32px; 10} 11.price-ing { 12 margin-top: 11px; 13 font-size: 16px; 14 width: 100%; 15 text-align: center; 16 color: $ing; 17} 18.price-table { 19 width: 926px; 20 margin: 0 auto; 21 margin-top: 70px; 22 color: $text-base-color; 23} 24table { 25width: 100%; 26box-shadow: 0px 3px 6px rgba(102, 101, 101, 0.164); 27border: solid rgba(102, 101, 101, 0.164); 28border-collapse:collapse; 29background: #FFF; 30 tr { 31 32 } 33 34 td 35{ 36padding-top: 35px; 37padding-bottom: 35px; 38padding-left: 30px; 39text-align: left; 40} 41td:first-child { 42 width: 31%; 43 padding-left: 19px; 44 text-align: left; 45} 46} 47.price-syousai { 48 width: 100%; 49 text-align: center; 50 margin-top: 36px; 51 color: #444444; 52 padding-bottom: 68px; 53} 54} 55 56.contact { 57 width: 100%; 58 height: 1027px; 59 background: linear-gradient(90deg, #05A5FA, #67FFD6); 60.contact-head { 61 padding-top: 63px; 62 width: 100%; 63 text-align: center; 64 font-size: 32px; 65 color: $contact-color; 66} 67.contact-ing { 68 width: 100%; 69 text-align: center; 70 margin-top: 7px; 71 font-size: 16px; 72 color: $contact-color; 73}.contact-text { 74 margin-top: 36px; 75 text-align: center; 76 font-size: 16px; 77 color: $contact-color; 78}.contact-form { 79 width: 908px; 80 height: 700px; 81 background-color: $contact-color; 82 margin: 0 auto; 83 margin-top: 44px; 84}.contact-box { 85 padding-top: 34px; 86 list-style: none; 87 li { 88 font-weight: bold; 89 font-size: 16px; 90 margin-left: 63px; 91.contact-nyuuryoku { 92 margin-top: 39px; 93 background-color: $form-backcolor; 94 border: #EEFBFB solid; 95 border-radius: 3px; 96 width: 499px; 97 height: 43px; 98} .contact-nyuuryoku-naiyou { 99 width: 783px; 100 height: 179px; 101 margin-top: 39px; 102 background-color: $form-backcolor; 103 border: #EEFBFB solid; 104 border-radius: 3px; 105} 106.contact-nyuuryoku:first-child { 107 margin-bottom: 27px; 108} 109.contact-nyuuryoku:second-child { 110 margin-bottom: 21px; 111 } 112} 113li:last-child { 114 text-align: center; 115 margin-left: 0px; 116 margin-top: 27px; 117} 118}/* .contact-box */ 119.sousin-btn { 120text-align: center; 121} 122input[type="submit"] { 123color: $contact-color; 124background-image: $contact-background-color; 125padding: 9px 50px; 126border: transparent 0px solid; 127border-radius: 10px; 128font-size: 14px; 129font-weight: bold; 130margin-top: 38px; 131} 132}/* .contact */ 133 134

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

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

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

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

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

guest

回答1

0

ベストアンサー

var headerHight = 80; //ヘッダーの高さをpx指定としているからではないですか?

投稿2021/11/11 00:54

Lhankor_Mhy

総合スコア36158

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

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

sakaseteotome

2021/11/11 11:12

ご対応ありがとうございます。 var headerHight = 80; をheaderの高さである94に修正しましたが、依然としてずれてしまう状態です……。
sakaseteotome

2021/11/16 10:34

ご返信遅くなり申し訳ありません。 ただいま確認したところ確かにそちらの環境では問題なく動作していることを確認しました! ありがとうございました。 とりあえず違う環境でやってみるなどで対策を考えていきたいと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問