2016-11-29 62 views
0

我在table中有一个div,由于它的大小,这是需要溢出几个td的。 这适用于个人电脑,但在手机上,我有一些问题,它溢出页面外。检查的截图:div在页面外溢出

enter image description here

enter image description here

代码:

body { 
 
    font-family: Verdana, sans-serif; 
 
    height: 100%; 
 
} 
 

 
.kalender {height: 60vh;} 
 

 
table, td, th { 
 
    text-align: left; 
 
    border: 1px solid black; 
 
    vertical-align: text-top; 
 
    padding: 5px; 
 
    font-size: 13px; 
 
} 
 

 
table { 
 
    height: 100%; 
 
    width: 100%; 
 
} 
 

 
th { 
 
    height: 6%; 
 
    background-color: #e7e7e7; 
 
} 
 

 
td { 
 
    width: 14.28%; 
 
    height: 15.6%; 
 
    position: relative; 
 
} 
 

 
.outer { 
 
     position: absolute; 
 
     font-size: 10px; 
 
     } 
 

 
    .details { 
 
     display: none; 
 
     background-color: gray; 
 
     overflow: visible; 
 
     border: 2px solid black; 
 
     float: left; 
 
     position: relative; 
 
     z-index: 10; 
 
     padding: 5px; 
 
     font-size: 12px; 
 
    } 
 

 
.kortNavn { 
 
    position: relative; 
 
    top: 0; 
 
    left: 0; 
 
    display: flex; 
 
    text-align: center; 
 
} 
 

 
.skoleFri { 
 
    border-radius: 50%; 
 
\t width: 8px; 
 
\t height: 8px; 
 
    background-color:red; 
 
    display: inline-block; 
 
} 
 

 
.sfoFri { 
 
    border-radius: 50%; 
 
\t width: 8px; 
 
\t height: 8px; 
 
    background-color:blue; 
 
    display: inline-block; 
 
} 
 

 
    div:hover > .details {display: block;}
<div class="kalender"> 
 
    <table *ngIf="datoer"> 
 
     <tr> 
 
      <th>Man</th> 
 
      <th>Tir</th> 
 
      <th>Ons</th> 
 
      <th>Tor</th> 
 
      <th>Fre</th> 
 
      <th>Lør</th> 
 
      <th>Søn</th> 
 
     </tr> 
 
     <tr> 
 
      <td *ngFor="let cell of ukeEn()"> 
 
       {{cell.text}} 
 
       <div class="outer" *ngIf="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngFor="let kort of datoerContains(cell).kortSkolenavn"> 
 
         {{kort}} 
 

 
         <div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngIf="datoerContains(cell).sfoFri == true" ></div> 
 

 
        </div> 
 

 
        <div class="details" *ngFor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         {{skole.skole}} <br> 
 
         {{skole.kommentar}} <br> 
 
         SFO: {{skole.sfodag}} 
 
        </div> 
 

 
       </div> 
 
      </td>    
 
     </tr> 
 
    </table>

溢出的divdetails类。这个div务必在td之内,因为如您所见,它取决于td*ngForcell,当它调用details中的datoerContains(cell)时。

所以我需要找到一种方法来保持它在页面内。想法?

+0

问题寻求帮助的代码必须包括必要的重现它最短的代码**在问题本身**最好在[**堆栈片段** ](https://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/)。请参阅[**如何创建最小,完整和可验证的示例**](http://stackoverflow.com/help/mcve) –

回答

0

除了显示与桌面位置相关的详细信息外,还可以将其显示在某个常量的位置 - 您知道哪里显示不会有任何问题。或者至少在手机上!

+0

您是否有关于如何对其进行编码的示例? – MariusJ

1

你的溢出溢出代码:visible; 你必须设置溢出:隐藏;

+0

我试过了;它没有帮助... – MariusJ

+0

尝试改变位置 –

+0

改变它为什么? – MariusJ

0

你可能需要几个不同的外部类,声明右边:0当它靠近屏幕右侧(向左打开)和底部:当它接近底线时为100%。另外,不知道它是否是错误类型的,但你在外面丢失点。如果您可以展示真实代码以获得进一步帮助,这将是一件好事

+0

你有代码示例吗? – MariusJ

+0

您需要给我们提供完整样式或URL的实例,比我们可以告诉你什么是错误的 – codexy

0

请看看这个。我相信,你就可以开始从

body { 
 
    font-family: Verdana, sans-serif; 
 
    height: 100%; 
 
} 
 

 
.kalender {height: 60vh;} 
 

 
table, td, th { 
 
    text-align: left; 
 
    border: 1px solid black; 
 
    vertical-align: text-top; 
 
    padding: 5px; 
 
    font-size: 13px; 
 
} 
 

 
table { 
 
    height: 100%; 
 
    width: 100%; 
 
} 
 

 
th { 
 
    height: 6%; 
 
    background-color: #e7e7e7; 
 
} 
 

 
td { 
 
    width: 14.28%; 
 
    height: 15.6%; 
 
    position: relative; 
 
} 
 

 
.outer { 
 
    position: absolute; 
 
    font-size: 10px; 
 
    top: 0px; 
 
    left: 0px; 
 
    
 
} 
 

 
table { 
 
    table-layout: fixed; 
 
} 
 
    .details { 
 
    background-color: gray; 
 
    display: none; 
 
    
 
    border: 2px solid black; 
 
    position: relative; 
 
    z-index: 10; 
 
    padding: 5px; 
 
    font-size: 12px; 
 
    
 
} 
 
.rdet{right: 0; left: auto;position: absolute;} 
 
.rbot{position: absolute; bottom: 0px; top: auto; } 
 
.kortNavn { 
 
    position: relative; 
 
    top: 0; 
 
    left: 0; 
 
    display: flex; 
 
    text-align: center; 
 
} 
 

 
.skoleFri { 
 
    border-radius: 50%; 
 
\t width: 8px; 
 
\t height: 8px; 
 
    background-color:red; 
 
    display: inline-block; 
 
} 
 

 
.sfoFri { 
 
    border-radius: 50%; 
 
\t width: 8px; 
 
\t height: 8px; 
 
    background-color:blue; 
 
    display: inline-block; 
 
} 
 

 
    .outer:hover > .details {display: block;}
<div class="kalender"> 
 
    <table *ngif="datoer"> 
 
     <tbody><tr> 
 
      <th>Man</th> 
 
      <th>Tir</th> 
 
      <th>Ons</th> 
 
      <th>Tor</th> 
 
      <th>Fre</th> 
 
      <th>Lør</th> 
 
      <th>Søn</th> 
 
     </tr> 
 
     <tr> 
 
      
 

 

 

 

 
    
 
    
 
    
 
    
 
    
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td><td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td><td *ngfor="let cell of ukeEn()"> 
 
7    <div class="rout outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="rdet details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 

 

 
      
 
     </tr> 
 
      <tr> 
 
      
 

 

 

 

 
    
 
    
 
    
 
    
 
    
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td><td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td><td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="rdet details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 

 

 
      
 
     </tr> 
 
      <tr> 
 
      
 

 

 

 

 
    
 
    
 
    
 
    
 
    
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="rbot details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="rbot details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 
       
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="rbot details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
    
 
       </div> 
 
      </td> 
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="rbot details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
    
 
      </td> 
 
<td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="rbot details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 
    
 

 
       </div> 
 
      </td><td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="rbot details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td><td *ngfor="let cell of ukeEn()"> 
 
7    <div class="outer" *ngif="datoerContains(cell).fulltSkolenavn != null"> 
 

 
        <div class="kortNavn" *ngfor="let kort of datoerContains(cell).kortSkolenavn"><div class="skoleFri"></div> 
 
         <div class="sfoFri" *ngif="datoerContains(cell).sfoFri == true"></div> 
 

 
        </div> 
 

 
        <div class="rdet rbot details" *ngfor="let skole of datoerContains(cell).fulltSkolenavn"> 
 
         skole skole <br> 
 
         skole kommentar <br> 
 
         SFO: skole sfodag 
 
        </div> 
 

 
       </div> 
 
      </td> 
 

 

 
      
 
     </tr> 
 
    </tbody></table> 
 
</div>

+0

谢谢!我试图做类似的事情,但似乎无法正常工作。在个人电脑上,它只是扩大高度,如果页面适合它,我不想发生。在移动设备上,这个问题根本就没有解决...... 你的例子和我的类似,但是“外部”类应该围绕“细节”类。 我已经扩展了问题中的代码以获得进一步的建议。 – MariusJ

+0

看看编辑的代码。剩下的只是可能会声明它应该以bottom打开:0;当底部没有空间时 – codexy

+0

显然,我们正在接近。但我不喜欢这个词,是否有可能让div向左重叠它的div(s)到右侧,div的右侧重叠它的div(s)向右? 另外,当我使用bottom:0时,如果隐藏div非常高,我会遇到红色和蓝色点移动到隐藏div顶端的问题。 – MariusJ