2015-01-27 4 views
0

나는 div 요소가 있습니다CSS 속성에 JavaScript 값을 할당하는 방법은 무엇입니까?

<div class="page"> 
     //some contents 
</div> 

CSS : 자바 스크립트와

.page{ 
    bottom: 0; 
    color: #1f1f21; 
    font-size: 17px; 
    font-weight: 400; 
    left: 0; 
    overflow: visible; 
    position: absolute; 
    right: 0; 
    top: 0; 
} 

얻기 화면 높이 :

var page_height = screen.height; 
alert(page_height); 
.page 클래스에이 page_height 값을 적용 할 수있는 방법을

?

(예) 나는 높이 속성을

height: 405px; 

답변

1

사용 .height()를 추가 할 필요가 screen.height = 405

만약 내가, 내 page 클래스 예를 들어

에 화면의 높이를 설정해야합니다

$('.page').height(page_height); 
+0

는 언급을 ...... –

+0

downvoter 케어를 확인합니다 ?? –

+0

Worked :) 고맙습니다. 대답을 수락할까요 –

-1

시도해보십시오.(210)

var page_height = screen.height; 
 
$('.page').height(page_height) 
 
alert(page_height);
.page{ 
 
    bottom: 0; 
 
    color: #1f1f21; 
 
    font-size: 17px; 
 
    font-weight: 400; 
 
    left: 0; 
 
    overflow: visible; 
 
    position: absolute; 
 
    right: 0; 
 
    top: 0; 
 
    width:500px; 
 
    background:green; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> 
 
<div class="page"> 
 
     //some contents 
 
</div>

관련 문제