首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么我的HTML div会覆盖整个屏幕?

为什么我的HTML div会覆盖整个屏幕?
EN

Stack Overflow用户
提问于 2019-02-27 17:00:52
回答 3查看 196关注 0票数 3

我已经在一个项目上工作了几天,我总是遇到这个问题。我有一个包含数据的表,我希望两边的填充都是30px,并且“.task-link”或“header-6”随着窗口展开。取而代之的是,div的宽度覆盖了整个屏幕,它看起来并不均匀,这简直要了我的命。对不起,我是HTML的新手,所以请放我一马,我相信这是显而易见的,我尝试了很多不同的方法都没有成功,我不明白为什么它应该覆盖整个屏幕。不管怎样,下面是我的代码:

代码语言:javascript
运行
复制
    main {
        background-color: #c9c9c9;
    }
    
    body, html {
        margin: 0px;
        padding: 0px;
    }
    
    #tablediv {
        padding-left: 30px;
        padding-right: 30px;
        padding-bottom: 0px;
    }
    
    table {
        border-collapse: collapse;
        white-space: nowrap;
        /* width:100%; */
        table-layout: fixed;
    }
    
    table tr th{
        white-space: nowrap;
        border: 1px solid white;
        text-align: center;
        text-transform: uppercase;
        color: #fff;
        font-size: 17px;
    }
    
    table tr td {
        text-align: center;
        text-transform: uppercase;
        color: white;
    }
    
    table tr td.shrink,
    table tr th.shrink {
        white-space: nowrap;
    }
    
    
    table tr td.expand,
    table tr th.expand {
        word-wrap: break-word;
        width: 20%;
    }
    .task-link {
        overflow: hidden;
        padding: 0 0%;
        width: 0;
    }
代码语言:javascript
运行
复制
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
        <link rel="stylesheet" href="main.css">
        <script src="main.js"></script>
    </head>
    <body>
            <!-- <div id="sidebar" class="flex col-sm-4">
                    <a href="tasks.html">
                        <i class="fas fa-tasks"></i><br>Tasks
                    </a>
                    <a href="profiles.html">
                        <i class="fas fa-user-circle"></i><br>Profiles
                    </a>
                    <a href="#">
                        <i class="fas fa-mask"></i><br>Proxies
                    </a>
                    <a href="#">
                        <i class="fas fa-cogs"></i><br>Settings
                    </a>
                    <a href="#">
                        <i class="fas fa-check-circle"></i><br>Captcha
                    </a>
                </div> -->
        <main class="page-content">
            <div id="tablediv">
                
                <table id="table" class="col-sm-8">
                        <tr id="headers">
                            <th class="task-num shrink">1</th>
                            <th class="task-status shrink">Header 2</th>
                            <th class="task-platform shrink">Header 3</th>
                            <th class="task-type shrink">Header 4</th>
                            <th class="task-keyword shrink">Header 5</th>
                            <th class="task-link expand">Header 6</th>
                            <th class="task-profile shrink">Header 7</th>
                            <th class="task-proxy shrink">Header 8</th>
                        </tr>
                        <tr id="${temp}" class="profiletr" tabindex="0">
                            <td class="task-num shrink">1</td>
                            <td class="task-status shrink">2</td>
                            <td class="task-platform shrink">3</td>
                            <td class="task-type shrink">4</td>
                            <td class="task-keyword shrink">5</td>
                            <td class="task-link expand">longtextlongtextlongtext</td>
                            <td class="task-profile shrink">6</td>
                            <td class="task-proxy shrink">7</td>
                        </tr>
                    </table>
                </div>
            </main>
    </body>

这是一个正在发生的事情的例子,以及我希望它看起来是什么样子。现在:https://gyazo.com/00870da7fa1d8642dde8814ab4bd3bac

我想要的:https://gyazo.com/8c5a48ceb6a4e2470dbf10c686992fbc

表格一直走到另一边,每一面都有30px的填充,标题6会扩展以匹配屏幕的扩展,当它变小时,我只想让标题6变小。

EN

回答 3

Stack Overflow用户

发布于 2019-02-27 17:41:22

可以使用bootstrap响应表。在这里,.table响应类创建了一个响应表,它将在小型设备(低于768px)上水平滚动,并且当查看任何超过768px宽的设备时,它将使用整个屏幕宽度显示该表。

