2010-02-11 33 views
1

我有一個頁面,其中有一個向左和向右的菜單我有一個帶有大量文本的新節。文本的位置正確,但是一旦文本低於左側菜單的高度,文本就會位於左側。如何將大量文本的相對元素放置在高度不高的元素旁邊,向左移動

據我所知,這是因爲該部分浮動(請糾正我,如果我錯了)到左側,並根據填充和邊距進行定位。但是,如果我想在右側保留文本的左側垂直線,我該怎麼辦?如果我使用絕對定位,「footer」(這是另一個div部分)會向上移動並重疊文本。通過將左側菜單的高度定義爲高於文本的高度,我確實得到了一個很好的垂直文本行,但很難知道在哪裏定位頁腳部分。

請參閱下面的代碼。我試圖只複製需要的東西,希望我沒有錯過任何東西。

在此先感謝!

HTML:

<div id="container"> 

<div id="subsections"> 

<h4>Games</h4> 

<ul id="subnav"> 
    <li><a href="games.html#theGame">The Game</a></li> 
</ul> 

</div><!-- END #subsections --> 

<hr /> 

<div id="maincontent"> 

<h3>Welcome</h3> 

<div id="welctext"> 

<p>Welcome to this site. Here you can find information about the applications that this company has developed. You can subscribe to information about new or updated applicaionts here.</p> 

<p>This company is a small company that focus on developing application that can be used on the a mobile device. Presently the focus is on iPhone. Here you can find out what applications that are available right now. More to come...</p> 

</div><!-- END #welctext --> 

</div><!-- END #maincontent --> 

<hr/> 

<div id="footer"> 

<p> &copy; Some company name</p> 

</div><!-- END #footer --> 

</div><!-- END #container --> 

</body> 
</html> 

CSS:

body { 
    /*background-color: #333;*/ 
    /*background-color: #98310d;*/ 
    background-color: #d7e6f1; 
    background-image: url(../images/graphics/back-tile.jpg); 
    color: #4b5dcb; 
    font-family: "Apple Braille", "Trebuchet MS", Helvetica, Arial, Verdana, sans-serif; 
    font-size: 0.9em; 
    margin: 0; 
    padding: 0 0 0 0px; 
    /* IE auto center fix */ 
    text-align: left; 
} 

#container { 
    line-height: 1.6em; 
    margin: 0 auto 0 auto; 
    width: 720px; 
    padding: 20px 0px 0px 50px; 
    text-align: justify; 
    float: left; 
} 

#maincontent { 
    margin: 0px 0px 0px 50px; 
    padding: 0; 
} 

#subscribe { 
    margin: 0px 0px 0 220px; 
    padding: 0; 
    text-align: left; 
} 

#subsections { 
    float: left; 
    margin-bottom: 40px; 
    width: 220px; 
    /*height: 1300px;*/ 
} 

ul#subnav { 
    list-style: none; 
    margin: 0; 
    padding: 14px 0 0 10px; 
} 

div#footer { 
    border-top: 1px solid #FFF; 
    clear: both; 
    font-size: .75em; 
    line-height: 1.3em; 
    margin-bottom: 40px; 
    padding-bottom: 10px; 

} 

#welctext { 
    padding: 0 0 16px 0; 
} 

回答

1

那麼,它發送的問題,我的記憶又迷上了與我之前的rember如何做到這一點後,花了不到一分鐘。邊距是父容納人的邊際,而填充僅限於前一個元素。所以,爲了獲得我想要的漂亮線條,我只是將左邊距增加到適當的大小。它的工作原理和我希望我解釋正確的...

0

另一種方法是根本不使用邊距/填充&浮動兩個元素左側,所以他們總是並排坐,不管身高。在花車

大資源:http://www.westvalley.edu/common/tutorial/instruct/cssTutorial/index__1094.htm

+0

嗯,我不明白這是如何工作的。我嘗試過,但它所做的只是將所有內容儘可能地移動到最左邊,並將文本放置在菜單下,它應該直接位於菜單的右側。 – Nicsoft 2010-02-11 14:24:51

0

其實如果你飄,你對你的部分浮在部分只上浮。如果你想「保留」該區域,你實際上需要有display: inline-block。這表現爲一個塊div,有點像一個跨度在同一時間。

我可能已經改變了很多東西,但在這裏我貼出的jsfiddle: http://jsfiddle.net/o9vLpbe4/

確保您#maincontent.width + #subsections.width < #container.width,包括填充物之類的東西。並將其全部歸爲簡化。由於它的行爲像一個跨度,如果尺寸不符合這條線,它會突破到另一條線。

我也把#subsections#maincontent裏面的div。

相關問題