【问题标题】:How to arrange web page layout with bootstrap?如何使用引导程序安排网页布局?
【发布时间】:2018-09-25 02:10:01
【问题描述】:

我正在使用引导框架在我的系统上进行布局。我想这样安排页面的布局(见下图

但我面临着挑战。我的代码显示了这一点(见下图) 我需要将登录论坛部分转到右侧,就像我上传的第一张图片一样。

这是我的代码

<?php if($topics) : ?>
    <p id="topics">
        <div class="row">
        <?php foreach ($topics as $topic) : ?>
            <p class="topic">
         <div class="row">
            <div class="col">
          </div> 

        <div class="col-md-5">
                <div class="topic-content pull-right">
                    <h3><a href="topic.php?id=<?php echo $topic['id']; ?>"><?php echo $topic['title']; ?></a></h3>
                    <div class="topic-info">
                        <a href="topics.php?category=<?php echo urlFormat($topic['category_id']); ?>"><?php echo $topic['name']; ?></a> >> 
                        <a href="topics.php?user=<?php echo urlFormat($topic['user_id']); ?>"><?php echo $topic['username']; ?></a> >>
                        Posted on: <?php echo formatDate($topic['create_date']); ?>
                    <span class="badge pull-right"><?php echo replyCount($topic['id']); ?></span>
                    </div>
                </div>    
            </div>
        </div>

            </p>
    <?php endforeach; ?>
    </p>
<?php else : ?>
    <p>No Topics to Display.</p>
<?php endif; ?>
<div class="col-md-4" align="pull-right">
                <div class="sidebar">
                    <div class="block">
                        <h3>Login Form</h3>
                        <?php if(isLoggedIn()) : ?>
                            <div class="userdata">
                                Logged in as <?php echo getUser()['username']; ?>
                            </div>
                            <br />
                            <form role="form" method="post" action="logout.php">
                                <input type="submit" name="do_logout" class="btn btn-default" value="Log Out" />
                                <hr>
                                 <h4><a href="/prac/forum">All Topics</a></h4>
                                <h4><a href="create.php">Create Topic</a></h4>

                            </form>
                        <?php else : ?>
                            <form role="form" method="post" action="login.php">
                                <div class="form-group">
                                    <label>Username</label>
                                    <input name="username" type="text" class="form-control" placeholder="Enter Username" />
                                </div>
                                <div class="form-group">
                                    <label>Password</label>
                                    <input name="password" type="password" class="form-control" placeholder="password" />
                                </div>
                                <button name="do_login" type="submit" class="btn btn-primary">Login</button> <a class="btn btn-default" href="register.php">Create Account</a>
                            </form>
                        <?php endif; ?>
                    </div>
                    <div class="block">
                        <h3>Categories</h3>
                        <div class="list-group">
                            <a href="topics.php" class="list-group-item <?php echo is_active(null); ?>">All topics <span class="badge pull-right"><?php echo totalPostCount() ;?></span></a>
                            <?php foreach(getCategories() as $category) : ?>
                                <a href="topics.php?category=<?php echo $category['id']; ?>" class="list-group-item <?php echo is_active($category['id']); ?>">
                                    <?php echo $category['name']; ?>
                                    <span class="badge pull-right">
                                        <?php echo postCountByCategory($category['id']) ;?>
                                    </span>
                            </a>
                            <?php endforeach; ?>
                        </div>
                        
                    </div>
                    
                </div>
            </div>
    
</div>
<hr>

<h3>Forum Statistics</h3>

<p>
    <h6>Total Number of Users: <strong><?php echo $totalUsers; ?></strong></li>
    <h6>Total Number of Topics: <strong><?php echo $totalTopics; ?></strong></li>
    <h6>Total Number of Categories: <strong><?php echo $totalCategories; ?></strong></li>
</ul>

【问题讨论】:

  • pull-right 不是 align 属性的有效值。您是想将其添加到课程列表中吗?
  • 使用正确的应答器,如&lt;section&gt;&lt;/section&gt;&lt;div&gt;&lt;div/&gt; 作为主要元素(不是&lt;p&gt;&lt;/p&gt;,它仅用于段落),无需使用&lt;br&gt; 进入下一行:HTML带有display:block; 的元素会将所有车道视为正常行为。并阅读一些引导教程以了解网格的工作原理:)
  • 是的,请看我附上的图片
  • @Rayobeats 看起来您正在学习并尝试复制下面的页面,如果您只是复制/粘贴代码,您将学到什么?尝试使用逻辑逐步完成:我可以看到多少块? (页眉?页脚?侧边菜单?多少部分?..)我的元素如何在响应式上工作?使我的元素变为蓝色和下划线的 css 属性是什么?粗体字?等等

