2017-03-16 18 views
0

小提琴位於:https://jsfiddle.net/9me1rrLm/爲什麼我的div表格在調整大小時會失去底部邊框?

<body style="padding: 0px; margin: 0px; overflow-y: scroll; overflow-x: hidden; width: 100%;"> 
<div style="height:50px; overflow:hidden;"> 
<div style="display: table; width: 100%; height: 100%;"> 
    <div style="display: table-row;"> 
     <div style="display: table-cell; border-style: solid; width: 10%; vertical-align: top;"> 
     0002 
     </div> 
     <div style="display: table-cell; border-style: solid; width: 40%; vertical-align: middle;"> 
     Johnny Five Johnny Five Johnny Five 
     </div> 
     <div style="display: table-cell; border-style: solid; width: 30%; vertical-align: bottom;"> 
     Robotin' 
     </div> 
     <div style="display: table-cell; border-style: solid; width: 20%; vertical-align: bottom;"> 
     [email protected] 
     </div> 
    </div> 
</div> 
</div> 
</body> 

當瀏覽器是有點大多擴大,沒有任何問題:

Image 1

見,縮小瀏覽器之後,所以大多是擴大了,仍然沒有問題:

Image 2

然後,只要我能縮小瀏覽器後,我失去的文字和底邊框:

enter image description here

爲什麼?我不想失去邊界,我希望儘可能多的文本留在單元格內(溢出不可見)。

謝謝。

編輯1:只是爲了澄清,我不想刪除溢出隱藏或增加表的高度。保持這一點是什麼使這個問題變得困難。例如,我在這裏具有相同的固定高度和溢出,除了忽略我的垂直對齊外,它的工作原理非常完美。所以我現在有兩個版本。一個使邊界消失,其他失去它的垂直alginment(但允許文本對齊):

https://jsfiddle.net/2L0cggds/

<body style="padding: 0px; margin: 0px; overflow-y: scroll; overflow-x: hidden; width: 100%;"> 
<div style="display: table; width: 100%; height: 50px;"> 
    <div style="display: table-row; width: 100%; height: 50px;"> 
     <div style="display: table-cell; width: 10%;height: 50px; border-style: solid;"> 
     <div style="overflow:hidden; height: 50px;vertical-align:bottom;text-align:right;"> 
     0004 
     </div> 
     </div> 
     <div style="display: table-cell; width: 40%;height:50px;border-style: solid;"> 
     <div style="overflow:hidden; height:50px;vertical-align:bottom;text-align:right;"> 
     Johnny Five Johnny Five Johnny Five 
     </div> 
     </div> 
     <div style="display: table-cell; width: 30%;height: 50px; border-style: solid;"> 
     <div style="overflow:hidden; height: 50px;vertical-align:bottom;text-align:right;"> 
     Robotin' 
     </div> 
     </div> 
     <div style="display: table-cell; width: 20%;height:50px;border-style: solid;"> 
     <div style="overflow:hidden; height:50px;vertical-align:bottom;text-align:right;"> 
     [email protected] 
     </div> 
     </div> 
    </div> 
</div> 
</body> 

EDIT2:我知道這是可能的,因爲我看到在Visual Web GUI完成這件事。這花了我視覺的WebGUI分鐘看一看,看看如何邊框並沒有消失,文字停留在細胞內(小時HTML/CSS,在看不到盡頭和!):

enter image description here

這裏是我查看源代碼時看到的div瘋狂(它就像div內的div一樣......我只能展開並顯示出我們看到第一個單元格的位置......並突出顯示了50px ):

vwg image 1

回答

0

我得正是我想要的一個解決方案。我認爲我受到了「酷孩子」的影響,但我喜歡結果,並且我已經在html表格中工作了,所以我不需要看到強制這個與div表很好地配合。

它還需要表格中的表格。

總之,這裏的東西是完美的作品:

https://jsfiddle.net/99qz9okk/

