我的問題可能很簡單,但不知何故,我不能得到它修復。在一組對象中有一個對象懸停的情況下,我希望懸停對象保持不變,但所有其他對象都應該改變。獲取所有沒有徘徊的元素,並與他們做一些事
更具體地說:我有一個無序的菜單項列表。每當我將其中一個懸停時,所有其他項目都應該變小。當我「解除」這個項目時,他們應該改回來。
我發現這個職位,但它的答案並沒有爲我工作: Set style for not not hovered elements only
這是我試過到目前爲止:
/*This is the default size*/
#navigation ul li a
{
font-size: 14px;
}
/*When the list is hovered, change font-size (does’nt work)*/
#navigation ul:hover
{
font-size: 13px;
}
/*When the a menu-item is hovered change it’s font-size back to default*/
#navigation ul li a:hover
{
font-size: 14px;
}
這是我找到的答案之一後我提到。如果只用簡單的CSS就可以完成,那將會很棒。但它不起作用。我做錯什麼了嗎?
我也嘗試過用jQuery,儘管我不是專家。
for(var i=1; i <= anzahlNavipunkte; i++)
{
var naviId = "navi" + i; // id name for every menu-item
var currentMenuItem = "#navigation li:nth-child(" + i + ") a";
$(currentMenuItem).attr('id', naviId); // gives the current menu-item a specific id
$('#navigation li a').hover(function()
{
var hoveredId = $(this).attr("id"); // get the id of of the hovered element
$('#' + hoveredId).hover(function()
{
console.log(hoveredId);
$('#' + hoveredId).css('font-size', '14px'); // hovered element gets default font-size
$('#navigation ul').css('font-size', '13px'); // other elements change to 13px
}, function()
{
$('#navigation ul').css('font-size', '14px'); // other elements change back
})
});
};
它也行不通。可能是因爲它與純CSS解決方案的方法相同。有人可以幫我嗎?
我希望我的解釋是可以理解的。如果還有問題,請詢問。
你可以在這裏發佈你的'html'或者製作一個[fiddle](http://jsfiddle.net)。 –