Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   div всегда по высоте браузера (https://javascript.ru/forum/jquery/16241-div-vsegda-po-vysote-brauzera.html)

Freakmeister 31.03.2011 01:41

div всегда по высоте браузера
 
Есть такая вёрстка дивами: http://maestro-magnifico.ru/
В CSS прописано примерно следующее:
Код:

html {
height: 100%;
}

body {
height:100%;
background-image:url('images/bg.gif');
}

.main_border {
border:solid 1px #333333;
width: 90%;
height:99.7%; /* с запасом для бордеров */
margin:0 auto;
background-color:#FFFFFF;
min-width: 600px;
}

Смысл всего этого - сделать центральный блок - main_border, который содержит все остальные блоки, в 100% по высоте. Я окрасил его светло-зелёным для наглядности. Так как вёрстка резиновая, вы можете попробовать сузить окно браузера по ширине и сразу увидите в чём проблема - футер уезжает вниз, вместе с текстом в центральном блоке (как им и положено), а высота main_border не меняется. Нужно сделать чтобы он всегда оставался по высоте окна при ресайзе. На сколько я понимаю, сделать это на чистом CSS невозможно, и тут нужен JavaScript. Хочу использовать jQuery для этого, с синтаксисом знаком в теории, на практике ещё не применял, так что, даже не представляю как это должно работать. Буду признателен за любые подсказки.

Aetae 31.03.2011 02:13

Сотни готовых css вариантов в интернете.
Надо только поискать.

рони 31.03.2011 02:40

Цитата:

Сообщение от Freakmeister
height:99.7%; /* с запасом для бордеров */

замените на min-height: 100%;

poorking 31.03.2011 02:56

Я бы наверно вот так сделал, но это наверно не кроссбраузерно, вроде IE старых версий не может из изначально block элемента сделать inline-block, но в ie8-9 вроде работает, на других нет возможности проверить
<!DOCTYPE html>

<div class = "wrapper">
	<div class = "header">
		<h1>Header</h1>
	</div>
		
	<div class = "content">
		<div class = "nav col">
			<ol>
				<li>item</li>
				<li>item</li>
				<li>item</li>
				<li>item</li>
				<li>item</li>
			</ol>
		</div>
		<div class = "main col">
			Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br />
			Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
		</div>
		<div class = "extra col">
			Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only
	
		</div>
	</div>
	
	<div class = "footer">
		footer
	</div>
</div>
<style type = "text/css">
*{
	margin:0px; padding:0px;
}
html{
	height:100%;
}
body{
	height: 100%;
}
.header{
	background-color: orange;
}
.content{
	background-color: #eee;
}
.col{
	display: inline-block;
	vertical-align:top;
	padding:1%;
	
}
.nav{
	width: 15%;
	background-color: #fed;
}
.extra{
	margin-left:-4px;
	width: 20%;
	background-color: #fa5;
}
.main{
	overflow: auto;
	margin-left:-4px;
	width: 59%;
	background-color: #def;
}
.footer{
	text-align: center;
	background-color:gray;
}
.wrapper{
	height:100%;
	background-color:lightblue;
}
</style>

Freakmeister 31.03.2011 13:49

Цитата:

Сообщение от рони (Сообщение 98628)
замените на min-height: 100%;

Омайгад! Сработало.. :blink:


Часовой пояс GMT +3, время: 12:54.