Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to do this without JavaScript (html layout)

The page has the following layout:

<div id="main" style="min-height:500px;"> 
    <div id="header"></div>
    <div id="content"></div>
    <div id="footer"></div>
<div>

The main div can have a fixed height or min-height (style="height:500px;" or style="min-height:375px;").

Is it possible to make the footer and header take as much height as they need and allow the content to take the rest (content.height = main.height - (header.height + footer.height)) (without using JavaScript, elastic header and footer, content takes the rest)?

like image 540
Omu Avatar asked Jun 06 '12 10:06

Omu


People also ask

Can HTML work without JavaScript?

If we're talking about websites “working” or not with or without JavaScript, a site that is client-side rendered will 100% fail without JavaScript. It is sort of the opposite of “server-side rendered” ( SSR ) in which the document comes down as HTML right from the server.

Is it possible to make website without JavaScript?

Absolutely yes. With the webassembly, now you can run other languages on web and this runs faster than js. You can make website without js but it will not be interactive. In web development actually, there is no such alternative to JavaScript.

Can you use CSS without JavaScript?

Yes, you can animate elements with CSS only. No need for JavaScript!

Can I create dynamic website without JavaScript?

Yes you can, by generating all HTML on the server.


1 Answers

Yes, it is possible.

HTML:

<div id="main"> 
    <div id="header"></div>
    <div id="content"></div>
    <div id="footer"></div>
<div>

CSS:

html, body {
    margin: 0;
    padding: 0;
    height: 100%; /* needed for #main min-height */
}

div#main {
    position: relative; /* needed for footer positioning */
    height: auto !important; /* real browsers */
    height: 500px; /* IE6: treated as min-height*/
    min-height: 500px; /* real browsers */
}

div#header {
    /* Will be as high as its content */
}

div#content {
    /* Will be displayed below #header regardless to its height */
    padding: 0px 0px 50px 0px; /* bottom padding for footer + space */
}

div#footer {
    position: absolute;
    width: 100%;
    height: 40px; /* Needs to be fixed size because of #content padding-bottom */
    bottom: 0; /* stick to bottom */
}

This actually don't set #content height as you wanted, but displays everything as it should be (#main has expected height, #footer is at the bottom and doesn't cover #content).

like image 142
Wirone Avatar answered Oct 03 '22 23:10

Wirone