2014-12-26 4 views
0

web-tiki's responsive square elements을 조정했으며 로그인 화면을 만들고 싶습니다.화면의 반응 형 사각형 채우기 너비와 높이에서 div를 만드는 방법은 무엇입니까?

로그인 화면에서 헤더를 사용하고 나머지 페이지에 화면의 높이와 너비를 정확하게 채우고 싶습니다. 폭과 높이를 작성 그것은 다음과 같이 보일 것입니다 :

End result as wished

은 지금 코드가없는 부분 [배경 이미지 FILL 폭의 나머지와 HEIGHT] 단지 내 컨트롤의 외부 크기를 조정하기 때문에이를 수행 않습니다.

HTML :

<div id="top"> 
    <h1>My header</h1> 
</div> 

<!-- Fixed main screen --> 
<div id="login-screen" class="bg imgloginscreen"> 
    <div class="content rs"> 
     <div class="float-left">Some text, blabla</div> 
     <div class="float-right"> 
      <form> 
       <input type="text" value="Username"/><br/> 
       <button type="submit">Login </button> 
      </form> 
     </div> 
    </div> 
</div> 

CSS :

/* Responsive square elements stylesheet is adjusted from http://jsfiddle.net/webtiki/MpXYr/3/light/ which was designed by http://web-tiki.com/ */ 

#top { 
    clear: both; 
    margin: 0.25%; 
    width: 99.5%%; 
    padding: 0.1%; 
    background-color: #000; 
    color: #fff; 
} 
.imgloginscreen { 
    background-image: url('http://upload.wikimedia.org/wikipedia/en/3/37/Leaves.JPG'); 
} 
.content { 
    position: absolute; 
    height: 90%; /* = 100% - 2*5% padding */ 
    width: 90%; /* = 100% - 2*5% padding */ 
    padding: 5%; 
} 
/* For responsive images */ 
.content .rs { 
    width: auto; 
    height: auto; 
    max-height: 90%; 
    max-width: 100%; 
} 
.float-left { 
    float: left; 
} 
.float-right { 
    float: right; 
} 
/* Not sure how to make it fill the rest of screen? */ 
#login-screen { 
    float: left; 
    position: relative; 
    height: 99.5%; 
    width: 99.5%; 
    padding-bottom: 50%; 
    margin: 0.25%; 
    overflow: hidden; 
    background-color: #1E1E1E; 
} 

body { 
    font-family: 'Lato',verdana, sans-serif; 
    font-size: 20px; 
    color: #fff; 
    text-align: center; 
    background: #ECECEC; 
    margin: 0; 
} 

나는 누군가가 나가 화면에 들어갈 수 있도록 도와 수 있기를 바랍니다.

감사합니다.

JSFiddle : http://jsfiddle.net/2shygbcy/2/

+0

당신이 더 일반적인 접근 방법을 시도 할 수없는 이유는 무엇입니까? http://jsbin.com/fecofuzoje/1 –

답변

1

을 것이라고 기대하고 무엇을 확인 잊지 마세요.

HTML & CSS :

body { 
 
    margin: 0; 
 
    height: 700px; /* adjust according to your screen height */ 
 
    overflow-y: hidden; 
 
} 
 
#header { 
 
    background: #000; 
 
    color: #fff; 
 
    text-align: center; 
 
    padding: 10px 0; 
 
} 
 
#content { 
 
    height: 100%; 
 
    background: #1E1E1E; 
 
    padding-top: 20px; 
 
    text-align: center; 
 
} 
 
input[type="submit"] { 
 
    margin-top: 10px; 
 
}
<div id="header"> 
 
    <h1>My Header</h1> 
 
</div> 
 
<div id="content"> 
 
    <input type="text" placeholder="username" /> 
 
    <br/> 
 
    <input type="submit" value="Login" /> 
 
</div>

+0

감사. 모바일, 태블릿 및 데스크톱에 대한 높이가 다르다는 것을 염두에두면 다음과 같이 화면 높이에 따라 어떻게 조정해야합니까? 'height : 700px;/* 화면 높이에 따라 조정 * /'? –

+1

당신은 그에 대한 다양한 탐지 기술을 사용할 수 있으며 이에 따라 특정 CSS를로드 할 수 있습니다 : SO에 대한 게시물을 확인하십시오 : http://stackoverflow.com/questions/15228937/php-check-if-the-page-run-on- 모바일 또는 데스크톱 브라우저 http://stackoverflow.com/questions/14440296/reliable-way-to-detect-desktop-vs-mobile-browser http://stackoverflow.com/questions/4117555/ 가장 단순한 방법으로 모바일 장치 감지 희망이 도움이 되길 바랍니다. –

+1

감사합니다. 결국이 접근법을 사용하여 JavaScript를 사용하여 높이를 계산했습니다. $ ('# login'). css ({ height : ($ (window).innerHeight() - $ ('# top'). innerHeight()) });' –

1

사용 vw and vh Measurements

*{box-sizing: border-box; padding: 0; margin: 0} 
.imgloginscreen { 
    width: 100wv; 
    height: 100vh; 
    position: fixed; 
    top: 0; 
    left: 0; 
    background-image: url('http://upload.wikimedia.org/wikipedia/en/3/37/Leaves.JPG'); 
} 
+0

감사합니다.하지만 작동하지 않습니다. 이미지는 페이지 크기를 조정할 때 크기가 조정되고 작아집니다. –

+0

제안 사항을 구현하고 화면의 크기를 변경하여 http://jsfiddle.net/2shygbcy/2/를 참조하십시오. 화면이 가득 채워져 있어야합니다. –

1

box-sizing - CSS 이봐,이 당신은 내가 더 일반적인 접근 방식을 시도하는 것이 좋습니다

 

    http://jsfiddle.net/2shygbcy/1/ 

+0

흠 여기 백그라운드에서 이미지를 가져올 수 없습니다. 감사. –

관련 문제