【问题标题】:Rearranging the order of cells in a table for mobile重新排列移动表格中单元格的顺序
【发布时间】:2018-01-08 04:41:33
【问题描述】:

我正在尝试更改@mobile 屏幕上表格中单元格的顺序,但没有任何运气。

我在 Mac 上的表格宽度是一个网格,具有不同的单元格大小、颜色、字体大小等,但在移动设备上,我希望它是一个由水平线分隔的简单列表,每个项目都有一个链接。我设法做到了,但我还想更改列表的显示顺序。

尝试添加 div 并以这种方式排序,但没有成功。任何建议都将受到欢迎!

这是我的 HTML 和移动 CSS:

@mobile screen CSS

.situations {


		table.situ {
		margin-left: 0%;
		}


		tr { 
		display: block;
		color: #161616 !important;
		line-height: 1 !important;
		border: none;

	}

		#frame {
		height: 100px;
		width: 100%;
		}
	
	td { 
		/* Behave  like a "row" */
		display: block;
		background-color: #ffffff;
		border: none;
		border-bottom: 0.5px solid #161616; 
		position: relative;
		padding-left: 2%;
		text-align: center;
		height: 60px;
		width: $fullWidth;
		font-size: 14px !important;
		color: #161616 !important;
			padding-top: 8%;
		padding-bottom: 8%;
		line-height: 1 !important;

	}
	
	td:before { 
		/* Now like a table header */
		position: absolute;
		/* Top/left values mimic padding */
		top: 6px;
		left: 6px;
		width: 45%; 
		padding-right: 10px; 
		white-space: nowrap;
		color: #161616 !important;
		line-height: 1 !important;
		border: none;
	}
  }
<section class="situations responsiveWidth center cinch2">
<div class="table"><table class="situ" id="frame" border="0" cellspacing="0" cellpadding="0">

  <tr>
  <div id="situ4"><td class="product1" height="33.333%" rowspan="2"><a class="label black" href="product1.html">Text</a></td></div>
    <div id="situ6"><td class="product2" height="16.666%"><a class="label black" href="product2.html">Text</a></td></div>
    
    <div id="situ3"><td class="product3" height="50%" rowspan="3"><a class="label black" href="product3.html">Text</a></td></div>
  </tr>
  <tr>
  	<div id="situ5"><td class="product4" height="16.666%"><a class="label black" href="product4.html">Text</a></td></div>
  </tr>
  <tr>
  	<div id="situ2"><td class="product5" height="33.333%" colspan="2" rowspan="2"><a class="label black big" href="product5.html">Text</a></td></div>
  </tr>
  <tr>
  <div id="situ7"><td class="product6" height="16.666%"><a class="label black" href="product6.html">Text</a></td></div>
  </tr>
  <tr>
  <div id="situ8"><td class="product7" height="16.666%"><a class="label black startout" href="product7.html" id="situ8">Text</a></td></div>
  <div id="situ1"><td class="product8" height="33.333%" colspan="2" rowspan="2"><a class="label white big" href="product8.html">Text</a></td></div>
  </tr>
  <tr>
  <div id="situ9"><td class="product9" height="16.66666%"><a class="label black" href="product9.html" id="situ9">Text</a></td></div>
  </tr>
  </table></div>
  <br>
  </section>

【问题讨论】:

    标签: html css mobile responsive-design html-table


    【解决方案1】:

    您可以考虑使用 div 代替表格,并为行设置一个弹性框。更改列的顺序非常容易。

    .table {
      display: table;
      width: 100%;
    }
    
    .row {
      display: flex;
      justify-content: space-between;
      width: 100%;
      border-bottom: thin solid lightgray;
    }
    
    .cell {
      display: table-cell;
      padding: 0.5em;
    }
    
    .title {
      order: 2;
    }
    
    .name {
      order: 1;
    }
    
    .zip {
      order: 4;
    }
    
    .place {
      order: 3;
    }
    <div class="table">
      <div class="row">
        <div class="cell title">Title</div>
        <div class="cell name">Name</div>
        <div class="cell zip">Zip</div>
        <div class="cell place">Place</div>
      </div>
      <div class="row">
        <div class="cell title">Title</div>
        <div class="cell name">Name</div>
        <div class="cell zip">Zip</div>
        <div class="cell place">Place</div>
      </div>
      <div class="row">
        <div class="cell title">Title</div>
        <div class="cell name">Name</div>
        <div class="cell zip">Zip</div>
        <div class="cell place">Place</div>
      </div>
    </div>

    【讨论】:

    • 非常感谢!我试了一下,但我认为我在 Mac 宽度上的原始网格需要是一张桌子。有谁知道我如何在保持表格的同时重新排列单元格?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多