简体   繁体   English

桌面和移动视图的表结构不同

[英]Different Table structure for desktop and mobile view

I am new to this area. 我是这个领域的新手。 Could someone please help out of this. 有人可以帮忙吗? Now, I need a page with both desktop and mobile view. 现在,我需要一个同时具有桌面视图和移动视图的页面。 On this page, I need a table displayed. 在此页面上,我需要显示一个表。

In the Desktop view, it is displayed normally. 在桌面视图中,它正常显示。

    th1     th2     th3
    td1-1   td1-2   td1-3
    td2-1   td2-2   td3-3

But when switching to mobile view, I need to use this table with a different structure: With the table head at the left side and the table content at the right side. 但是,当切换到移动视图时,我需要使用具有不同结构的该表:表头位于左侧,表内容位于右侧。

    th1  td1-1
    th2  td1-2
    th3  td1-3
    th1  td2-1
    th2  td2-2
    th3  td2-3

Sorry, I don't have enough reputation to post images... 抱歉,我没有足够的声誉来发布图片...

Could someone please help out of this? 有人可以帮忙吗?

Well, write your codes for desktop first with the specified attributes, and soon after, start writing a new version of your table structure using media queries , the parent element for all your mobile-related GUI is the syntax below; 好吧,首先使用指定的属性为桌面编写代码,然后不久,使用媒体查询开始编写新版本的表结构,所有与移动相关的GUI的父元素是以下语法; write all your mobile-related codes in there; 在其中写下所有与手机相关的代码;

@media all and (max-width: 658px) {

 // Your Codes For Mobile

} 

Looking forward to get more familiar with media queries? 希望对媒体查询更加熟悉吗? then read this; 然后阅读

Media Queries 媒体查询

You can use media query to decide layout when it display in different screen sizes. 您可以使用媒体查询来确定以不同屏幕尺寸显示时的布局。 The idea is, when screen fit 500px or less, display table in mobile mode, otherwise, display in desktop mode. 这个想法是,当屏幕适合500px或更小尺寸时,以移动模式显示表格,否则,以桌面模式显示。

Here is example code: 这是示例代码:

CSS CSS

/*normal mode*/
#desk-table {
    display: block;
}
#phone-table {
    display: none;
}

/*mobile mode*/
@media only screen and (max-width: 500px) { // max-width is the size of the web broswer in mobile 
    #desk-table {
        display: none;
    }
    #phone-table {
        display: block;
    }
}

HTML HTML

<table id="desk-table">
<tr>
    <td>th-1</td>
    <td>th-2</td>
    <td>th-3</td>
</tr>
<tr>
    <td>td1-1</td>
    <td>td2-1</td>
    <td>td3-1</td>
</tr>
<tr>
    <td>td1-2</td>
    <td>td2-2</td>
    <td>td3-2</td>
</tr>

<table id="phone-table">
<tr>
    <td>th-1</td>
    <td>td1-1</td>
</tr>
<tr>
    <td>td2-1</td>
    <td>td2-1</td>
</tr>
<tr>
    <td>th-3</td>
    <td>td3-1</td>
</tr>
    <tr>
    <td>th-1</td>
    <td>td1-2</td>
</tr>
<tr>
    <td>td2-1</td>
    <td>td2-2</td>
</tr>
<tr>
    <td>th-3</td>
    <td>td3-2</td>
</tr>

You should use some Responsive Framekwork such as: 您应该使用一些响应式框架,例如:

They created really nice responsive column layout. 他们创建了非常好的响应式列布局。

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

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