2011-08-23 8 views
2

의사 요소의 CSS를 동적으로 설정할 수 있습니까? 예를 들면 :자바 스크립트를 사용하여 의사 요소 CSS 동적으로

동적 도움말 용기를 스타일링

jQuery를

$('#help').css({ 
    "width" : windowWidth - xOffset, 
    "height" : windowHeight - yOffset, 
    "bottom" : -windowHeight, 
    "left" : 200 
}); 

내부 도움말 컨테이너의 경계 설정에 jQuery를 시도 : 위의

에 대한

$('#help:before').css({ 
    "width" : windowWidth - xOffset, 
    "height" : windowHeight - yOffset 
}); 

CSS 파일을

#help { opacity: 0.9; filter:alpha(opacity=90); -moz-opacity: 0.9; z-index: 1000000; bottom: -550px; left: 400px; background-color: #808080; border: 5px dashed #494949; -webkit-border-radius: 20px 20px 20px 20px; -moz-border-radius: 20px 20px 20px 20px; border-radius: 20px 20px 20px 20px; } #help:before { border: 5px solid white; content: ''; position: absolute; -webkit-border-radius: 20px 20px 20px 20px; -moz-border-radius: 20px 20px 20px 20px; border-radius: 20px 20px 20px 20px; } 
+0

[자바 스크립트에서 CSS 의사 클래스 규칙 설정]의 중복 가능성 (http://stackoverflow.com/questions/311052/setting-css-pseudo-class-rules-from-javascript) – thirtydot

답변

0

.css()을 사용하여 너비와 높이를 설정하는 대신 .width()height()을 직접 사용해야합니다.

+1

당신이 게시 할 수 있습니다 이 코드는 내 코드가 작동하지 않습니다 : $ ('# help : before'). width (windowHeight - 410) .height (windowHeight - 210); – Jack

관련 문제