【问题标题】:Adding a Down Arrow to Select Drop Down添加向下箭头以选择下拉菜单
【发布时间】:2014-05-24 17:56:22
【问题描述】:

您好,我正在创建一个 MVC Razor 站点,我目前有一个样式下拉框,Here is the jsfiddle。我不知道如何添加向下箭头。有任何想法吗?我试过this 但它对我不起作用。这是我当前的代码

HTML

<div class="dropdown">
    <select>
        <option>Option One </option>
        <option>Option Two </option>
        <option>Option Three </option>
    </select>
</div>

CSS

.dropdown select{
  background:transparent;
   width: 297px;
   padding: 2px;
   font-family:Arial, Helvetica, sans-serif;
   font-size:1.2em;
   font-weight:600;
   color:#fff;
   line-height: 1;
   border: 0;
   border-radius: 0;
   /*Hides the default arrows for Selects*/
  -webkit-appearance: none;
  -moz-appearance: none;
    text-indent: 0.01px;
    text-overflow: '';

  }


.dropdown{
    width: 297px;
    overflow: hidden;
    background: no-repeat right #363636;
    border-top:#575757 1px solid;
    -webkit-border-radius: 4px 4px 4px 4px;
     -moz-border-radius: 4px 4px 4px 4px;
          border-radius: 4px 4px 4px 4px;
    -webkit-box-shadow: inset 0 2px 4px rgba(107, 105, 105, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
     -moz-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
          box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
          -moz-box-shadow:    0px 8px 3px -9px #000000;
          -webkit-box-shadow: 0px 8px 3px -9px #000000;
          box-shadow:         0px 8px 3px -9px #000000;  

}

select > option {
  background: #D3D3D3;
  color: black;

【问题讨论】:

    标签: html css razor


    【解决方案1】:

    您可以通过 css 和伪元素创建这个三角形

    .dropdown {
        position: relative;
    }
    
    .dropdown:before {
        content: "";
        position: absolute;
        right: 10px;
        top: 8px;
        width: 0; 
        height: 0; 
        border-left: 10px solid transparent;
        border-right: 10px solid transparent;
        border-top: 10px solid #f00;
    }
    
    .dropdown:after {
        content: "";
        position: absolute;
        right: 10px;
        top: 3px;
        width: 0; 
        height: 0; 
        border-left: 10px solid transparent;
        border-right: 10px solid transparent;
        border-top: 10px solid #333;
    }
    

    这是一个演示:http://jsfiddle.net/S3h27/363/

    【讨论】:

    • 谢谢你,这就是我要找的!
    • @Confused Comment from user6950100“你需要点击箭头的外侧才能放下它”,(在answer中传递了错误)跨度>
    • @Confused Example 错过了position: relative; 属性。堆栈顺序很简单。
    • 您可以使用pointer-events: none;,这样当您点击箭头时下拉菜单会显示下拉菜单。
    猜你喜欢
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    • 2023-03-23
    相关资源
    最近更新 更多