【问题标题】:Create a table using only CSS仅使用 CSS 创建表
【发布时间】:2014-04-06 02:32:28
【问题描述】:

我需要一个如下所示的表格布局:

单元格一(行跨度 2)

单元格二和三(在单元格一和彼此旁边)

第四单元格(第二单元格和第三单元格下方的 colspan 2)

我遇到的问题是它只需要使用 CSS 来完成,我根本不能在代码中使用任何表格元素。

如果单元格 2、3 和 4 为空,则单元格 1 还需要拉伸到 100% 的宽度。

我正在 Joomla 中开发 Artisteer 4 模板,并且已经搜索了所有内容,但无法找到可行的解决方案。

我的代码如下:

<div class="prof-layout-wrapper">
   <div class="prof-content-layout">
      <div class="prof-content-layout-row">
         <div class="prof-layout-cell prof-content">
<?php
 echo $view->position('banner2', 'prof-nostyle');
 if ($view->containsModules('breadcrumb'))
 echo artxPost($view->position('breadcrumb'));
 echo $view->positions(array('user1' => 50, 'user2' => 50), 'prof-article');
 echo $view->position('banner3', 'prof-nostyle');
 echo artxPost(array('content' => '<jdoc:include type="message" />', 'classes' => ' prof-m  essages'));
 echo '<jdoc:include type="component" />';
 echo $view->position('banner4', 'prof-nostyle');
 echo $view->positions(array('user4' => 50, 'user5' => 50), 'prof-article');
 echo $view->position('banner5', 'prof-nostyle');?>
 </div>
 <?php if ($view->containsModules('left')) : ?>
   <div class="prof-layout-cell prof-sidebar1">
     <?php echo $view->position('left', 'prof-block'); ?>
   </div>
  <?php endif; ?>
 <?php if ($view->containsModules('right')) : ?>
    <div class="prof-layout-cell prof-sidebar2">
       <?php echo $view->position('right', 'prof-block'); ?>
    </div>
        <?php endif; ?>
       </div>
     </div>
   </div>

css 是:

.prof-layout-wrapper
{
  position: relative;
  margin: 0 auto 0 auto;
  z-index: auto !important;
 }

.prof-content-layout
{
  display: table;
  width: 100%;
  table-layout: fixed;    
  float: left;
}

.prof-content-layout-row
{
   display: table-row;
 }

.prof-layout-cell
{
  display: table-cell;
  vertical-align: top;
}

在我的一生中,我无法在不破坏整个布局的情况下让 Cell 4 跨越。

请帮忙!

(我希望这是一个足够好的解释)

【问题讨论】:

    标签: html css joomla css-tables


    【解决方案1】:

    当然!

    Demo Fiddle

    HTML

    <div class='table'>
        <div class='row'>
            <div class='cell'>cell1</div>
            <div class='cell'>
                <div class='table'>
                    <div class='row'>
                        <div class='cell'>cell2</div>
                        <div class='cell'>cell3</div>
                    </div>
                    <div class='caption'>cell4</div>
                </div>
            </div>
        </div>
    </div>
    

    CSS

    html, body {
        width:100%;
    }
    .table {
        display:table;
        width:100%;
    }
    .row {
        display:table-row;
    }
    .cell {
        display:table-cell;
        border:1px solid grey;
    }
    .caption {
        display:table-caption;
        caption-side:bottom;
        border:1px solid grey;
    }
    

    如果你想要自动展开/折叠功能,你可以稍微调整一下代码,a la this fiddle

    【讨论】:

    • @ImkeZA,一点也不——所以这就是解决方案?
    猜你喜欢
    • 2020-04-19
    • 2011-03-04
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    相关资源
    最近更新 更多