html頁面Bootstrap頂部的白條 (White bar at top of html page Bootstrap)


問題描述

html頁面Bootstrap頂部的白條 (White bar at top of html page Bootstrap)

頁面頂部會出現一個白條,表示要包含圖像的部分。通過刪除網頁的不同部分,我發現刪除打開和關閉標籤可以修復它,但我仍然需要包含它們。此外,刪除引導程序也可以解決問題,但我稍後需要引導程序。我真的不知道是什麼導致了這個問題。

* {
  margin: 0;
  padding: 0;
  list‑style: none;
  text‑decoration: none;
}

body {
  font‑family: 'Raleway', sans‑serif;
}

.sidebar {
  top: 0;
  position: fixed;
  left: ‑250px;
  width: 250px;
  height: 100%;
  background: rgb(4, 11, 20);
  transition: all .5s ease;
}

.sidebar header {
  font‑size: 22px;
  color: white;
  text‑align: center;
  line‑height: 70px;
  background: rgb(4, 11, 20);
  user‑select: none;
}

.sidebar ul a {
  display: block;
  height: 100%;
  width: 100%;
  line‑height: 65px;
  font‑size: 20px;
  color: white;
  padding‑left: 40px;
  transition: 0.3s;
  opacity: 0.8;
}

ul li:hover a {
  padding‑left: 45px;
  opacity: 1;
}

.sidebar ul a i {
  margin‑right: 8px;
}

#check {
  display: none;
}

label #menu‑open,
label #menu‑close {
  position: absolute;
  cursor: pointer;
}

label #menu‑open {
  left: 40px;
  top: 15px;
  font‑size: 35px;
  color: black;
  padding: 6px 12px;
  transition: all .5s;
}

label #menu‑close {
  z‑index: 1111;
  left: 195px;
  top: 15px;
  font‑size: 30px;
  color: white;
  padding: 4px 9px;
  opacity: 0;
  transition: all .5s;
  transition‑delay: .5s;
}

#check:checked~.sidebar {
  left: 0;
}

#check:checked~label #menu‑open {
  left: 250px;
  opacity: 0;
  pointer‑events: none;
}

#check:checked~label #menu‑close {
  opacity: 1;
}

section {
  background: url("https://images.pexels.com/photos/1779487/pexels‑photo‑1779487.jpeg?cs=srgb&dl=pexels‑designecologist‑1779487.jpg") no‑repeat;
  background‑position: center;
  background‑size: cover;
  height: 100vh;
  transition: all .5s;
}
<!doctype html>
<html lang="en" dir="ltr">

<head>
  <!‑‑ Required meta tags ‑‑>
  <meta charset="utf‑8">
  <meta name="viewport" content="width=device‑width, initial‑scale=1, shrink‑to‑fit=no">

  <!‑‑ Bootstrap CSS ‑‑>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384‑ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap‑icons@1.5.0/font/bootstrap‑icons.css">
  <link href="css/style.css" rel="stylesheet">
  <title>Tyler Wong Portfolio</title>
</head>

<body>

  <input type="checkbox" id="check">
  <label for="check">
          <i class="bi bi‑list" id="menu‑open"></i>
          <i class="bi bi‑x" id="menu‑close"></i>
        </label>
  <div class="sidebar">
    <header>Tyler Wong</header>
    <ul>
      <li>
        <a href="#"> <i class="bi bi‑house‑door"></i> Home </a>
      </li>
      <li>
        <a href="#"> <i class="bi bi‑person"></i> About </a>
      </li>
      <li>
        <a href="#"> <i class="bi bi‑code‑square"></i> Projects </a>
      </li>
      <li>
        <a href="#"> <i class="bi bi‑mailbox"></i> Contact </a>
      </li>

    </ul>
  </div>

  <script src="https://code.jquery.com/jquery‑3.3.1.slim.min.js" integrity="sha384‑q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384‑UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384‑JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

  <section></section>

</body>

</html>






<hr>




<h2>參考解法</h2>

<h4>方法 1:</h4> <p>The problem is <code><label for="check"></code> you are putting this element in top as <code>inline‑block</code>, a simple solution is change it to</p>
<p><code><label for="check" style="display: inline;"></code></p>
<p><div class=

