2011-01-06 3 views
2

jquery를 사용하여 동일한 CSS 속성을 여러 번 덮어 쓰지 않고 적용하는 방법은 무엇입니까?jquery를 사용하여 동일한 CSS 속성을 여러 번 덮어 쓰지 않고 적용하는 방법은 무엇입니까?

$(function() { 

    $("#hello").css({ 

    // Is there a way to apply both of these instead of having the second override the first? 

    "background-image" : "-webkit-gradient(linear,left top,left bottom,color-stop(0, #444444),color-stop(1, #999999))", 
    "background-image" : "-moz-linear-gradient(top, #444444, #999999)" 

    }); 

});

답변

6

;으로 각 '지시어'를 구분하십시오.

$("#hello").css({ 
    "background-image" : "-webkit-gradient(linear,left top,left bottom,color-stop(0, #444444),color-stop(1, #999999));-moz-linear-gradient(top, #444444, #999999)" 
}); 

또한, 하나의 CSS 클래스에 넣어, 그리고이 훨씬 예뻐 및 관리 방법을 수행하십시오 CSS 클래스를

.gradient { 
    -webkit-gradient(linear,left top,left bottom,color-stop(0, #444444),color-stop(1, #999999)); 
    -moz-linear-gradient(top, #444444, #999999); 
} 


$("#hello").addClass("gradient"); 
+1

이동합니다. 장기적으로는 관리 효율성에 도움이 될 것입니다. – chprpipr

+0

위의 대답에서 마지막 컬러 스톱 속성 이후 미스 펜 린더에 문제가 있다고 생각합니다. 나는 그것을 고쳤다. – karim79

+0

죄송 합니다만 JQuery 트릭이 작동하지 않습니다. – Lastnico

관련 문제