简体   繁体   English

如何使用引导程序或 css 水平内联

[英]how to horizontally inline from using bootstrap or css

I have read many questions and many articles but cant find my answer Here is my code result我已经阅读了很多问题和很多文章,但找不到我的答案这是我的代码结果在此处输入图像描述

Here is my code这是我的代码

 .checkout-cart-total { background-color: #f5f5f5; padding: 45px; } @media only screen and (max-width: 575px) {.checkout-cart-total { padding: 30px; } }.checkout-cart-total h4 { flex-basis: 18px; line-height: 23px; font-weight: 600; color: #292929; }.checkout-cart-total h4:first-child { margin-top: 0; margin-bottom: 25px; }.checkout-cart-total h4:last-child { margin-top: 15px; margin-bottom: 0; }.checkout-cart-total h4 span { float: right; display: block; }.checkout-cart-total ul { border-bottom: 1px solid #292929; }.checkout-cart-total ul li { color: #292929; font-size: 14px; line-height: 23px; font-weight: 600; display: block; margin-bottom: 16px; }.checkout-cart-total ul li span { color: #292929; float: right; }.checkout-cart-total p { line-height: 30px; font-weight: 600; color: #292929; padding: 10px 0; border-bottom: 1px solid #292929; margin: 0; }.checkout-cart-total p span { float: right; }
 <div class="col-12 mb-60"> <h4 class="checkout-title">Cart Total</h4> <div class="checkout-cart-total"> <h4>Product <span>Total</span></h4> <ul> <?php $cartres = $fetchcart->fetchAll(PDO::FETCH_ASSOC); foreach($cartres as $row){?> <li> <input type="text" disabled value="<?php echo $row['p_name']; ?>" name="product_name[]" style="color:#292929;font-size:14px;font-weight:600;display:inline;float:left;border:none;background:transparent;"> X <input type="text" disabled value="<?php echo $row['qty']; ?>" name="qty[]" style="color:#292929;font-size:14px;font-weight:600;display:inline;float:left;border:none;background:transparent;"> <span><input type="text" disabled value="<?php echo $row['price']; ?>" name="product_name[]" style="color:#292929;font-size:14px;font-weight:600;float:left;display:inline;border:none;background:transparent;"><input type="text" disabled value="<?php echo $row['p_id']; ?>" hidden name="product_id[]" style="color:#292929;font-size:14px;font-weight:600;float:left;display:inline;border:none;background:transparent;"></span> </li> <?php }?> </ul> </div> </div>

Help me to figure out how to align this I have done many techniques like the form-inline bootstrap class but doesn't work for me.帮助我弄清楚如何对齐这个我已经完成了许多技术,例如表单内联引导 class 但对我不起作用。 Because I am submitting two data at a time so I cant use form-inline class first form is for user details and second for product details and checkout at a time.因为我一次提交两个数据,所以我不能使用表格内联 class 第一个表格用于用户详细信息,第二个用于产品详细信息和结帐。

The best design can be achieved using tables.使用表格可以实现最佳设计。 This is what tables are used for - representation of data.这就是表格的用途——数据的表示。 You can also use <input type="number"> for quantity and update total price accordingly.您还可以使用<input type="number">作为数量并相应地更新总价。

DOCS: https://getbootstrap.com/docs/4.5/content/tables/文档:https://getbootstrap.com/docs/4.5/content/tables/

 /*DEMO*/body{padding:2rem}input[type="number"]{max-width:75px} tbody th,tbody td{vertical-align:middle!important}
 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"> <div class="row"> <div class="col-12"> <h4>Cart Total</h4> <table class="table table-striped table-hover"> <thead class="thead-dark"> <tr> <th scope="col">#</th> <th scope="col">Product</th> <th scope="col">Price</th> <th scope="col">Quantity</th> <th scope="col">Total</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Lorem Ipsum</td> <td>1400</td> <td><input class="form-control form-control-sm" type="number" value="1"></td> <td>1400</td> </tr> <tr> <th scope="row">2</th> <td>Dolor Sit Amet</td> <td>425</td> <td><input class="form-control form-control-sm" type="number" value="2"></td> <td>850</td> </tr> <tr> <th scope="row">3</th> <td>Lorem Lorem</td> <td>850</td> <td><input class="form-control form-control-sm" type="number" value="1"></td> <td>850</td> </tr> </tbody> </table> </div> </div>

I think its better to use Table layout or Display Flex or Grid layout.我认为最好使用 Table 布局或 Display Flex 或 Grid 布局。

All the theories below are from w3school ,以下所有理论均来自w3school

Table Layout: 表格布局:

The table-layout property defines the algorithm used to lay out table cells, rows, and columns. table-layout 属性定义了用于布局表格单元格、行和列的算法。

The main benefit of table-layout: fixed;表格布局的主要好处:固定; is that the table renders much faster.是表格呈现得更快。 On large tables, users will not see any part of the table until the browser has rendered the whole table.在大表上,在浏览器渲染整个表之前,用户将看不到表的任何部分。 So, if you use table-layout: fixed, users will see the top of the table while the browser loads and renders rest of the table.因此,如果您使用 table-layout: fixed,用户将在浏览器加载并呈现表格的 rest 时看到表格的顶部。 This gives the impression that the page loads a lot quicker!这给人的印象是页面加载速度更快!

Display Flex: Click here显示弹性:点击这里

HTML: HTML:

<div> // display:flex, flex-direction:column, justify-content:space-around

<div> // display:flex, flex-direction:row, justify-content:space-around
 <div> </div>
<div> </div>
</div>

<div> // display:flex, flex-direction:row, justify-content:space-around
 <div> </div>
<div> </div>
</div>

</div>

Grid Layout: Link here网格布局:链接在这里

The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning. CSS 网格布局模块提供基于网格的布局系统,具有行和列,可以更轻松地设计 web 页面,而无需使用浮动和定位。

My choice: There are always different approaches to do a thing, but in the situation, you mention I would prefer to go with display: flex method.我的选择:做一件事总是有不同的方法,但在这种情况下,你提到我更喜欢 go 与display: flex方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM