Скрыть DIV на мобильных устройствах - PullRequest
0 голосов
/ 28 февраля 2019

Ниже приведен мой код, и я хотел бы знать, как скрыть панель значков 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, но он все еще отображается на меньших экранах.Буду признателен за любую помощь или совет.

1 Ответ

0 голосов
/ 28 февраля 2019

Ваш 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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...