<table style="width: 100%; height: 100px; table-layout:fixed;" cellspacing="0" cellpadding="0"> 
    <tr> 
     <td style="border-style: solid; width: 10%;"> 
      <div style="height: 100px; overflow:hidden;"> 
      <table cellspacing="0" cellpadding="0" style="width: 100%; height: 100%; table-layout:fixed;"> 
      <tr> 
      <td style="vertical-align: bottom; text-align: left;"> <!-- vertical-align needs to be here, it seems --> 
      0001 
      </td> 
      </tr> 
      </table> 
      </div> 
     </td> 
     <td style="border-style: solid; width: 40%;"> 
      <div style="height: 100px; overflow:hidden;"> 
      <table cellspacing="0" cellpadding="0" style="width: 100%; height: 100%; table-layout:fixed;"> 
      <tr> 
      <td style="vertical-align: bottom; text-align: right;"> 
      Johnny Five Johnny Five Johnny Five! Johnny Five Johnny Five Johnny Five? Johnny Five Johnny Five Johnny Five!! 
      </td> 
      </tr> 
      </table> 
      </div> 
     </td> 
     <td style="border-style: solid; width: 30%;"> 
      <div style="height: 100px; overflow:hidden;"> 
      <table cellspacing="0" cellpadding="0" style="width: 100%; height: 100%; table-layout:fixed;"> 
      <tr> 
      <td style="vertical-align: bottom; text-align: center;"> 
      Robotin' 
      </td> 
      </tr> 
      </table> 
      </div> 
     </td> 
     <td style="border-style: solid; width: 20%;"> 
      <div style="height: 100px; overflow:hidden;"> 
      <table cellspacing="0" cellpadding="0" style="width: 100%; height: 100%; table-layout:fixed;"> 
      <tr> 
      <td style="vertical-align: middle; text-align: center;"> 
      [email protected] 
      </td> 
      </tr> 
      </table> 
      </div> 
     </td> 
    </tr> 
</table> 

也就是說,只是工作。我可以保持高度不變(不會增加)。文本溢出不會擴展到它所在的單元格之外。我不會丟失底部邊框。我可以垂直和水平對齊文本。完善。

