簡體   English   中英

避免在菜單中更改鼠標懸停

[英]Avoid mouse hover change in ul li menue

我正在使用twitter bootstrap以便具有類似列表的選擇選項。

我想避免用鼠標移到列表項上來改變它們的背景。 參見screeshot:

屏幕截圖

下面是可見的代碼。 看看jsfiddle將是最簡單的:

https://jsfiddle.net/qqnkc9u3/3/

的HTML:

<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
    D2ropdown
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
    <li><a class="my2" href="#"><!--data-value="action"--> Action</a></li>
    <li><a class="my2" href="#" data-value="another action">Another action</a></li>
    <li><a class="my2" href="#" data-value="something else here">Something else here</a></li>
    <li><a class="my2" href="#" data-value="separated link">Separated link</a></li>
</ul>

js:

$(".dropdown-menu li a").click(function(){
$(this).parents(".dropdown").find('.btn').html($(this).text() + ' <span ></span>');
$(this).parents(".dropdown").find('.btn').val($(this).data('value'));
});

CSS:

@charset "UTF-8";

@import url('https://fonts.googleapis.com/css?family=PT+Sans');

#dropdownMenu1 {
/*text-indent: -150px;*/
-webkit-appearance: none;
-moz-appearance: none;

font-family: 'PT Sans', sans-serif;
/*font-style: italic;*/
color: red;
font-size: 18px;
text-align: left;

width: 242px;
height: 42px;
border: 4px;
/*background-color: #e7eaf3;*/
background: url("http://www.adelepham.com/deepthoughts/gray-pattern.jpg") no-repeat 0 0;
/*color: #5B629B;*/
/*padding: 4px;*/
}

.my2 {
text-indent: -7px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;

font-style: italic;
font-family: 'PT Sans', sans-serif;
color: red;
font-size: 18px;

-webkit-appearance: none;
-moz-appearance: none;
width: 242px;
height: 42px;
/*border: 4px;*/
/*color: #5B629B;*/
background: url("http://www.adelepham.com/deepthoughts/gray-pattern.jpg") no-repeat 0 0;
}

您可以通過將Bootstrap選擇器添加到CSS來覆蓋Bootstrap的默認值;

.my2,
.dropdown .dropdown-menu>li>a:focus, 
.dropdown .dropdown-menu>li>a:hover {
    text-indent: -7px;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
    border-radius: 3px;

    font-style: italic;
    font-family: 'PT Sans', sans-serif;
    color: red;
    font-size: 18px;

    -webkit-appearance: none;
    -moz-appearance: none;
    width: 242px;
    height: 42px;
    /*border: 4px;*/
    /*color: #5B629B;*/
    background: url("http://www.adelepham.com/deepthoughts/gray-pattern.jpg") no-repeat 0 0;
}

看到更新的小提琴: https//jsfiddle.net/qqnkc9u3/4/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM