首页 > 解决方案 > 删除隐藏溢出的滚动条

问题描述

我试图隐藏溢出元素上的滚动条。
我尝试使用overflow: hidden;但它不起作用。

这是我的最小示例:

#navbar {
  width: 10000px;
  border: solid red 1px;
  overflow-x: hidden;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <div id="container">
    <div id="navbar">hello</div>
  </div>
</body>

</html>

标签: htmlcss

解决方案


是的,你可以拥有超过 100%,你可以将你的容器设置为 100%,并拥有你所需要的内部元素。

#container {
  width: 100%;
  overflow: hidden;
}

#navbar {
  /* your requirement */
  max-width: 10000px;
  border: solid red 1px;
  white-space: nowrap;
  width: auto;
}
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <div id="container">
    <div id="navbar">Flex items have a default order value of 0, therefore items with an integer value greater than 0 will be displayed after any items that have not been given an explicit order value. You can also use negative values with order, which can be quite useful.
      If you want to make one item display first, and leave the order of all other items unchanged, you can give that item an order of -1. As this is lower than 0 the item will always be displayed first. In the live code example below I have items laid
      out using Flexbox. By changing which item has the class active assigned to it in the HTML, you can change which item displays first and therefore becomes full width at the top of the layout, with the other items displaying below it. Flex items have
      a default order value of 0, therefore items with an integer value greater than 0 will be displayed after any items that have not been given an explicit order value. You can also use negative values with order, which can be quite useful. If you want
      to make one item display first, and leave the order of all other items unchanged, you can give that item an order of -1. As this is lower than 0 the item will always be displayed first. In the live code example below I have items laid out using
      Flexbox. By changing which item has the class active assigned to it in the HTML, you can change which item displays first and therefore becomes full width at the top of the layout, with the other items displaying below it. Flex items have a default
      order value of 0, therefore items with an integer value greater than 0 will be displayed after any items that have not been given an explicit order value. You can also use negative values with order, which can be quite useful. If you want to make
      one item display first, and leave the order of all other items unchanged, you can give that item an order of -1. As this is lower than 0 the item will always be displayed first. In the live code example below I have items laid out using Flexbox.
      By changing which item has the class active assigned to it in the HTML, you can change which item displays first and therefore becomes full width at the top of the layout, with the other items displaying below it. Flex items have a default order
      value of 0, therefore items with an integer value greater than 0 will be displayed after any items that have not been given an explicit order value. You can also use negative values with order, which can be quite useful. If you want to make one
      item display first, and leave the order of all other items unchanged, you can give that item an order of -1. As this is lower than 0 the item will always be displayed first. In the live code example below I have items laid out using Flexbox. By
      changing which item has the class active assigned to it in the HTML, you can change which item displays first and therefore becomes full width at the top of the layout, with the other items displaying below it. Flex items have a default order value
      of 0, therefore items with an integer value greater than 0 will be displayed after any items that have not been given an explicit order value. You can also use negative values with order, which can be quite useful. If you want to make one item display
      first, and leave the order of all other items unchanged, you can give that item an order of -1. As this is lower than 0 the item will always be displayed first. In the live code example below I have items laid out using Flexbox. By changing which
      item has the class active assigned to it in the HTML, you can change which item displays first and therefore becomes full width at the top of the layout, with the other items displaying below it. Flex items have a default order value of 0, therefore
      items with an integer value greater than 0 will be displayed after any items that have not been given an explicit order value. You can also use negative values with order, which can be quite useful. If you want to make one item display first, and
      leave the order of all other items unchanged, you can give that item an order of -1. As this is lower than 0 the item will always be displayed first. In the live code example below I have items laid out using Flexbox. By changing which item has
      the class active assigned to it in the HTML, you can change which item displays first and therefore becomes full width at the top of the layout, with the other items displaying below it. Flex items have a default order value of 0, therefore items
      with an integer value greater than 0 will be displayed after any items that have not been given an explicit order value. You can also use negative values with order, which can be quite useful. If you want to make one item display first, and leave
      the order of all other items unchanged, you can give that item an order of -1. As this is lower than 0 the item will always be displayed first. In the live code example below I have items laid out using Flexbox. By changing which item has the class
      active assigned to it in the HTML, you can change which item displays first and therefore becomes full width at the top of the layout, with the other items displaying below it. Flex items have a default order value of 0, therefore items with an
      integer value greater than 0 will be displayed after any items that have not been given an explicit order value. You can also use negative values with order, which can be quite useful. If you want to make one item display first, and leave the order
      of all other items unchanged, you can give that item an order of -1. As this is lower than 0 the item will always be displayed first. In the live code example below I have items laid out using Flexbox. By changing which item has the class active
      assigned to it in the HTML, you can change which item displays first and therefore becomes full width at the top of the layout, with the other items displaying below it. Flex items have a default order value of 0, therefore items with an integer
      value greater than 0 will be displayed after any items that have not been given an explicit order value. You can also use negative values with order, which can be quite useful. If you want to make one item display first, and leave the order of all
      other items unchanged, you can give that item an order of -1. As this is lower than 0 the item will always be displayed first. In the live code example below I have items laid out using Flexbox. By changing which item has the class active assigned
      to it in the HTML, you can change which item displays first and therefore becomes full width at the top of the layout, with the other items displaying below it.</div>
  </div>
</body>

</html>


推荐阅读