如何在选择框下拉列表中更改蓝色突出显示的颜色

时间:2013-10-15 18:03:54

标签: css

如何更改此下拉列表中的蓝色突出显示?

link to select box demo

如果可能的话,我想将高亮颜色更改为灰色。

select {
  border: 0;
  color: #EEE;
  background: transparent;
  font-size: 20px;
  font-weight: bold;
  padding: 2px 10px;
  width: 378px;
  *width: 350px;
  *background: #58B14C;
  -webkit-appearance: none;
}

#mainselection {
  overflow: hidden;
  width: 350px;
  -moz-border-radius: 9px 9px 9px 9px;
  -webkit-border-radius: 9px 9px 9px 9px;
  border-radius: 9px 9px 9px 9px;
  box-shadow: 1px 1px 11px #330033;
  background: url("http://www.danielneumann.com/wp-content/uploads/2011/01/arrow.gif") no-repeat scroll 319px 5px #58B14C;
}
<div id="mainselection">
  <select>
    <option>Select an Option</option>
    <option>Option 1</option>
    <option>Option 2</option>
  </select>
</div>

10 个答案:

答案 0 :(得分:15)

是的,您可以更改select的背景,但是使用CSS无法更改突出显示颜色(当您悬停时)!

  

你几乎没有选择:

  1. 是将select转换为ul, li类型的选择,并使用此功能执行任何操作。

  2. 使用ChoosenSelect2jQuery Form Styler等库。这些允许您以更广泛和跨浏览器的方式进行样式化。

答案 1 :(得分:15)

我相信你正在寻找outline CSS属性(与active和hover psuedo属性一起):

/* turn it off completely */
select:active, select:hover {
  outline: none
}

/* make it red instead (with with same width and style) */
select:active, select:hover {
  outline-color: red
}

轮廓,轮廓颜色,轮廓样式和轮廓宽度的完整详细信息 https://developer.mozilla.org/en-US/docs/Web/CSS/outline

答案 2 :(得分:9)

在寻找解决方案的同时找到了这个。我只测试过FF 32.0.3

box-shadow: 0 0 10px 100px #fff inset;

答案 3 :(得分:3)

要同时设置悬停颜色的样式并避免Firefox中的操作系统默认颜色,您需要在选择选项选择选项中添加一个框阴影:悬停声明,设置颜色菜单背景颜色的“选择选项”上的框阴影。

select option {
  background: #f00; 
  color: #fff; 
  box-shadow: inset 20px 20px #f00
} 

select option:hover {
  color: #000; 
  box-shadow: inset 20px 20px #00f;
}

答案 4 :(得分:3)

尝试这个..我知道这是一个老帖子,但它可能会帮助某人

select option:hover,
    select option:focus,
    select option:active {
        background: linear-gradient(#000000, #000000);
        background-color: #000000 !important; /* for IE */
        color: #ffed00 !important;
    }

    select option:checked {
        background: linear-gradient(#d6d6d6, #d6d6d6);
        background-color: #d6d6d6 !important; /* for IE */
        color: #000000 !important;
    }

答案 5 :(得分:2)

这适用于firefox和chrome,优雅地回退到IE中的系统颜色。只需确保将title属性设置为选项的内容。它允许您设置背景和前景色。

select option:checked:after {
    content: attr(title);
    background: #666;
    color: #fff;
    position: absolute;
    width: 100%;
    left: 0;
    border: none;
}

答案 6 :(得分:0)

当我们单击“输入”元素时,它将变为“焦点”。删除此“焦点”操作的蓝色荧光笔很简单,如下所示。要使其具有灰色,可以定义灰色边框。

select:focus{
    border-color: gray;
    outline:none;
}

答案 7 :(得分:0)

image of focus class in button having box-shadow

尝试删除按钮中 :focus 类的框阴影,所附图像显示了引导程序中的情况。

/// Define migration block.
private let migrationBlock: MigrationBlock = { migration, oldSchemaVersion in
    switch oldSchemaVersion {
    case 0:
        Migrations.migrateFrom0To1(migration)
    case 1:
        Migrations.migrateFrom1To2(migration)
    case 2:
        Migrations.migrateFrom2To3(migration)
    case 3:
        Migrations.migrateFrom3To4(migration)
    case 4:
        Migrations.migrateFrom4To5(migration)
    case 5:
        Migrations.migrateFrom5To6(migration)
    default:
        break
    }
}

/// Initialize realm configuration.
///
/// - Throws: If error during realm configuration.
private func initializeRealm(realmConfiguration: Realm.Configuration?) throws {
    // Init Realm configuration.
    var config: Realm.Configuration
    if realmConfiguration == nil {
        config = Realm.Configuration(schemaVersion: currentSchemaVersion)
        // Get current schema version of the database before migration.
        let oldSchemaVersion = try schemaVersionAtURL(config.fileURL!)
        print("oldSchemaVersion: \(oldSchemaVersion) currentSchemaVersion: \(currentSchemaVersion)")

        // Perform all migrations one by one
        // (old version to new version) and keep last config.
        if oldSchemaVersion < currentSchemaVersion {
            for tmpCurrentSchemaVersion in oldSchemaVersion...currentSchemaVersion {
                config = Realm.Configuration(schemaVersion: tmpCurrentSchemaVersion, migrationBlock: migrationBlock)
                try! Realm.performMigration(for: config)
            }
        }
    } else {
        config = realmConfiguration!
    }

    self.realm = try! Realm(configuration: config)
}

答案 8 :(得分:-1)

在CSS代码中添加此代码,并使用您选择的颜色更改红色背景色:

.dropdown-menu>.active>a {color:black; background-color:red;}
.dropdown-menu>.active>a:focus {color:black; background-color:red;}
.dropdown-menu>.active>a:hover {color:black; background-color:red;}

答案 9 :(得分:-2)

我刚刚发现这个网站为选择框提供了很酷的主题 http://gregfranko.com/jquery.selectBoxIt.js/

如果您对整体外观有疑问,可以试试这个主题 blue - yellow - grey

相关问题