2013-07-26 62 views
0

我在这里一个小问题,我做了一个的jsfiddle为你们用它玩:http://jsfiddle.net/darkguy2008/NQUz8/HTML拉伸页眉和页脚长期的内容没有JS

我的问题是,当有不可避免的长内容,页眉和页脚不会延伸到它,而是最大的浏览器窗口。

我需要找到一种方法让它伸展,我已经有了一个想法,即将页眉和页脚作为内容div的一部分,但如果内容比浏览器窗口更短,它们不会伸展到100%的浏览器窗口宽度,这就是我不想要的。

此外,页面的标题/副标题可以长于内容,这样对大家都没好处:/

我很想改变设计,但它是一个报告的网站,我可以” t把它放在一个边缘:0 auto;因为这个想法并不是以网站为中心或者使报告具有固定的宽度(因为它们不能)。

这个想法也是为了避免JS。我知道我可以使用JQuery修复宽度,但项目也可以被外部客户端使用,所以我们不能强制他们使用JS。奇怪我知道,但我已经看到了愚蠢的系统管理员阻止JS的情况,我们不能做太多的工作,除了让它工作。

我可以使用HTML5和CSS3,因此,如果有一种方法,与这两个技术做这将是巨大的:)

任何想法,欢迎!

HTML:

<header> 
    <div class="wrap"> 
     <table border="0"> 
      <tr> 
       <td rowspan="2"> 
        <img src="http://dummyimage.com/230x100/000/fff&text=LOGO" align="left" style="border-width:0px;" /> 
       </td> 
       <td> 
        <h1>title 1 lololol</h1> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <h2>subtitle omgomgomgomgomg</h2> 
       </td> 
      </tr> 
     </table> 
    </div> 
    <div id="menu">menu goes here omg</div> 
</header> 
<div>contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontent</div> 
<footer> 
    <div class="wrap"> 
     <p>Footer goes here o.o"</p> 
    </div> 
</footer> 

CSS:

/*********************/ 
/** RESET */ 
/*********************/ 
* 
{ 
    padding: 0; 
    margin: 0; 
    /*border: 0;*/ 
    font-family: Arial; 
} 

/*********************/ 
/** Main CSS */ 
/*********************/ 
body 
{ 
    font-family: Arial; 
    font-size: 10pt; 
} 

.wrap 
{ 
    position: relative; 
    margin: 0 0; 
    width: 640px; 
} 

header, footer 
{ 
    background: #0f6; 
    float:left;  
    min-width:100%; 
} 

#menu 
{ 
    min-width: 100%; 
    border-top: 2px solid red; 
    border-bottom: 2px solid red; 
} 

th, td { padding: 0; } 
table { border-collapse:collapse; border-spacing: 0; } 
+0

是'contentcontentcontent [...]'真正的使用 - 情况,还是你的内容实际上包含空白;即'内容内容'?只需在文本中添加空格,就可以进行文字换行。 –

+0

这是一种真正的用例。我的网站将有一些表格,这些表格有时会很长(或者至少足以让我在这里提到的错误出现)显示数据,所以它们不能包装:( – DARKGuy

+0

这是一个完全独立的用例。正如你现在的问题所展示的那样,你有一个宽广的视角,因为你有一个完整的词。默认情况下,浏览器不会包装那些内容,所以我希望所有你会得到的答案都会提到改变单词包装的行为,但这不会解决你的问题'

'问题。 –

回答

0

基本上你必须在你的“标题”元素中加入内容和页脚,这样你的内容才能增长。

HTML

<div> 
<header> 
    <div class="wrap"> 
     <table border="0"> 
      <tr> 
       <td rowspan="2"> 
        <img src="http://dummyimage.com/230x100/000/fff&text=LOGO" align="left" style="border-width:0px;" /> 
       </td> 
       <td> 
        <h1>title 1 lololol</h1> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <h2>subtitle omgomgomgomgomg</h2> 
       </td> 
      </tr> 
     </table> 
    </div> 
    <div id="menu">menu goes here omg</div> 
    <div class="content">contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontent</div> 
    <footer> 
    <div class="wrap"> 
     <p>Footer goes here o.o"</p> 
    </div> 
</footer> 
</header> 


</div> 

在修改CSS:

.content 
{ 
    background: #FFFFFF; 
} 

这里是工作提琴:

Fiddle

+0

是啊!正是我需要的! :D我不敢相信我昨天花了整整一天的时间试图去做,非常感谢! :)我不知道如何重新排列div,因此它们都是页眉和页脚的一部分:D – DARKGuy

0

正如在帖子的最后,在这里使用的自动换行和你的宽度设置为任何你想要它。我以100%为你设定它,但它只能达到你拥有的最大宽度。 http://jsfiddle.net/NQUz8/2/

<div style="word-wrap:break-word; width="100%;">content here</div> 

我会使用某种类型的css类或id,如果可以的话。我只是在这里使用风格来告诉你它是如何工作的。

+0

我会对此赞不绝口,但我还没有足够的声望呢:(你的建议太棒了,因为它使得内容包装,所以我可以使用它,即移动设备:)我一定会使用它,谢谢! – DARKGuy