Html使用CSS和Divs自定义选择标记

时间:2016-06-27 04:31:20

标签: html css select drop-down-menu

好的,我正在尝试使用css和divs spans创建自定义html选择框。 我没有看到任何错误,但不知道为什么它不能正常工作

以下是fiddle

<div class="ik_select episodes_list_selectbox ik_select_autowidth" style="position: relative; width: 258px;">
<div class="ik_select_link episodes_list_selectbox-link">
<div class="ik_select_link_text">active opt 4</div></div>
<div class="ik_select_dropdown episodes_list_selectbox-dd" style="position: absolute; z-index: 9998; width: 100%; display: none;">
<div class="ik_select_list" style="position: relative;">
<div class="ik_select_filter_wrap">

3 个答案:

答案 0 :(得分:0)

基本的选择语句如下:

a:link, a:visited{
 text-decoration: none;
 display: inline-block;
 color: black;
 background-color: white;
}

a:hover, a:focus, a:active{
 text-decoration: none;
 display: inline-block;
 color: white;
 background-color: black;
}

答案 1 :(得分:0)

根据选择部分的考虑,您应该使用内置的选择 - 选项对来完美地工作。如果您坚持使用DIV用于此目的,那么您必须在那里使用一些JavaScript才能使其正常工作。

根据我的意见,您应该自定义select-option以便为您工作,

&#13;
&#13;
import pandas as pd
from sklearn.cross_validation import train_test_split
from sklearn import svm
from time import time

dum_data = pd.read_csv("dummy_variable_file.csv")
train_cols = dum_data.columns[5:]
target = dum_data.columns[4]

x = dum_data[train_cols]
y = dum_data[target]
x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=442, train_size=0.70)

clf = svm.SVC(probability = True)
model = clf.fit(x_train,y_train)

output_predict_test     =   model.predict(x_test)
output_proba_test       =   model.predict_proba(x_test)
output_decision_test    =   model.decision_function(x_test)
&#13;
.custom-select {
	position: relative;
	display: block;
}

/* This is the native select, we're making everything but the text invisible so
 * we can see the button styles in the wrapper */
.custom-select select {
	width: 100%;
	margin: 0;
	outline: none;
	padding: .6em .8em .5em .8em;

	/* Prefixed box-sizing rules necessary for older browsers */
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;

	/* Font size must be 16px to prevent iOS page zoom on focus */
	font-size: 16px;
}


/* Custom arrow sits on top of the select - could be an image, SVG, icon font,
 * etc. or the arrow could just baked into the bg image on the select. */
.custom-select::after {
	content: " ";
	position: absolute;
	top: 50%;
	right: 1em;
	z-index: 2;
	/* These hacks make the select behind the arrow clickable in some browsers */
	pointer-events: none;
	display: none;
}
@supports ( -webkit-appearance: none ) or ( appearance: none )
	/* Firefox <= 34 has a false positive on @supports( -moz-appearance: none )
	 * @supports ( mask-type: alpha ) is Firefox 35+
	 */
	or ( ( -moz-appearance: none ) and ( mask-type: alpha ) ) {
	
	/* Show custom arrow */
	.custom-select::after {
		display: block;
	}

	/* Remove select styling */
	.custom-select select {
		padding-right: 2em; /* Match-01 */
		/* inside @supports so that iOS <= 8 display the native arrow */
		background: none; /* Match-04 */
		/* inside @supports so that Android <= 4.3 display the native arrow */
		border: 1px solid transparent; /* Match-05 */

		-webkit-appearance: none;
		-moz-appearance: none;
		appearance: none;
	}
	.custom-select select:focus {
		border-color: #aaa; /* Match-03 */
	}
}
.custom-select {
	border: 3px solid #303840;
	background: #56B4F9;
}

.custom-select::after {
	width: 0;
	height: 0;
	border-left: 4px solid transparent;
	border-right: 4px solid transparent;
	border-top: 7px solid #303840;
	margin-top: -3px;
}

.custom-select select {
	font-family: 'Source Sans Pro', Avenir, 'Helvetica Neue', Helvetica, Arial, sans-serif;
	letter-spacing: 0px;
	font-weight: 700;
	color: #303840;
	line-height: 1.5;
	cursor: pointer;
}


/* Focus style */

.custom-select select:focus {
	outline: none;
	box-shadow: none;
	border: 1px solid transparent;
}


/* Set options to normal weight */

.custom-select option {
	font-weight: bold;
	background: #fff;
	box-shadow: none;
}
&#13;
&#13;
&#13;

答案 2 :(得分:0)

根据项目的性质,使用div元素来设置select样式的原因有多种,这可能是一个坏主意。仅举几例:

  • 您不会受益于原生移动浏览器界面支持。
  • 您可能还会对可访问性和可用性产生副作用。

如果您需要完整的详细信息,请参阅here主题的非常好的文章。

如果你仍然认为你需要这个,我怀疑你试图修复你提供的JSFiddle将提供良好的投资回报。你需要更多的东西来获得一个很好的选择(包括一些不可忽视的JavaScript)。我建议的是调查流行的现有解决方案来实现目标,例如:

  1. 选择2:https://select2.github.io/examples.html
  2. bootstrap-select:http://silviomoreto.github.io/bootstrap-select/examples/
  3. Selectize.js:http://selectize.github.io/selectize.js/