2008-10-08 61 views
0

代碼和預覽:what i have http://img78.imageshack.us/img78/9795/previewec9.gif我怎樣才能得到這個div的一部分坐在一起?

<html> 
<head> 
<title>Testing some CSS</title> 
<style type="text/css"> 
.dDay { 
    font-size:205% 
} 
.dMon { 
    font-weight:bold; 
    font-variant:small-caps; 
    font-size:130%; 
    margin-top:-.7em; 
} 
.detailContainer { 
    vertical-align:middle; 
    display:table-cell; 
    padding:0em 0em 0em 1em; 
} 
#dContainer { 
    border:1px solid green; 
    display:table; 
    height:3.25em; 
    } 
</style> 
<body> 
<div id="dContainer"> 
    <div class="dDay">31</div> 
    <div class="dMon">sep</div> 
    <div class="detailContainer">Test O.O</div> 
</div> 
</body> 
</html> 

我的問題是:是否有可能到明年將其他日期部分,第一個,所以纔出現這樣的:what i want http://img505.imageshack.us/img505/2787/previewsp2.gif


編輯:奇怪,我試圖浮動之前我問的問題,並沒有工作...感謝大家:d

回答

2
<html> 
<head> 
<title>Testing some CSS</title> 
<style type="text/css"> 
.dDay { 
    font-size:205% 
} 
.dMon { 
    font-weight:bold; 
    font-variant:small-caps; 
    font-size:130%; 
    margin-top:-.7em; 
} 
.detailContainer { 
    vertical-align:middle; 
    display:table-cell; 
    padding:0em 0em 0em 1em; 
} 
#dContainer, #dContainer2 { 
    border:1px solid green; 
    display:table; 
    height:3.25em; 
    float: left; 
    } 
</style> 
<body> 
<div id="dContainer"> 
    <div class="dDay">31</div> 
    <div class="dMon">sep</div> 
</div> 
<div id="dContainer2"> 
    <div class="dDay">31</div> 
    <div class="dMon">sep</div> 
    <div class="detailContainer">Test O.O</div> 
</div> 
</body> 
</html> 
3

使用風格=「浮動:左」每個DIV(直接或通過一個樣式表)

+0

我想我將不得不作出額外的div來包含日期和月份,然後浮正確的嗎? – Anders 2008-10-08 15:36:22

+0

不會「顯示:table-cell;」不通過v7在IE中工作? – matthewdunnam 2008-10-08 18:26:02

1

浮動:左,如果你想將元素阻塞到s它彼此相鄰。

0
  1. 複製dContainer和放置副本後,立即它。
  2. 更改ID和新的ID給#dContainer風格。
  3. 加入剛剛#dContainer(不是新的div)新的CSS塊,並把「浮動:左;」在塊中。
0
<html> 
<head> 
<title>Testing some CSS</title> 
<style type="text/css"> 
.dDay { 
    font-size:205% 
} 
.dMon { 
    font-weight:bold; 
    font-variant:small-caps; 
    font-size:130%; 
    margin-top:-.7em; 
} 
.dDate { 
    display:table-cell; 
} 
.detailContainer { 
    vertical-align:middle; 
    display:table-cell; 
    padding-left:1em; 
} 
#dContainer { 
    border:1px solid green; 
    display:table; 
    height:3.25em; 
} 
</style> 
<body> 
<div id="dContainer"> 
    <div class="dDate"> 
     <div class="dDay">31</div> 
     <div class="dMon">sep</div> 
    </div> 
    <div class="dDate"> 
     <div class="dDay">31</div> 
     <div class="dMon">sep</div> 
    </div> 
    <div class="detailContainer">Test O.O</div> 
</div> 
</body> 
</html> 

[編輯]綜觀其他答案:
- 浮動當然是正確的答案,我只是與最初的邏輯去的,實際上完成它(做一個真正的表可能是其實邏輯最後一步......)
- 注意:不會好看在IE(6,7)。

0

有什麼理由,爲什麼你不能使用<跨度>標籤,而不是<格>的?這樣,您的網頁在沒有CSS的情況下閱讀時仍然有意義。

相關問題