久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何抵消固定導航欄將我帶到的位置?

How do I offset where my fixed nav bar takes me?(如何抵消固定導航欄將我帶到的位置?)
本文介紹了如何抵消固定導航欄將我帶到的位置?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我的網站上有一個固定的導航欄,它位于頂部,帶有可將我帶到頁面下方不同部分的鏈接.但是,因為我的固定導航欄的高度為 40px,所以每個部分的開頭 40px 都被覆蓋了.我將如何使用 HTML 或 CSS 將我的鏈接帶我的位置偏移 40 像素?謝謝.

I have a fixed navigation bar on my website that stays at the top with links that take me to different sections further down the page. However, because my fixed nav bar has a height of 40px, the beginning 40px of every section is covered up. How would I offset where my links take me by 40px using either HTML or CSS? Thanks.

推薦答案

您可以嘗試將虛擬"錨點絕對定位在每個部分頂部上方 40 像素處.您可以給它們零寬度/高度和隱藏可見性,以確保這些錨點不會影響頁面的顯示方式.當用戶單擊固定導航欄中的鏈接之一時,窗口將滾動到虛擬錨點的頂部,在其實際部分的開頭上方 40 像素處.

You might try absolutely positioning "dummy" anchors 40 pixels above the top of each section. You can give them zero width/height and hidden visibility to ensure that these anchors don't affect how your page is displayed. When the user clicks one of the links in your fixed navigation bar, the window will scroll to the top of the dummy anchor, 40 pixels above the beginning of its actual section.

示例 HTML:

<div class="navbar">
  <a href="#anchor1">Anchor 1</a>
  <a href="#anchor2">Anchor 2</a>
  <a href="#anchor3">Anchor 3</a>
</div>
<div class="section">
  <span id="anchor1" class="anchor"></span>
  Section Content
</div>
<div class="section">
  <span id="anchor2" class="anchor"></span>
  Section Content
</div>
<div class="section">
  <span id="anchor3" class="anchor"></span>
  Section Content
</div>?

示例 CSS:

body {
    padding-top: 40px;
}
.navbar {
    position: fixed;
    width: 100%;
    height: 40px;
    top: 0;
    left: 0;
    z-index: 10;
    border-bottom: 1px solid #ccc;
    background: #eee;
}
.section {
    position: relative;
}
.anchor {
    display: block;
    position: absolute;
    width: 0;
    height: 0;
    z-index: -1;
    top: -40px;
    left: 0;
    visibility: hidden;
}

有關工作示例,請參閱 http://jsfiddle.net/HV7QL/

For a working example, see http://jsfiddle.net/HV7QL/

CSS3 還包括 :target 偽類,它適用于 id 已被 引用的元素>href 文檔中的鏈接,或 URL 的哈希值.您可以在 :target 的頂部應用 40 像素的填充,該填充將僅應用于用戶從固定導航欄中選擇的部分.

CSS3 also includes the :target pseudo-class, which applies to an element whose id has been referenced by the href of a link in the document, or the hash value of the URL. You can apply a 40-pixel padding to the top of the :target that will be applied only to the section the user selects from the fixed navbar.

示例 CSS:

.section:target {
    padding-top: 40px;
}

這在語義上比上述方法更清晰,但不適用于舊版瀏覽器.

This is semantically cleaner than the method described above, but won't work on older browsers.

工作示例:http://jsfiddle.net/5Ngft/

這篇關于如何抵消固定導航欄將我帶到的位置?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to check for duplicate CSS rules?(如何檢查重復的 CSS 規則?)
Remove duplicate CSS declarations across multiple files(刪除多個文件中的重復 CSS 聲明)
How can I duplicate a div onclick event?(如何復制 div onclick 事件?)
opening html from google drive(從谷歌驅動器打開 html)
How to embed videos from Google drive to webpage?(如何將視頻從 Google 驅動器嵌入到網頁?)
How to view Google drive pdf link in iframe(如何在 iframe 中查看 Google Drive pdf 鏈接)
主站蜘蛛池模板: 国产免费黄网 | 视频一区二区中文字幕日韩 | 成人黄色电影在线观看 | 美女福利视频一区 | 久久精品亚洲成在人线av网址 | 噜噜噜噜狠狠狠7777视频 | 成年人精品视频在线观看 | 日本久久精品视频 | 亚洲一区二区三区高清 | 亚洲欧美日韩系列 | 欧美一级视频免费看 | 国产第一区二区 | 婷婷毛片| 欧美国产一区二区三区 | 一级毛片色一级 | 一区精品国产欧美在线 | 国产精品成人品 | 亚洲成人毛片 | 亚洲精品国产精品国自产在线 | 国产一区91在线 | 色综合天天综合网国产成人网 | 中文字幕欧美日韩 | 国产三级精品三级在线观看四季网 | 亚洲成人激情在线观看 | 日韩精品激情 | 亚洲精品国产区 | 欧美片网站免费 | 日韩毛片免费看 | 精品一区二区不卡 | 在线中文字幕av | 国产精品久久久久久妇女 | 亚洲成人一区 | 激情五月综合 | 精品国产一区二区三区免费 | 亚洲一区电影 | 日韩一| 成人欧美一区二区三区白人 | 亚洲成人三级 | 成人亚洲在线 | 亚洲人成一区二区三区性色 | 一区二区三区电影在线观看 |