如何使用 Bootstrap “行"转换基于表格的布局和“col-*-*" [英] How to convert table based layout with Bootstrap "row" and "col-*-*"

查看:21
本文介绍了如何使用 Bootstrap “行"转换基于表格的布局和“col-*-*"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在基于表格布局(无 div)的网站上工作.现在需求发生变化,必须重新创建以使其看起来响应式,对于响应式,我们选择引导程序作为选项.

现在,我如何将表格布局转换为引导网格布局,以便 1. 外观不变,2. 也具有响应性.

站点中的表格布局过于复杂.有很多嵌套.例如:

<tr style='padding-bottom:1em;'><td><表格边框=0"><tr valign='bottom'><td width='50'>&nbsp;</td><td><img border="0" src="#" width="100" height="300"></td><td width='25'>&nbsp;</td><td><span style='font-size:10px;color:#cccccc;'>Alpha 测试</span></td></tr>
</td><td align='right'><table border="0" cellspacing="0"><tr><td align='center' colspan='3'><span>另一个测试文本</span><span style='color:#FFFFC;'>- </span><span style='font-size:11px;color:#fffff;'>随机文本</span></td></tr></td></tr>

例如,我如何使用 bootstrap rowcol-*-* 网格布局转换上述代码.

相信我,我尝试了很多来转换它,但有时看起来会改变,或者有时根本不起作用.

也欢迎关于如何将 table base layout 转换为 bootstrap 的一般建议.

解决方案

这里有一些很棒的文献:Bootstrap 3 网格系统

  • div class="container"
  • 替换 table 和 tbody
  • div class="row"
  • 替换 tr
  • div class="col-ww-nn" 替换 td
    • 其中ww 是设备宽度(xssmmdlg>)
    • 其中 nn 是 1-12 的数字,表示宽度百分比(除以 12)

以下是您更新后的代码(也包括一些语法修复).请注意,我添加了响应能力,因此在手机(xs 设备)上,您的第二个主列将是单独的一行.您可以使用 img-response 使图像具有响应性,以便其大小随设备而变化.

<div class="row"><div class="col-xs-12 col-sm-6"><div class="row"><div class="col-xs-4 col-sm-4">&nbsp;

<div class="col-xs-4 col-sm-4"><img src="#" class="img-responsive">

<div class="col-xs-4 col-sm-4">&nbsp;

<div class="col-xs-4 col-sm-4"><span style="font-size:10px;color:#cccccc;">Alpha 测试</span>

<div class="col-xs-12 col-sm-6"><div class="row"><div class="col-xs-4 col-sm-4"><span>另一个测试文本</span>

<div class="col-xs-4 col-sm-4"><span style="color:#ffffcc;">- </span>

<div class="col-xs-4 col-sm-4"><span style="font-size:11px;color:#ffffff;">随机文本</span>

I am working on site which is based on table-layout (no div). Now requirement change and has to re-create so that it look responsive, and for responsive we choose bootstrap as option.

Now, How can I convert tables layout into bootstrap grid layout so can 1. look not change, 2. have responsive also.

table-layout is too complex in site. lots of nesting is there. For example:

<table border="0" width='100%' bgcolor='#ff00ff'>
<tr style='padding-bottom:1em;'>
<td>
    <table border="0">
        <tr valign='bottom'>
            <td width='50'>&nbsp;</td>
            <td>
                <img border="0" src="#" width="100" height="300">
            </td>
            <td width='25'>&nbsp;</td>
            <td>
                <span style='font-size:10px;color:#cccccc;'>Alpha testing</span>
            </td>
        </tr>
    </table>
</td>
<td align='right'>
    <table border="0" cellspacing="0">
        <tr>
            <td align='center' colspan='3'>
                <span>Another tesing text</span>
                <span style='color:#FFFFCC;'> - </span>
                <span style='font-size:11px;color:#fffff;'>Random text</span>
            </td>
        </tr>
    </table>
</td>
</tr>

For example how can I convert above code with bootstrap row, col-*-* grid-layout.

Trust me, I tried a lot to convert this, but sometime looks change or some time just not work at all.

General suggestion on how to convert table base layout into bootstrap are also welcome.

解决方案

Here is some great literature: Bootstrap 3 Grid system

Below is your updated code (including some syntax fixes too). Note, I've added responsiveness so that on phones (xs devices) your second main column would be a separate line. And you can make images responsive with img-response so that it's size changes with the device.

<div class="container" style="background-color:#ff00ff">
    <div class="row">
        <div class="col-xs-12 col-sm-6">
            <div class="row">
                <div class="col-xs-4 col-sm-4">
                    &nbsp;
                </div>
                <div class="col-xs-4 col-sm-4">
                    <img src="#" class="img-responsive">
                </div>
                <div class="col-xs-4 col-sm-4">
                    &nbsp;
                </div>
                <div class="col-xs-4 col-sm-4">
                    <span style="font-size:10px;color:#cccccc;">Alpha testing</span>
                </div>
            </div>
        </div>
        <div class="col-xs-12 col-sm-6">
            <div class="row">
                <div class="col-xs-4 col-sm-4">
                    <span>Another tesing text</span>
                </div>
                <div class="col-xs-4 col-sm-4">
                    <span style="color:#ffffcc;"> - </span>
                </div>
                <div class="col-xs-4 col-sm-4">
                    <span style="font-size:11px;color:#ffffff;">Random text</span>
                </div>
            </div>
        </div>
    </div>
</div>

这篇关于如何使用 Bootstrap “行"转换基于表格的布局和“col-*-*"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