首页 > 解决方案 > 我正在尝试制作一个下拉侧边栏菜单

问题描述

我正在尝试制作一个下拉侧边栏菜单。

请看附上的图片

https://i.stack.imgur.com/nsvzQ.png

我需要该部分在桌面视图中打开并在移动视图中关闭。

实现这一目标的最佳方法是什么?

我正在尝试使用以下链接中的代码。

https://codepen.io/gregsaxton/pen/eoWGxL

<ul class="m-d expand-list">
<li data-md-content="200">
    <label name="tab" for="tab1" tabindex="-1" class="tab_lab" role="tab">Product Description</label>
    <input type="checkbox" checked class="tab" id="tab1" tabindex="0" />
    <span class="open-close-icon">
        <i class="fas fa-plus"></i>
        <i class="fas fa-minus"></i>
    </span>
    <div class="content">
        Welcome to Brackets, a modern open-source code editor that understands web design. It's a lightweight,
        yet powerful, code editor that blends visual tools into the editor so you get the right amount of help
        when you want it.
    </div>
</li>
<li data-md-content="300">
        <label name="tab" for="tab2" tabindex="-1" class="tab_lab" role="tab">Specifications</label>
        <input type="checkbox" class="tab" id="tab2" tabindex="0" />
        <span class="open-close-icon"><i class="fas fa-plus"></i><i class="fas fa-minus"></i></span>
        <div class="content">
            <em>Brackets is a different type of editor.</em>
        Brackets has some unique features like Quick Edit, Live Preview and others that you may not find in other
        editors. Brackets is written in JavaScript, HTML and CSS. That means that most of you using Brackets
        have the skills necessary to modify and extend the editor. In fact, we use Brackets every day to build
        Brackets. To learn more about how to use the key features, read on.
    </div>
</li>
<li data-md-content="600">
        <label name="tab" for="tab3" tabindex="-1" class="tab_lab" role="tab">Shipping &amp; Returns</label>
        <input type="checkbox" class="tab" id="tab3" tabindex="0" />
        <span class="open-close-icon"><i class="fas fa-plus"></i><i class="fas fa-minus"></i></span>
  <div class="content">
            <h3>Projects in Brackets</h3>
    <p>
        In order to edit your own code using Brackets, you can just open the folder containing your files.
        Brackets treats the currently open folder as a "project"; features like Code Hints, Live Preview and
        Quick Edit only use files within the currently open folder.
    </p>
    <samp>
        Once you're ready to get out of this sample project and edit your own code, you can use the dropdown
        in the left sidebar to switch folders. Right now, the dropdown says "Getting Started" - that's the
        folder containing the file you're looking at right now. Click on the dropdown and choose "Open Folder…&quot;
        to open your own folder.
        You can also use the dropdown later to switch back to folders you've opened previously, including this
        sample project.
    </samp>
        </div>
</li>

标签: javascripthtmlcss

解决方案


通过使用两种方法,您可以做到这一点

  1. 使用 javascript 检测设备(台式机/移动设备),然后在 if 条件下,您可以关闭或打开 onload 部分。

  2. 使用 css 媒体查询来检测屏幕大小并打开或关闭部分 onload。

示例:对于选项 2

/* 
  ##Device = Desktops
  ##Screen = 1281px to higher resolution desktops
*/

@media (min-width: 1281px) {
  
  /* CSS */
  
}

/* 
  ##Device = Laptops, Desktops
  ##Screen = B/w 1025px to 1280px
*/

@media (min-width: 1025px) and (max-width: 1280px) {
  
  /* CSS */
  
}

/* 
  ##Device = Tablets, Ipads (portrait)
  ##Screen = B/w 768px to 1024px
*/

@media (min-width: 768px) and (max-width: 1024px) {
  
  /* CSS */
  
}

/* 
  ##Device = Tablets, Ipads (landscape)
  ##Screen = B/w 768px to 1024px
*/

@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
  
  /* CSS */
  
}

/* 
  ##Device = Low Resolution Tablets, Mobiles (Landscape)
  ##Screen = B/w 481px to 767px
*/

@media (min-width: 481px) and (max-width: 767px) {
  
  /* CSS */
  
}

/* 
  ##Device = Most of the Smartphones Mobiles (Portrait)
  ##Screen = B/w 320px to 479px
*/

@media (min-width: 320px) and (max-width: 480px) {
  
  /* CSS */
  
}

推荐阅读