如何防止下拉选项从CSS的其他下拉菜单中隐藏?

如何解决如何防止下拉选项从CSS的其他下拉菜单中隐藏?

以下是下拉菜单的两个图像。我在同一页面的每个页面内部都有多个下拉菜单。单击下拉菜单时,其所有选项都会被触发,但最后一个选项会在另一个选择下拉菜单选项下受到阻碍。 (参考:图像2)如何防止这种情况发生? 相应的下拉菜单的3个选项是:配置文件,Word,标签。 Hashtag选项受阻。在此处检查完整代码:Codepen

图片1

enter image description here

图片2

enter image description here

我正在尝试以下代码:

    $(".custom-select").each(function() {
      var classes = $(this).attr("class"),id      = $(this).attr("id"),name    = $(this).attr("name");
      var template =  '<div class="' + classes + '">';
          template += '<span class="custom-select-trigger">' + $(this).attr("placeholder") + '</span>';
          template += '<div class="custom-options">';
          $(this).find("option").each(function() {
            template += '<span class="custom-option ' + $(this).attr("class") + '" data-value="' + $(this).attr("value") + '">' + $(this).html() + '</span>';
          });
      template += '</div></div>';
      
      $(this).wrap('<div class="custom-select-wrapper"></div>');
      $(this).hide();
      $(this).after(template);
    });
    $(".custom-option:first-of-type").hover(function() {
      $(this).parents(".custom-options").addClass("option-hover");
    },function() {
      $(this).parents(".custom-options").removeClass("option-hover");
    });
    $(".custom-select-trigger").on("click",function() {
      $('html').one('click',function() {
        $(".custom-select").removeClass("opened");
      });
      $(this).parents(".custom-select").toggleClass("opened");
      event.stopPropagation();
    });
    $(".custom-option").on("click",function() {
      $(this).parents(".custom-select-wrapper").find("select").val($(this).data("value"));
      $(this).parents(".custom-options").find(".custom-option").removeClass("selection");
      $(this).addClass("selection");
      $(this).parents(".custom-select").removeClass("opened");
      $(this).parents(".custom-select").find(".custom-select-trigger").text($(this).text());
    });
    body {
      background: #ededed;
      font-family: 'Open Sans',sans-serif;
    }
    .center {
      position: absolute;
      display: inline-block;
      top: 50%; left: 50%;
      transform: translate(-50%,-50%);
    }
    
    /** Custom Select **/
    .custom-select-wrapper {
      position: relative;
      display: inline-block;
      user-select: none;
    }
      .custom-select-wrapper select {
        display: none;
      }
      .custom-select {
        position: relative;
        display: inline-block;
      }
        .custom-select-trigger {
          position: relative;
          display: block;
          width: 230px;
          padding: 0 84px 0 22px;
          font-size: 20px;
          font-weight: 300;
          color: #fff;
          line-height: 40px;
          background: #265a88;
          border-radius: 4px;
          cursor: pointer;
        }
          .custom-select-trigger:after {
            position: absolute;
            display: block;
            content: '';
            width: 10px; height: 10px;
            top: 50%; right: 25px;
            margin-top: -3px;
            border-bottom: 1px solid #fff;
            border-right: 1px solid #fff;
            transform: rotate(45deg) translateY(-50%);
            transition: all .4s ease-in-out;
            transform-origin: 50% 0;
          }
          .custom-select.opened .custom-select-trigger:after {
            margin-top: 3px;
            transform: rotate(-135deg) translateY(-50%);
          }
      .custom-options {
        position: absolute;
        display: block;
        top: 100%; left: 0; right: 0;
        min-width: 100%;
        margin: 15px 0;
        border: 1px solid #b5b5b5;
        border-radius: 4px;
        box-sizing: border-box;
        box-shadow: 0 2px 1px rgba(0,.07);
        background: #fff;
        transition: all .4s ease-in-out;
        
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transform: translateY(-15px);
      }
      .custom-select.opened .custom-options {
        opacity: 1;
        visibility: visible;
        pointer-events: all;
        transform: translateY(0);
      }
        .custom-options:before {
          position: absolute;
          display: block;
          content: '';
          bottom: 100%; right: 25px;
          width: 7px; height: 7px;
          margin-bottom: -4px;
          border-top: 1px solid #b5b5b5;
          border-left: 1px solid #b5b5b5;
          background: #fff;
          transform: rotate(45deg);
          transition: all .4s ease-in-out;
        }
        .option-hover:before {
          background: #f9f9f9;
        }
        .custom-option {
          position: relative;
          display: block;
          padding: 0 22px;
          border-bottom: 1px solid #b5b5b5;
          font-size: 18px;
          font-weight: 600;
          color: #b5b5b5;
          line-height: 47px;
          cursor: pointer;
          transition: all .4s ease-in-out;
        }
        .custom-option:first-of-type {
          border-radius: 4px 4px 0 0;
        }
        .custom-option:last-of-type {
          border-bottom: 0;
          border-radius: 0 0 4px 4px;
        }
        .custom-option:hover,.custom-option.selection {
          background: #f9f9f9;
        }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="sources" id="sources" class="custom-select sources" placeholder="Requirement Completed">
        <option value="profile">Profile</option>
        <option value="word">Word</option>
        <option value="hashtag">Hashtag</option>
      </select>

解决方法

您可以通过两种方式解决它:

第一个是在CSS中设置z-index,例如:.custom-options{z-index: 1;}
第二个是设置位置,例如:.custom-options{position: relative;}

第一个解决方案将使窗帘出现在另一个元素上方,第二个解决方案将默认情况下保留该空间以使其正确显示(即使关闭了窗帘)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-