[英]CSS table cell not filling 100% of the screen width
I have the following:我有以下内容:
<div class="xx-row">
<div class="background-image" style="background-image: url('<?php echo theme('background_image', 'url'); ?>');">
<div class="yy-column">
</div>
</div>
</div>
.xx-row {
display: table;
}
.yy-column {
display: table-cell;
}
When viewing the page in full screen, for some reason the columns do not fill the width of the page.全屏查看页面时,由于某种原因,列没有填满页面的宽度。 If I manually set the width it works but I don't want to do this.
如果我手动设置宽度,它可以工作,但我不想这样做。 Setting the width to the 100% doesn't have any effect.
将宽度设置为 100% 没有任何效果。
This is how I'd like it to look:这就是我希望它的样子:
Inspecting element, parent div looks OK and xx-row looks OK too, the background image after the xx-row also looks fine and stretches the screen.检查元素,父 div 看起来不错,xx-row 看起来也不错,xx-row 之后的背景图像也看起来不错并拉伸了屏幕。 So it's the columns that are the issue, if I set it to 100% that fills up the screen but the left column takes up about 80% of the screen.
所以问题出在列上,如果我将其设置为 100% 填满屏幕,但左列占据屏幕的 80% 左右。
It might be some problems with width of some parent element of your .row
. .row
的某些父元素的宽度可能存在一些问题。 Inspect all parent elements, I think - you will find the guilty one.我认为检查所有父元素 - 你会找到有罪的。 Although inspect
.column
and .row
classes in console, maybe there are some other css frameworks that can affect it (the .column
and .row
names are vary common, uses in Bootstrap etc.).尽管在控制台中检查
.column
和.row
类,但可能还有其他一些 css 框架会影响它( .column
和.row
名称很常见,用于 Bootstrap 等)。 Don't forget to add width: 100%;
不要忘记添加
width: 100%;
to your table
element.到您的
table
元素。
UPDATED更新
The main mistake was the .column
's direct parent was not .row
, but .background-image
.主要错误是
.column
的直接父级不是.row
,而是.background-image
。 Rewrited the code according to right display: table
and display: table-cell
, the elements should be direct relatives.根据正确的
display: table
和display: table-cell
重写了代码,元素应该是直系亲属。
* { box-sizing: border-box; } html { height: 100%; } body { height: 100%; margin: 0; padding: 0; }.xx-row { display: block; width: 100%; height: 100%; }.background-image { display: table; width: 100%; height: 100%; }.yy-column { display: table-cell; }.one { background: #333; }.two { background: #000; }
<div class="xx-row"> <div class="background-image" style="background-image: url('<?php echo theme('background_image', 'url'); ?>');"> <div class="yy-column one"> </div> <div class="yy-column two"> </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.