在移动设备上隐藏 DIV

京东

下面是我的代码,我想知道如何在移动设备上隐藏图标栏 DIV。我试图添加下面的@media,但它仍然显示在较小的屏幕上。任何帮助或建议将不胜感激。

@media only screen and (max-width: 980px) {
#icon-bar {
top: 100px !important;
}
}

@media only screen and (max-width: 980px) { /*adjust the max width value to hide the button on the screen sizes of your choice*/
#icon-bar {
display: none;
}
}

body {margin:0;height:2000px;}

.icon-bar {
  position: fixed;
  top: 50%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
}

.icon-bar a {
  display: block;
  text-align: center;
  padding: 16px;
  transition: all 0.3s ease;
  color: white;
  font-size: 20px;
}

.icon-bar a:hover {
  background-color: #000;
}

.facebook {
  background: #3B5998;
  color: white;
}

.twitter {
  background: #55ACEE;
  color: white;
}

.google {
  background: #dd4b39;
  color: white;
}

.linkedin {
  background: #007bb5;
  color: white;
}

.youtube {
  background: #bb0000;
  color: white;
}

.content {
  margin-left: 75px;
  font-size: 30px;
}
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<body>

<div class="icon-bar">
  <a href="#" class="facebook"><i class="fa fa-facebook"></i></a> 
  <a href="#" class="twitter"><i class="fa fa-twitter"></i></a> 
  <a href="#" class="google"><i class="fa fa-google"></i></a> 
  <a href="#" class="linkedin"><i class="fa fa-linkedin"></i></a>
  <a href="#" class="youtube"><i class="fa fa-youtube"></i></a> 
</div>

<div class="content">
  <h3>Howdy</h3>
  <p>Your content goes here.....</p>
   <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  <p>Your content goes here.....</p>  

</body>
</html> 

下面是我的代码,我想知道如何在移动设备上隐藏图标栏 DIV。我试图添加下面的@media,但它仍然显示在较小的屏幕上。任何帮助或建议将不胜感激。

尼克帕森斯

icon-bar的不是id. 它是一个class. 因此你需要在你的 css 中使用.icon-bar而不是#icon-bar

此外,您的第一个媒体查询是多余的,因为它改变了图标栏的高度,但在您的第二个媒体查询中,您将其隐藏,因此永远不会看到高度变化,因此您可以删除第一个媒体查询。

请参阅下面的工作示例:

body {
  margin: 0;
  height: 2000px;
}

@media only screen and (max-width: 980px) {
  .icon-bar {
    display: none;
  }
}

.icon-bar {
  position: fixed;
  top: 50%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
}

.icon-bar a {
  display: block;
  text-align: center;
  padding: 16px;
  transition: all 0.3s ease;
  color: white;
  font-size: 20px;
}

.icon-bar a:hover {
  background-color: #000;
}

.facebook {
  background: #3B5998;
  color: white;
}

.twitter {
  background: #55ACEE;
  color: white;
}

.google {
  background: #dd4b39;
  color: white;
}

.linkedin {
  background: #007bb5;
  color: white;
}

.youtube {
  background: #bb0000;
  color: white;
}

.content {
  margin-left: 75px;
  font-size: 30px;
}
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<body>
  <div class="icon-bar">
    <a href="#" class="facebook"><i class="fa fa-facebook"></i></a>
    <a href="#" class="twitter"><i class="fa fa-twitter"></i></a>
    <a href="#" class="google"><i class="fa fa-google"></i></a>
    <a href="#" class="linkedin"><i class="fa fa-linkedin"></i></a>
    <a href="#" class="youtube"><i class="fa fa-youtube"></i></a>
  </div>

  <div class="content">
    <h3>Howdy</h3>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
    <p>Your content goes here.....</p>
  </div>
</body>
</html>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在移动设备上使用 jquery 隐藏 div

来自分类Dev

在移动设备上隐藏div无法正常工作

来自分类Dev

在低于特定屏幕分辨率的移动设备上隐藏 div