标签: php html css twitter-bootstrap


【解决方案1】:

在其他&lt;p&gt; 标签中似乎有很多不必要的rows&lt;p&gt; 标签。老实说,它需要重组。最佳做法是不要将 divs 包装在 &lt;p&gt; 标记中,因为它们不应该真正用作包装器。

您想将 2 列分成 2 个单独的 Bootstrap cols,它们应该被包裹在 row 类中。

例如:

<div class="row">
    <div class="col-xs-12 col-sm-8">
        <p>All your forum info here etc.</p>
    </div>
    <div class="col-xs-12 col-sm-4">
        *Login Form Here*
        *Categories Here*
    </div>
</div>

上面的列将它们分成 66.66666667% x 33.33333333% 宽度的列在桌面上,然后在较小的设备上都是全宽 (100%)。

【讨论】:

    【解决方案2】:

    您可以简单地使用引导网格 Grid 系统来完成这项任务。请通过此链接查看官方文档... https://getbootstrap.com/docs/4.1/layout/grid/

    但是,我创建了一个我认为符合您要求的示例布局。

    <html>
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="">
        <link rel="icon" href="../../../../favicon.ico">
    
        <title>sample web page</title>
    
        <!-- Bootstrap core CSS -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
        <style type="text/css">
          .left-block{
            width:100%;
            height:500px;
            padding: 20px;
    
          }
          .right-block{
            width:100%;
            padding: 20px;
            height:500px;
            background-color: #D3D3D3;
          }
        </style>
        
     </head>
     <body>
      <div class="container-fluid">
        <div class="row">
         <div class="col-lg-8">
            <div class="left-block">
              <h1>sample content</h1>
              <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ullamcorper nisl ut sodales tincidunt. Praesent tristique lobortis tincidunt. Cras aliquet, lectus ut facilisis tempor, nulla felis porta sem, quis pulvinar lacus justo eget sapien. Integer dapibus bibendum sodales. Sed semper sagittis ex, et suscipit odio luctus vel. Fusce laoreet a sapien vitae mattis. Quisque ligula massa, sagittis vel odio vel, hendrerit iaculis leo. Aliquam erat volutpat. Fusce mollis, augue vel egestas tristique, nunc ligula placerat erat, sed venenatis elit ex et nulla. </p>
            </div>
         </div>
         <div class="col-lg-4">
           <div class="right-block">
             <h2>Login Section</h2>
                <hr>
                <form>
                    <div class="form-group">
                        <label for="exampleInputEmail1">Email address</label>
                        <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
                         <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
                    </div>
                    <div class="form-group">
                       <label for="exampleInputPassword1">Password</label>
                        <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
                    </div>
                    <div class="form-check">
                       <input type="checkbox" class="form-check-input" id="exampleCheck1">
                       <label class="form-check-label" for="exampleCheck1">Check me out</label>
                    </div>
                    <button type="submit" class="btn btn-primary">Submit</button>
                  </form>
           </div>
         </div>
       </div>
      </div>
       
     </body>
    </html>

    还有什么问题,欢迎在下方留言...

    【讨论】:

      【解决方案3】:

      不要将结构 div 放在 &lt;p&gt; 标记内!试试这个:

      <div class="container">
          <div class="row">
              <div class="col-md-4">
                  This is one third of the page wide (4/12)
              </div>
              <div class="col-md-8">
                  This is two thirds of the page wide (8/12)
              </div>
          </div>
      </div>
      

      【讨论】:

        【解决方案4】:
        <div class="col-md-12">
         <div class="row">
          <div class="col-md-8">
             <p> this is where 'normalization' text should go </p>
          </div>
          <div class="col-md-4">
             <p> this is where the form goes </p>
          </div>
         </div>
        </div>
        

        试试上面的代码。这是基本引导网格布局的示例。第一个将页面定义为“12”——其中的剩余 div 也必须加起来为 12,此示例为 8 + 4(2 列),但也可以有 3 个 4+4+4 等等。

        【讨论】:

          【解决方案5】:

          你可以使用下面的例子来用Bootstrap安排网页布局:

          <div class="col-md-12">
             <div class="row">
           <div class="col-md-8">
           <p> Your Left area put here  </p>
           </div>
          <div class="col-md-4">
            <p> Your right area Put here </p>
           </div>
           </div>
           </div
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2020-04-10
            • 2016-02-26
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2022-12-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多