离屏导航 - 右和左 - 仅css [英] Off-screen navigation - right and left - css only

查看:112
本文介绍了离屏导航 - 右和左 - 仅css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个只有css的右侧和左侧离屏导航抽屉,我遇到了问题,让每一侧正常工作。

I'm trying to create a right and left off-screen navigation drawer with only css and I'm having problems getting each side to work properly.

我使用复选框作为我的按钮,例如:

I'm using checkboxes as my buttons like this:

<input type="checkbox" id="toggle-right">
<input type="checkbox" id="toggle-left">

如果我有在顶部的toggle-right位置,右侧的抽屉打开,但不是左侧。

If I have the toggle-right place on top then the right drawer opens, but not the left.

如果我像这样反转订单:

If I reverse the order like this:

<input type="checkbox" id="toggle-left">
<input type="checkbox" id="toggle-right">

向左切换可以使用,但不能切换。

Toggle left will work, but not toggle right.

我通过 JSFiddle 向您显示了我的意思。

I made a JSFiddle to show you what I mean.

如果有人有时间来看看,并帮助我想出这一点,我会很感激。

If someone has time to take a look and help me figure this out I would appreciate it.

查看 JSFiddle ,反向复选框的顺序切换,看看我在说什么。

While reviewing the JSFiddle, reverse the order of the checkbox toggles to see what I'm talking about.

推荐答案

问题在于使用 + - 邻近兄弟选择器。因为它只适用于您的复选框的下一个元素,它只适用于其中一个。解决方案是使用 - 一般兄弟选择器。

The problem lies with the usage of + - adjacent sibling selector. As it works only for next element to your checkbox, it will only works for one of them. The solution is to use ~ - general sibling selector.

header {
  width: 100%;
  height: 90px; 
  background-color:#f1f1f1;}

.menu-toggle {
  text-decoration: none;
  text-align: center;
  width: 44px;
  height: 44px;
  font-size: 30px;
  color: rgba(0, 0, 0, 0.5);
  -webkit-transition: all 0.15s ease-out 0s;
  -moz-transition: all 0.15s ease-out 0s;
  transition: all 0.15s ease-out 0s;
  position: absolute;
  top: 0px;
  right: auto;
  bottom: 0;
  left: 20px;
  z-index: 2; }

.menu-toggle:hover {
  color: #000000; }

#toggle-left {
  display: none; }
#toggle-left:checked ~ .page-wrap nav.menu {
  left: 0px; }
#toggle-left:checked ~ .page-wrap .menu-toggle {
  left: 220px; }

.profile-toggle {
  text-decoration: none;
  text-align: center;
  width: 44px;
  height: 44px;
  font-size: 30px;
  color: rgba(0, 0, 0, 0.5);
  -webkit-transition: all 0.15s ease-out 0s;
  -moz-transition: all 0.15s ease-out 0s;
  transition: all 0.15s ease-out 0s;
  position: absolute;
  top: 0px;
  right: 40px;
  bottom: 0;
  left: auto;
  z-index: 2; }

.profile-toggle:hover {
  color: #000000; }

#toggle-right {
  display: none; }
#toggle-right:checked + .page-wrap nav.profile {
  right: 0px; }
#toggle-right:checked + .page-wrap .profile-toggle {
  right: 220px; }

nav.menu {
  position: fixed;
  top: 0px;
  right: auto;
  bottom: 0px;
  left: -270px;
  -webkit-transition: all 0.15s ease-out 0s;
  -moz-transition: all 0.15s ease-out 0s;
  transition: all 0.15s ease-out 0s;
  height: auto;
  width: 200px;
  background: #111111;
  z-index: 2000; }


nav.profile {
  position: fixed;
  top: 0px;
  right: -270px;
  bottom: 0px;
  left: auto;
  -webkit-transition: all 0.15s ease-out 0s;
  -moz-transition: all 0.15s ease-out 0s;
  transition: all 0.15s ease-out 0s;
  height: auto;
  width: 200px;
  background: #990000;
  z-index: 2000; }

<input type="checkbox" id="toggle-left">
<input type="checkbox" id="toggle-right">

<div class="page-wrap">
  <header>
    <div class="top-bar">
      <label for="toggle-left" class="menu-toggle">☰</label>
      <label for="toggle-right" class="profile-toggle"><b>+</b></label>
    </div>
    <div class="middle-line"></div>
    <div class="bottom-bar"></div>
  </header>

  <nav class="menu">
  </nav>

  <nav class="profile">

  </nav>

这篇关于离屏导航 - 右和左 - 仅css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