html - 一个平行 div 中的 CSS 表格

标签 html css layout position css-tables

在一个网页上,我有一个容器 div,里面有两个相邻的 div。在第一个内部 div 中,我尝试设置一个 CSS 表格,其中有 4 列均匀填充 div。

我遇到的问题是单元格的宽度似乎是相对于页面宽度的,而不是表格/它的父 div。如果我将宽度从 25% 减小到更低,它会适合,但如果我缩放页面,它们仍然会换行,因为右边的 div 会碰到最右边的表格单元格。

我应该如何设置布局以将它们保留在 div 中?

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <style type="text/css">
            html,body, div {
                display: block;
                height: 100%;
                width: 100%;    
            }

            #container {
                position: absolute;
                height: 300px;
                width: 100%;
            }
            .sideBySide {
                position: absolute;
                float: left;
                height: 100%;
            }

            #galleria {
                background-color:#0C0;
                left: 0px;
                right: 300px;
                width: auto;
            }

            #tagit {
                background-color: #099;
                right: 0px;
                width: 300px;
            }

            #table {
                position: absolute;
                margin: 0px;
                padding: 0px;
                display: table;
                height: 100%;
                width: 100%;
            }

            .table-row {
                position: relative;
                margin: 0px;
                padding: 0px;
                display: table-row;
                width: 100%;
                height: 25%;
            }

            .table-cell {
                position: relative;
                margin: 0px;
                padding: 0px;
                display: table-cell;
                float: left;
                height: 100%;
                width: 25%;

                padding: 20px;
            }

            .kuva {
                position: relative;
                margin: 0px;
                padding: 0px;
                width: 100%;
                height: 100%;

                background-color: #999;
            }

        </style>
    </head>

    <body>
        <div id="container">
            <div id="galleria" class="sideBySide">
                <div id="table">
                    <div class="table-row">
                        <div class="table-cell">
                            <div class="kuva">Cell1</div>
                        </div>
                        <div class="table-cell">
                            <div class="kuva">Cell2</div>
                        </div>
                        <div class="table-cell">
                            <div class="kuva">Cell3</div>
                        </div>
                        <div class="table-cell">
                            <div class="kuva">Cell4</div>                       
                        </div>
                    </div>
                </div>
             </div>
        </div>
    </body>
</html>

最佳答案

移除

float: left;

来自

.table-cell

关于html - 一个平行 div 中的 CSS 表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17776554/

相关文章:

html - CSS中的背景颜色可以设置为 'erase'吗?

PHP - MYSQL 不插入多行

html - 编辑按钮的背景颜色(事件链接)

html - 如何将 div 定位为与另一个 div 齐平?

javascript - 使用 iphone dev 将 HTML 字符串转换为普通文本

javascript - 使用 jQuery 隐藏父 div

javascript - 如何获得滚动和封面效果?

html - Joomla 中的背景图片

iphone - -sizeWithFont 在设备上的功能不同

android - 为 seekbar/progressbar Android 使用可缩放位图