来自分类Dev

在移动设备上查看时,div边框

来自分类Dev

根据Bootstrap中的设备隐藏和移动div

来自分类Dev

隐藏 <div> 块在移动设备上不起作用

来自分类Dev

在IOS设备上使用“ visibility:hidden”隐藏div

来自分类Dev

在移动设备上滚动内容溢出的固定div

来自分类Dev

如何在移动设备上滚动叠加层div

来自分类Dev

仅在使用jQuery的移动设备上显示div

来自分类Dev

在移动设备上如何更改两个div的顺序?

来自分类Dev

打字机使div在较小的设备上移动

来自分类Dev

在移动设备上滚动显示内容溢出的固定div

来自分类Dev

在移动设备上查看时,stick div正在跳跃

来自分类Dev

我希望左浮动div调整移动设备上的宽度

来自分类Dev

在移动设备上div如何保持相同的大小

来自分类Dev

将中心 div 推送到移动设备上的内容顶部

来自分类Dev

Bootstrap 4:修复移动设备上 Div 之外的图像

来自分类Dev

Jquery在移动设备的某些点滚动时显示和隐藏div

来自分类Dev

移动设备和桌面设备上同一个div的样式不同

来自分类Dev

仅在移动设备与桌面设备上的小空间(使用 pos absolute / css 堆叠 div)

来自分类Dev

移动隐藏子div的内容

来自分类Dev

移动设备上的3个div重新排列div堆栈

来自分类Dev

将bootstrap 3中的小型设备的上div和下div移动到ip

来自分类Dev

移动设备上的3个div重新排列div堆栈

来自分类Dev

溢出:移动设备上的隐藏难题

来自分类Dev

在移动设备上隐藏侧面滚动菜单

来自分类Dev

CSS / 在移动设备上隐藏按钮

来自分类Dev

如何在移动设备上垂直堆叠div,但在网络版本上保持水平?

Related 相关文章

  1. 1

    在移动设备上使用 jquery 隐藏 div

  2. 2

    在移动设备上隐藏div无法正常工作

  3. 3

    在低于特定屏幕分辨率的移动设备上隐藏 div

  4. 4

    在移动设备上查看时,div边框

  5. 5

    根据Bootstrap中的设备隐藏和移动div

  6. 6

    隐藏 <div> 块在移动设备上不起作用

  7. 7

    在IOS设备上使用“ visibility:hidden”隐藏div

  8. 8

    在移动设备上滚动内容溢出的固定div

  9. 9

    如何在移动设备上滚动叠加层div

  10. 10

    仅在使用jQuery的移动设备上显示div

  11. 11

    在移动设备上如何更改两个div的顺序?

  12. 12

    打字机使div在较小的设备上移动

  13. 13

    在移动设备上滚动显示内容溢出的固定div

  14. 14

    在移动设备上查看时,stick div正在跳跃

  15. 15

    我希望左浮动div调整移动设备上的宽度

  16. 16

    在移动设备上div如何保持相同的大小

  17. 17

    将中心 div 推送到移动设备上的内容顶部

  18. 18

    Bootstrap 4:修复移动设备上 Div 之外的图像

  19. 19

    Jquery在移动设备的某些点滚动时显示和隐藏div

  20. 20

    移动设备和桌面设备上同一个div的样式不同

  21. 21

    仅在移动设备与桌面设备上的小空间(使用 pos absolute / css 堆叠 div)

  22. 22

    移动隐藏子div的内容

  23. 23

    移动设备上的3个div重新排列div堆栈

  24. 24

    将bootstrap 3中的小型设备的上div和下div移动到ip

  25. 25

    移动设备上的3个div重新排列div堆栈

  26. 26

    溢出:移动设备上的隐藏难题

  27. 27

    在移动设备上隐藏侧面滚动菜单

  28. 28

    CSS / 在移动设备上隐藏按钮

  29. 29

    如何在移动设备上垂直堆叠div,但在网络版本上保持水平?

热门标签

归档