不是我是絕對noob,但我最近沒有涉足html/css(更多C++,C#,後端等)。但正如我所提到的,「酷小孩」一直在談論div,但是在使用div表時我還沒有找到一個解決方案 - 或者更困難或者我以某種方式丟失了某些東西。我認爲,這是我缺乏理解的地方,但嘿,爲什麼不嘗試使用我的「html表格」解決方案,而只是替換:

  • 表格與div顯示:表;
  • tr with div display:table-row;
  • td with div display:table-cell;

那麼,這不正確的工作,所以,哦!現在,我不喜歡你的div表!

對於哈哈的:

https://jsfiddle.net/8goq3hkv/

<div style="display: table; width: 100%; height: 100px; table-layout:fixed;"> 
    <div style="display: table-row;"> 
     <div style="display: table-cell; border-style: solid; width: 10%;"> 
      <div style="height: 100px; overflow:hidden;"> 
      <div style="display: table; width: 100%; height: 100%; table-layout:fixed;"> 
      <div style="display: table-row;"> 
      <div style="display: table-cell; vertical-align: bottom; text-align: left;"> <!-- vertical-align needs to be here, it seems --> 
      0001 
      </div> 
      </div> 
      </div> 
      </div> 
     </div> 
     <div style="display: table-cell; border-style: solid; width: 40%;"> 
      <div style="height: 100px; overflow:hidden;"> 
      <div style="display: table; width: 100%; height: 100%; table-layout:fixed;"> 
      <div style="display: table-row;"> 
      <div style="display: table-cell; vertical-align: bottom; text-align: right;"> 
      Johnny Five Johnny Five Johnny Five! Johnny Five Johnny Five Johnny Five? Johnny Five Johnny Five Johnny Five!! 
      </div> 
      </div> 
      </div> 
      </div> 
     </div> 
     <div style="display: table-cell; border-style: solid; width: 30%;"> 
      <div style="height: 100px; overflow:hidden;"> 
      <div style="display: table; width: 100%; height: 100%; table-layout:fixed;"> 
      <div style="display: table-row;"> 
      <div style="display: table-cell; vertical-align: bottom; text-align: center;"> 
      Robotin' 
      </div> 
      </div> 
      </div> 
      </div> 
     </div> 
     <div style="display: table-cell; border-style: solid; width: 20%;"> 
      <div style="height: 100px; overflow:hidden;"> 
      <div style="display: table; width: 100%; height: 100%; table-layout:fixed;"> 
      <div style="display: table-row;"> 
      <div style="display: table-cell; vertical-align: middle; text-align: center;"> 
      [email protected] 
      </div> 
      </div> 
      </div> 
      </div> 
     </div> 
    </div> 
</div> 
1

這是因爲你在一個容器設置一個高度50px因此,當文本環繞並使單元更大時,它將在底部切割表格。

JSFiddle

<body style="padding: 0px; margin: 0px; overflow-y: scroll; overflow-x: hidden; width: 100%;"> 

<!-- REMOVE THE HEIGHT ATTRIBUTE FROM THIS DIV --> 
<div style="height:50px; overflow:hidden;"> 

<div style="display: table; width: 100%; height: 100%;"> 
    <div style="display: table-row;"> 
     <div style="display: table-cell; border-style: solid; width: 10%; vertical-align: top;"> 
     0002 
     </div> 
     <div style="display: table-cell; border-style: solid; width: 40%; vertical-align: middle;"> 
     Johnny Five Johnny Five Johnny Five 
     </div> 
     <div style="display: table-cell; border-style: solid; width: 30%; vertical-align: bottom;"> 
     Robotin' 
     </div> 
     <div style="display: table-cell; border-style: solid; width: 20%; vertical-align: bottom;"> 
     [email protected] 
     </div> 
    </div> 
</div> 
</div> 
</body> 
+0

我的道歉。我不希望桌子的高度增加(這將成爲我想要的一個固定高度的標題),並且如果他們確實將其大小設置爲所有文字都不適合的程度,我可以儘可能多地顯示,其餘部分(溢出)被隱藏。這就是爲什麼我很難以及爲什麼要伸出援手。我知道這是可能的,因爲我已經看到了這一點。我將添加一些Visual WebGUI代碼的圖片,這些代碼完成了我想要實現的功能。 – JustLooking

+0

想通了。去掉div表和使用html表。 – JustLooking

1

刪除溢出的內嵌樣式:隱藏或調整容器的高度。

+0

但我希望容器具有一定的高度,並且我不希望文本溢出單元格。他們是必要的。 – JustLooking

+0

然後我會建議使用媒體查詢來調整字體大小或使列的寬度更寬。如果這條線斷了一個字,它會使列更長。 – SROwl

+0

我正在嘗試重新創建我在Visual WebGUI代碼中看到的內容,並且我確定他們不會執行您的建議。然而,他們能夠。但是有很多div容器和css類,我無法追蹤源代碼。 – JustLooking

1

你的問題是,該表顯示在div具有其height明確設置爲網頁時皺縮下來,是不是足夠大的值,並且div上有overflow:hidden集:

<div style="height:100px; overflow:hidden;"> 

刪除overflow:hidden,那不會發生。對於修改的工作版本,請參閱here

您還可以設置overflow:scroll以保持整體高度並允許用戶查看所有溢出的表格。請參閱here

+0

我的歉意。我不希望桌子的高度增加(這將成爲我想要的一個固定高度的標題),並且如果他們確實將其大小設置爲所有文字都不適合的程度,我可以儘可能多地顯示,其餘部分(溢出)被隱藏。這就是爲什麼我很難以及爲什麼要伸出援手。我知道這是可能的,因爲我已經看到了這一點。我將添加一些Visual WebGUI代碼的圖片,這些代碼完成了我想要實現的功能。 – JustLooking

+0

想通了。去掉div表和使用html表。 – JustLooking

2

這是因爲這個代碼包裝你的表:

<div style="height:50px; overflow:hidden;"> 

表變得更高。即其下邊界下降,但包裝div(見上)隱藏溢出部分。

如果仍然想要一個底部邊框,只需將其適用於本包裝DIV:

https://jsfiddle.net/q3rxj91p/1/

+0

關閉,種類很多(底部邊界更厚),但我失去了單元格3和單元格4中與底部對齊的文本。我知道這是可能的,我盯着由VWG生成的HTML實現了這一點!我很親密! – JustLooking

+0

那你爲什麼不把文字對齊呢?底部被你的'overflow:hidden'規則隱藏(https://jsfiddle.net/q3rxj91p/3/) – Johannes

+0

因爲我想有能力把文本放在單元格的任何地方。它可以垂直對齊頂部,中部,底部和文本對齊的左,中,右。我爲用戶提供了爲特定實用程序生成簡單網頁的功能。所以我正在組建一個設計師,讓他們有一個標題,一個身體和一個頁腳。這將是我的標題的一部分,我允許(在標題中)只是一個圖像,只是文本,或兩者(所以表格將擴展到兩個「兩個」列)。文本可以放置在圖像下方,左上方,右下方。文本可以按照他們的意願對齊 – JustLooking

相關問題