* {
  margin: 0;
  padding: 0;
  list‑style: none;
  text‑decoration: none;
}
body{
  font‑family: 'Raleway', sans‑serif;
}
.sidebar{
  top:0;
  position: fixed;
  left: ‑250px;
  width: 250px;
  height: 100%;
  background: rgb(4,11,20);
  transition: all .5s ease;
}
.sidebar header{
  font‑size: 22px;
  color: white;
  text‑align: center;
  line‑height: 70px;
  background: rgb(4,11,20);
  user‑select: none;
}
.sidebar ul a {
  display: block;
  height: 100%;
  width: 100%;
  line‑height: 65px;
  font‑size: 20px;
  color: white;
  padding‑left: 40px;
  transition:0.3s;
  opacity: 0.8;
}
ul li:hover a{
  padding‑left: 45px;
  opacity: 1;
}
.sidebar ul a i{
  margin‑right: 8px;
}
#check{
  display: none;
}
label #menu‑open,label #menu‑close{
  position: absolute;
  cursor: pointer;
}
label #menu‑open{
  left: 40px;
  top: 15px;
  font‑size: 35px;
  color: black;
  padding: 6px 12px;
  transition: all .5s;
}

label #menu‑close{
  z‑index: 1111;
  left: 195px;
  top: 15px;
  font‑size: 30px;
  color: white;
  padding: 4px 9px;
  opacity: 0;
  transition: all .5s;
  transition‑delay: .5s;
}
#check:checked ~ .sidebar{
  left:0;
}
#check:checked ~ label #menu‑open{
  left: 250px;
  opacity: 0;
  pointer‑events: none;
}
#check:checked ~ label #menu‑close{
  opacity:1;
}

section {
  background: red no‑repeat;
  background‑position: center;
  background‑size: cover;
  height: 100vh;
  transition: all .5s;
}
<!doctype html>
<html lang="en" dir="ltr">
  <head>
    <!‑‑ Required meta tags ‑‑>
    <meta charset="utf‑8">
    <meta name="viewport" content="width=device‑width, initial‑scale=1, shrink‑to‑fit=no">

    <!‑‑ Bootstrap CSS ‑‑>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384‑ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap‑icons@1.5.0/font/bootstrap‑icons.css">
    <!‑‑ Ignore for Code Snippet ‑‑>
    <!‑‑ <link href="css/style.css" rel="stylesheet"> ‑‑>
    <title>Tyler Wong Portfolio</title>
  </head>
  <body>

    <input type="checkbox" id="check">
    <label for="check" style="display: inline;">
      <i class="bi bi‑list" id="menu‑open"></i>
      <i class="bi bi‑x" id="menu‑close"></i>
    </label>
    <div class="sidebar">
      <header>Tyler Wong</header>
      <ul>
        <li> <a href="#"> <i class="bi bi‑house‑door"></i> Home </a> </li>
        <li> <a href="#"> <i class="bi bi‑person"></i> About </a> </li>
        <li> <a href="#"> <i class="bi bi‑code‑square"></i> Projects </a> </li>
        <li> <a href="#"> <i class="bi bi‑mailbox"></i> Contact </a> </li>

      </ul>
    </div>

    <script src="https://code.jquery.com/jquery‑3.3.1.slim.min.js" integrity="sha384‑q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384‑UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384‑JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

    <section></section>

  </body>
</html>

方法 2:

I had runned same code on my local the issue seems to be here

label {
     display: inline‑block;
 }

It fixed the error comment this display property and see it will reflect

方法 3:

If you move <section> to the top of the html it should go away do to the flow of html. Your other option is to give it a negative position

background: {
  position: relative;
  top:‑25px;
}

(by Tyler WongBlaztixGopal OswalJustin)

參考文件

  1. White bar at top of html page Bootstrap (CC BY‑SA 2.5/3.0/4.0)

#bootstrap-4 #css #html






相關問題

在不同選項卡上時如何隱藏特定選項卡 (How to hide specific tab when on different tab)

如何將引導程序 4 中的內容連續居中? (How to center in bootstrap 4 the content in a row?)

構建 JavaScript 時缺少模塊 (Missing Module When Building JavaScript)

React-Bootstrap 選項卡 defaultActiveKey 不隨 stateChange 改變 (React-Bootstrap Tabs defaultActiveKey is not changing with stateChange)

表格內容的對齊方式 (alignment of the content in table)

切換器圖標無法調整導航欄寬度 (Toggler icon does not working on adjusting the navbar width)

如何根據設備大小使用屏幕 (How to use the screens based on the device size)

如何在引導程序 4 中為 col 調整大小設置動畫? (How to animate col resize in bootstrap 4?)

html頁面Bootstrap頂部的白條 (White bar at top of html page Bootstrap)

如何從 reactstrap 輸入覆蓋表單控制類? (How can I override form-control class from a reactstrap input?)

文檔似乎沒有變化,但為什麼寬度在 Bootstrap 4 和 5 之間給出不同的圖像比例? (It seems to be no change in docs, but why does width give different image scale between Bootstrap 4 and 5?)

引導表拆分單元格 (Bootstrap table split cells)







留言討論