代码语言:javascript
运行
复制
    <!DOCTYPE html>
        <html>
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>Title</title>
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
        </head>
        <body>
            <div class="container">
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>1</th>
                                <th>Header 2</th>
                                <th>Header 3</th>
                                <th>Header 4</th>
                                <th>Header 5</th>
                                <th>Header 6</th>
                                <th>Header 7</th>
                                <th>Header 8</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>1</td>
                                <td>2</td>
                                <td>3</td>
                                <td>4</td>
                                <td>5</td>
                                <td>longtextlongtextlongtext</td>
                                <td>6</td>
                                <td>7</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </body>
        </html>

票数 2
EN

Stack Overflow用户

发布于 2019-02-27 17:20:48

删除col-sm-8并签出引导网格

https://getbootstrap.com/docs/4.0/layout/grid/

票数 1
EN

Stack Overflow用户

发布于 2019-02-27 17:31:31

bootstrap网格必须始终在一行内,而且网格要有12列。

例如:

代码语言:javascript
运行
复制
<div class="row">
<div class="col-md-4></div>
<div class="col-md-4></div>
<div class="col-md-4></div>
</div>

这将产生3个具有相同宽度的相同列

代码片段:

代码语言:javascript
运行
复制
    main {
        background-color: #c9c9c9;
    }
    
    body, html {
        margin: 0px;
        padding: 0px;
    }
    
    #tablediv {
        padding-left: 30px;
        padding-right: 30px;
        padding-bottom: 0px;
    }
    
    table {
        border-collapse: collapse;
        white-space: nowrap;
        /* width:100%; */
        table-layout: fixed;
    }
    
    table tr th{
        white-space: nowrap;
        border: 1px solid white;
        text-align: center;
        text-transform: uppercase;
        color: #fff;
        font-size: 17px;
    }
    
    table tr td {
        text-align: center;
        text-transform: uppercase;
        color: white;
    }
    
    table tr td.shrink,
    table tr th.shrink {
        white-space: nowrap;
    }
    
    
    table tr td.expand,
    table tr th.expand {
        word-wrap: break-word;
        width: 20%;
    }
    .task-link {
        overflow: hidden;
        padding: 0 0%;
        width: 0;
    }
代码语言:javascript
运行
复制
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
        <link rel="stylesheet" href="main.css">
        <script src="main.js"></script>
    </head>
    <body>
            <!-- <div id="sidebar" class="flex col-sm-4">
                    <a href="tasks.html">
                        <i class="fas fa-tasks"></i><br>Tasks
                    </a>
                    <a href="profiles.html">
                        <i class="fas fa-user-circle"></i><br>Profiles
                    </a>
                    <a href="#">
                        <i class="fas fa-mask"></i><br>Proxies
                    </a>
                    <a href="#">
                        <i class="fas fa-cogs"></i><br>Settings
                    </a>
                    <a href="#">
                        <i class="fas fa-check-circle"></i><br>Captcha
                    </a>
                </div> -->
        <main class="page-content">
            <div class="row" id="tablediv">
            <div class="col-sm-2"></div>

            <div class="col-sm-8">
                <table id="table" class="col-sm-8">
                        <tr id="headers">
                            <th class="task-num shrink">1</th>
                            <th class="task-status shrink">Header 2</th>
                            <th class="task-platform shrink">Header 3</th>
                            <th class="task-type shrink">Header 4</th>
                            <th class="task-keyword shrink">Header 5</th>
                            <th class="task-link expand">Header 6</th>
                            <th class="task-profile shrink">Header 7</th>
                            <th class="task-proxy shrink">Header 8</th>
                        </tr>
                        <tr id="${temp}" class="profiletr" tabindex="0">
                            <td class="task-num shrink">1</td>
                            <td class="task-status shrink">2</td>
                            <td class="task-platform shrink">3</td>
                            <td class="task-type shrink">4</td>
                            <td class="task-keyword shrink">5</td>
                            <td class="task-link expand">longtextlongtextlongtext</td>
                            <td class="task-profile shrink">6</td>
                            <td class="task-proxy shrink">7</td>
                        </tr>
                    </table>
                </div>
            <div class="col-sm-2"></div>
                </div>
            </main>
    </body>

正如您所看到的,这会在屏幕的两侧生成一个空白点。此外,https://getbootstrap.com/docs/4.0/layout/grid/还提供了很多信息,请务必查看。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54901570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档