javascript - 格式问题

标签 javascript html css

我目前正在尝试练习如何将我的网页居中。目前,我正在使用表中的表来分解我的网站,但我希望页面的前 1/3 穿过整个页面,而其余 2/3 留在中间。谢谢你的帮助! (见下面的代码)

            <!DOCTYPE html>
            <html>
                <head>
                    <title>R.P.E Limited</title>
                        <style>
                                .container {
                                  float: center
                                }

                                .left {
                                  float:left;
                                }

                                .right {
                                  float:right;
                                }

                                html, body{
                               height: 100%;
                               min-height: 100%;
                                }


                                .top {
                                height: 10%;
                                }

                                .mid {
                                height: 45%;
                                }

                                .bot {
                                height: 45%;
                                }

                                body {
                                width:90%;
                                }
                        </style>
                </head>
                    <body>
                        <table height="100%" width=250%>
                          <tr>                                                      <!--Webpage start-->                            
                            <td>                                                    <!--LEAVE BLANK-->
                            </td>
                                <td>                                                <!--All code goes in here-->
                                    <table height="100%" width=100%>


                                        <td class="left" width=20%>                 <!--Left blank-->
                                        </td>



                                        <td class="container" width=60%>

                                            <table class="top" height="100%">       <!--THE PAGE STARTS HERE-->
                                                <tr><td>Top</td></tr>               <!--TOP-->
                                            </table>

                                            <table class="mid" height="100%">
                                                <tr><td>Mid</td></tr>               <!--MID-->
                                            </table>

                                            <table class="bot" height="100%">
                                                <tr><td>Bot</td></tr>               <!--BOTTOM-->
                                            </table>
                                        </td>




                                        <td class="right" width=20%>                <!--Right blank-->
                                        </td>

                                    </table>
                                </td>                                               <!--All code ends here-->
                            <td>                                                    <!--LEAVE BLANK-->
                            </td>
                          </tr>
                        </table>                                                    <!--Webpage end-->
                    </body>
            </html>

最佳答案

正如人们提到的那样使用样式是正确的方法。表格不应用于纯粹的布局目的。

这基本上应该是您正在寻找的内容:

<style>

.maincanvas {
  margin:0px auto;
  width: 600px
}

</style>


<div class="maincanvas">

   <p>This container will be centered with a width of 600px</p>

</div>

关于javascript - 格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33620384/

相关文章:

javascript - 如何在没有 iframe 的情况下渲染要放置在第三方网页的 div 内的 HTML 文本?

html - Bootstrap 将按钮对齐到 flexbox 列的底部

javascript - 使用 JavaScript 获取元素的所有 CSS 样式

javascript - Sinon Stub 单元测试

javascript - jQuery 动画 scrollTop 问题

html - 我找不到将文本移动到 DIV 中间的方法

javascript - 在 IE 中使用表格创建 pdf 时出现问题

Javascript 图像悬停缩放弹出窗口

javascript - 对 2 个对象使用键盘输入

html - 将文本垂直对齐到行内 block 的中间