使导航菜单响应

时间:2015-09-06 15:16:18

标签: jquery html css

从不同屏幕尺寸查看我的网站时,菜单会离开屏幕。如何使其响应?这里是site的链接我添加了html和css供您参考。感谢。

HTML

<div class="wrapper">
  <p class="menu">
    <a href="#" class="animBtn themeB hastip" title="<h2>Who We Are</h2>">Who We Are</a>

    <a href="#" class="animBtn themeB hastip" title="<h2>What We Do</h2>"Loree Do</a>

    <a href="/forum" class="animBtn themeB hastip" title="<h2>Step Into Our Community</h2>">Forum</a>

    <a href="#" class="animBtn themeB">Contact US</a>
  </p>
</div>

CSS

.menu {
  position: absolute;
  top: 50%;
  height: 300px;
  margin-left: 950px;
  margin-top: 10px;
}

a.animBtn:link, a.animBtn:visited {
  position: relative;
  display: block;
  width: 220px;
  margin: 10px auto 0;
  border-radius: 10px;
  font-size: 21px !important;
  padding: 14px 15px;
  border: 2px solid #608B82;
  background: rgba(255, 255, 255, 0.15);
  color: rgba(159,192,181,1);
  text-align: center;
  text-decoration: none;
  text-transform: note;
  overflow: hidden;
  letter-spacing: .08em;
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.2), 0 1px 0 rgba(0, 0, 0, 0.2);
  -webkit-transition: all .3s ease;
  -moz-transition: all .3s ease;
  -o-transition: all .3s ease;
  transition: all .3s ease;
}
a.animBtn:link:after, a.animBtn:visited:after {
  content: "";
  position: absolute;
  background: none repeat scroll 0 0 rgba(255, 255, 255, 0.1);
  height: 0%;
  left: 50%;
  top: 50%;
  width: 100%;
  z-index: -1;
  -webkit-transition: all .3s ease 0s;
  -moz-transition: all .3s ease 0s;
  -o-transition: all .3s ease 0s;
  transition: all .3s ease 0s;
}
a.animBtn:link:hover, a.animBtn:visited:hover {
  color: rgba(159,192,181,1);
  text-shadow: none;
}
a.animBtn:link:hover:after, a.animBtn:visited:hover:after {
  height: 420%;
}

a.animBtn.themeB:after {
  -moz-transform: translateX(-50%) translateY(-50%) rotate(45deg);
  -ms-transform: translateX(-50%) translateY(-50%) rotate(45deg);
  -webkit-transform: translateX(-50%) translateY(-50%) rotate(45deg);
  transform: translateX(-50%) translateY(-50%) rotate(45deg);
}

2 个答案:

答案 0 :(得分:0)

这个问题有多个解决方案。在您的情况下,您可能想尝试使用CSS3 media rules

如果我们查看菜单的CSS:

.menu {
  position: absolute;
  top: 50%;
  height: 300px;
  margin-left: 950px;
  margin-top: 10px;
}

左边距离将菜单推出较小的屏幕。因此对于较小的屏幕,您需要较小的边距。您可以通过将以下规则附加到CSS代码来设置:

@media all and (max-width: 600px) {
    .menu {
        margin-left: 250px;
    }
}

如果浏览器检测到小于600px的屏幕尺寸,则会覆盖菜单样式。

我看到W3schools还提供了一些其他解决方案over here

答案 1 :(得分:0)

好。开始了。以下代码仅适用于移动设备和屏幕大于移动设备。但对于适用于每个标准设备的流体布局,您可能需要为所有标准设备应用媒体屏幕。

这是HTML

<p class="menu">
<a href="#" class="animBtn themeB hastip" title="">Who We Are</a>

<a href="#" class="animBtn themeB hastip" title="">What We Do</a>

<a href="/forum" class="animBtn themeB hastip" title="">Forum</a>

<a href="#" class="animBtn themeB">Contact US</a>
</p>

CSS

@media screen and (max-width:320px){ /*For Mobile*/
.menu {
position: absolute;
top: 50%;
height: 300px;
margin:auto;
margin-top: 10px;
}

@media screen and (min-width:321px){ /* for screen larger than mobile*/
.menu {
 position: absolute;
top: 50%;
height: 300px;
margin-left: 70%;
margin-top: 10px;
}
}

根据需要自定义每个屏幕的位置。这是 DEMO 如有任何问题请回来。希望这能帮助你。