简体   繁体   English

用无序列表替换表

[英]Replacing tables with unordered lists

I have a requirement to remove the use of tables and replace the code with HTML lists ( <ul> and <li> ). 我需要删除表的使用,并用HTML列表( <ul><li> )替换代码。 The HTML code to be replaced is as below 要替换的HTML代码如下

<table>  
     <tr>  
         <td>  
            <img width="40" height="40" src="../images/johnsmith2.jpg" alt="johnsmith2" />  
        </td>  
        <td>  
            <table>  
                <tr><td>John Smith</td></tr>  
                <tr><td>24 years</td></tr>  
                <tr><td>Chicago</td></tr>  
            </table>  
        </td>  
    </tr>  
</table>  

Tried multiple options using lists but could not achieve this display. 使用列表尝试了多个选项,但无法实现此显示。 The text on the right always went below the image using lists, I wanted the vertical text list (name, then age, then city) to be adjacent to the image ie the list should produce the same shape as produced by the above table. 右侧的文本始终使用列表位于图像下方,我希望垂直文本列表(名称,年龄,城市)与图像相邻,即列表应具有与上表相同的形状。

Please let me know how this can be done via CSS with HTML lists. 请让我知道如何通过带有HTML列表的CSS来完成此操作。

There are so many tutorials for this. 有这么多的教程。 Keep googling or try in w3schools.com. 继续谷歌搜索或在w3schools.com中尝试。

or may be check this: http://www.javascriptkit.com/script/script2/verticalmenu.shtml 或者可以检查一下: http : //www.javascriptkit.com/script/script2/verticalmenu.shtml

You could try something like this 你可以尝试这样的事情

<style>
.profile li{
    float: right;
    clear: right;
}
.profile .image{
    float: left;
    clear: none;
}
</style>
<ul class="profile">
    <li class="image"><img width="40" height="40" src="../images/johnsmith2.jpg" alt="johnsmith2" /></li>
    <li>John Smith</li>
    <li>24 years</li>
    <li>Chicago</li>
</ul>

For this you can use display:table property for this. 为此,您可以为此使用display:table属性。 Write like this: 这样写:

CSS 的CSS

.profile > li{
    display:table-cell;
}

.profile{
    display:table;
}

HTML 的HTML

<ul class="profile">
    <li><img width="40" height="40" src="../images/johnsmith2.jpg" alt="johnsmith2" /></li>
    <li>
        <ul>
            <li>John Smith</li>
            <li>24 years</li>
            <li>Chicago</li>
        </ul>
    </li>
</ul>

Check this http://jsfiddle.net/GCfSx/1/ 检查此http://jsfiddle.net/GCfSx/1/

Here is an example on jsFiddle , which contains your required solution... 这是jsFiddle上的jsFiddle ,其中包含您所需的解决方案...

http://jsfiddle.net/ZHbxr/16/ http://jsfiddle.net/ZHbxr/16/

You need to mark the parent <ul> display as table and the inner <li> display as table-cell 您需要将parent <ul> display as table标记parent <ul> display as table ,将inner <li> display as table-cell标记inner <li> display as table-cell

转换无序列表 (<ul> ) 转换为 HTML 格式的表格 (<div id="text_translate"><p> 我以前一直在寻求一种解决方案,允许我将无序列表转换为格式化的 HTML 表。</p><p> 当时,一位好心的用户提出了一个解决方案,我在下面附上了。</p><p> 该解决方案将无序列表转变为 Google 表格中的常规表格,其中不同的值被划分到它们自己的单元格中。 相反,我希望将无序列表转换为仅放在一个单元格中的格式化 html 表列表。</p><p> 如果可能的话,除此之外,我希望能够将数百个无序列表放入脚本中,然后将其转换为各自的 HTML 格式的表格。</p><p> 请参阅下面我从另一个用户那里获得的先前解决方案。</p><p> 希望这一切都有意义。</p><p> <strong>编辑:</strong>我还在这篇文章的最底部添加了输入和首选 output。</p><pre> In your situation, how about the following sample script? Sample script 1: This script parses your value using the regex. function myFunction1() { // This sample value is from your question. const sample = `<ul> <li>Material: 100% polyester with polyurethane coating</li> <li>Water column pressure: 4000mm</li> <li>Fit: Regular unisex</li> <li>Elasticated waistband with drawstring</li> <li>Elasticated cuffs with tonal coated zips</li> <li>Single back pocket with eyelet</li> <li>Concealed side pockets</li> <li>Ultrasonically welded seams</li> <li>Reflective accents</li> </ul>`; // Parse list. const obj = sample.matchAll(/<li>([\w\S\s]+?)<\/li>/g); const values = [...obj].map(e => { if (e && e.length > 1) { const temp = e[1].split(":"); return temp.length == 1? [temp[0].trim(), ""]: temp.map(f => f.trim()); } return ["", ""]; }); // Put the values to the sheet. const sheetName = "Sheet1"; // Please set the sheet name. const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName); sheet.getRange(1, 1, values.length, values[0].length).setValues(values); } When this script is run, your sample value is parsed. And, the values are put to the sheet. Sample script 2: This script parses your value using XmlService. function myFunction1() { // This sample value is from your question. const sample = `<ul> <li>Material: 100% polyester with polyurethane coating</li> <li>Water column pressure: 4000mm</li> <li>Fit: Regular unisex</li> <li>Elasticated waistband with drawstring</li> <li>Elasticated cuffs with tonal coated zips</li> <li>Single back pocket with eyelet</li> <li>Concealed side pockets</li> <li>Ultrasonically welded seams</li> <li>Reflective accents</li> </ul>`; // Parse list. const root = XmlService.parse(sample).getRootElement(); const values = root.getChildren("li", root.getNamespace()).map(e => { const temp = e.getValue().split(":"); return temp.length == 1? [temp[0].trim(), ""]: temp.map(f => f.trim()); }); // Put the values to the sheet. const sheetName = "Sheet1"; // Please set the sheet name. const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName); sheet.getRange(1, 1, values.length, values[0].length).setValues(values); } References: map() setValues(values) Added: From your following additional question, That does the job for doing it on one single product. Let's say I have a batch of product details for several different products. Like here below. Is there a way to run the script on all three at once so it becomes three different tables? In this case, how about the following sample script? Sample script: function myFunction2() { // This is from your new question. const samples = [ "<ul><li>Material: 100% polyester with polyurethane coating</li><li>Lining: 100% polyester</li><li>Insulation: 100% polyester</li><li>Measurements: H160cm x W140cm x D1cm / H63 x W55.1 x 0.4 inches</li><li>When packed: H13cm x W47cm x D25cm / H5.1 x W18.5 x D9.8 inc </li><li>Pack-carry-store system with buckles and adjustable webbing straps</li><li>Soft, quilted and padded side</li><li>Waterproof upper on reverse</li></ul>", "<ul><li>Material: 100% polyester with polyurethane coating</li><li>Water column pressure: 4000mm</li><li>Soft mesh lining</li><li>Circumference: S1 – 61.5 cm / 24.2 inches, / S2 - 66 cm / 26 inches</li></ul>", "<ul><li>Material: 100% polyester with polyurethane coating</li><li>Lining: 100% polyester </li><li>Water column pressure: 8000mm</li><li>Measurements: H16 x W21 x D8.5cm / H6.3 x W8.3 x D3.3 inches</li><li>Volume: 3 liters / 0.8 gallons</li><li>Coated tonal zip closure</li><li>Single main compartment </li><li>Detachable adjustable webbing shoulder strap </li><li>Carry handle</li></ul>" ]; const sheetNames = ["Sheet1", "Sheet2", "Sheet3"]; // Please set the sheet names. samples.forEach((sample, i) => { const root = XmlService.parse(sample).getRootElement(); const values = root.getChildren("li", root.getNamespace()).map(e => { const temp = e.getValue().split(":"); return temp.length == 1? [temp[0].trim(), ""]: temp.map(f => f.trim()); }); const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetNames[i]); sheet.getRange(1, 1, values.length, values[0].length).setValues(values); }); }</pre><p> 请参阅下面的输入和首选 output。</p><p> 每当有一行带有冒号的文本时,比如“材料:100% 聚酯与聚氨酯涂层”,我希望它在表中分成两列,这样“材料:”在第 1 列,“带聚氨酯涂层的 100% 聚酯”在第 2 栏中。</p><p> <strong>输入:</strong></p><pre> /** List 1 **/ <ul> <li>Material: 100% polyester with polyurethane coating</li> <li>Lining: 100% polyester</li> <li>Insulation: 100% polyester</li> <li>Measurements: H160cm x W140cm x D1cm / H63 x W55.1 x 0.4 inches</li> <li>When packed: H13cm x W47cm x D25cm / H5.1 x W18.5 x D9.8 inc </li> <li>Pack-carry-store system with buckles and adjustable webbing straps</li> <li>Soft, quilted and padded side</li> <li>Waterproof upper on reverse</li> </ul> /** List 2 **/ <ul> <li>Material: 100% polyester with polyurethane coating</li> <li>Water column pressure: 4000mm</li> <li>Circumference: S1 – 61.5 cm / 24.2 inches, / S2 - 66 cm / 26 inches</li> <li>Soft mesh lining</li> </ul> /** List 3 **/ <ul> <li>Material: 100% polyester with polyurethane coating</li> <li>Lining: 100% polyester </li> <li>Water column pressure: 8000mm</li> <li>Measurements: H16 x W21 x D8.5cm / H6.3 x W8.3 x D3.3 inches</li> <li>Volume: 3 liters / 0.8 gallons</li> <li>Coated tonal zip closure</li> <li>Single main compartment </li> <li>Detachable adjustable webbing shoulder strap </li> <li>Carry handle</li> </ul></pre><p> <strong>通缉output:</strong></p><pre> /** Table 1 (converted from List 1) **/ <table> <tbody> <tr> <td>Material:</td> <td>100% polyester with polyurethane coating</td> </tr> <tr> <td>Lining:</td> <td>100% polyester</td> </tr> <tr> <td>Insulation:</td> <td>100% polyester</td> </tr> <tr> <td>Measurements:</td> <td>H160cm x W140cm x D1cm / H63 x W55.1 x 0.4 inches</td> </tr> <tr> <td>When packed:</td> <td>H13cm x W47cm x D25cm / H5.1 x W18.5 x D9.8 inc</td> </tr> <tr> <td>Pack-carry-store system with buckles and adjustable webbing straps</td> <td></td> </tr> <tr> <td>Soft, quilted and padded side</td> <td></td> </tr> <tr> <td>Waterproof upper on reverse</td> <td></td> </tr> </tbody> </table> /** Table 2 (converted from List 2) **/ <table> <tbody> <tr> <td>Material:</td> <td>100% polyester with polyurethane coating</td> </tr> <tr> <td>Water column pressure:</td> <td>4000mm</td> </tr> <tr> <td>Circumference:</td> <td>S1 – 61.5 cm / 24.2 inches, / S2 - 66 cm / 26 inches</td> </tr> <tr> <td>Soft mesh lining</td> <td></td> </tr> </tbody> </table> /** Table 3 (converted from List 3) **/ <table> <tbody> <tr> <td>Material:</td> <td>100% polyester with polyurethane coating</td> </tr> <tr> <td>Lining:</td> <td>100% polyester</td> </tr> <tr> <td>Water column pressure:</td> <td>8000mm</td> </tr> <tr> <td>Measurements:</td> <td>H16 x W21 x D8.5cm / H6.3 x W8.3 x D3.3 inches</td> </tr> <tr> <td>Volume:</td> <td>3 liters / 0.8 gallons</td> </tr> <tr> <td>Coated tonal zip closure</td> <td></td> </tr> <tr> <td>Single main compartment</td> <td></td> </tr> <tr> <td>Detachable adjustable webbing shoulder strap</td> <td></td> </tr> <tr> <td>Carry handle</td> <td></td> </tr> </tbody> </table></pre></div>)<table> </table></ul> - Convert unordered lists (<ul>) into HTML-formatted tables (<table>)

暂无
暂无

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

相关问题 转换无序列表 (<ul> ) 转换为 HTML 格式的表格 (<div id="text_translate"><p> 我以前一直在寻求一种解决方案,允许我将无序列表转换为格式化的 HTML 表。</p><p> 当时,一位好心的用户提出了一个解决方案,我在下面附上了。</p><p> 该解决方案将无序列表转变为 Google 表格中的常规表格,其中不同的值被划分到它们自己的单元格中。 相反,我希望将无序列表转换为仅放在一个单元格中的格式化 html 表列表。</p><p> 如果可能的话,除此之外,我希望能够将数百个无序列表放入脚本中,然后将其转换为各自的 HTML 格式的表格。</p><p> 请参阅下面我从另一个用户那里获得的先前解决方案。</p><p> 希望这一切都有意义。</p><p> <strong>编辑:</strong>我还在这篇文章的最底部添加了输入和首选 output。</p><pre> In your situation, how about the following sample script? Sample script 1: This script parses your value using the regex. function myFunction1() { // This sample value is from your question. const sample = `<ul> <li>Material: 100% polyester with polyurethane coating</li> <li>Water column pressure: 4000mm</li> <li>Fit: Regular unisex</li> <li>Elasticated waistband with drawstring</li> <li>Elasticated cuffs with tonal coated zips</li> <li>Single back pocket with eyelet</li> <li>Concealed side pockets</li> <li>Ultrasonically welded seams</li> <li>Reflective accents</li> </ul>`; // Parse list. const obj = sample.matchAll(/<li>([\w\S\s]+?)<\/li>/g); const values = [...obj].map(e => { if (e && e.length > 1) { const temp = e[1].split(":"); return temp.length == 1? [temp[0].trim(), ""]: temp.map(f => f.trim()); } return ["", ""]; }); // Put the values to the sheet. const sheetName = "Sheet1"; // Please set the sheet name. const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName); sheet.getRange(1, 1, values.length, values[0].length).setValues(values); } When this script is run, your sample value is parsed. And, the values are put to the sheet. Sample script 2: This script parses your value using XmlService. function myFunction1() { // This sample value is from your question. const sample = `<ul> <li>Material: 100% polyester with polyurethane coating</li> <li>Water column pressure: 4000mm</li> <li>Fit: Regular unisex</li> <li>Elasticated waistband with drawstring</li> <li>Elasticated cuffs with tonal coated zips</li> <li>Single back pocket with eyelet</li> <li>Concealed side pockets</li> <li>Ultrasonically welded seams</li> <li>Reflective accents</li> </ul>`; // Parse list. const root = XmlService.parse(sample).getRootElement(); const values = root.getChildren("li", root.getNamespace()).map(e => { const temp = e.getValue().split(":"); return temp.length == 1? [temp[0].trim(), ""]: temp.map(f => f.trim()); }); // Put the values to the sheet. const sheetName = "Sheet1"; // Please set the sheet name. const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName); sheet.getRange(1, 1, values.length, values[0].length).setValues(values); } References: map() setValues(values) Added: From your following additional question, That does the job for doing it on one single product. Let's say I have a batch of product details for several different products. Like here below. Is there a way to run the script on all three at once so it becomes three different tables? In this case, how about the following sample script? Sample script: function myFunction2() { // This is from your new question. const samples = [ "<ul><li>Material: 100% polyester with polyurethane coating</li><li>Lining: 100% polyester</li><li>Insulation: 100% polyester</li><li>Measurements: H160cm x W140cm x D1cm / H63 x W55.1 x 0.4 inches</li><li>When packed: H13cm x W47cm x D25cm / H5.1 x W18.5 x D9.8 inc </li><li>Pack-carry-store system with buckles and adjustable webbing straps</li><li>Soft, quilted and padded side</li><li>Waterproof upper on reverse</li></ul>", "<ul><li>Material: 100% polyester with polyurethane coating</li><li>Water column pressure: 4000mm</li><li>Soft mesh lining</li><li>Circumference: S1 – 61.5 cm / 24.2 inches, / S2 - 66 cm / 26 inches</li></ul>", "<ul><li>Material: 100% polyester with polyurethane coating</li><li>Lining: 100% polyester </li><li>Water column pressure: 8000mm</li><li>Measurements: H16 x W21 x D8.5cm / H6.3 x W8.3 x D3.3 inches</li><li>Volume: 3 liters / 0.8 gallons</li><li>Coated tonal zip closure</li><li>Single main compartment </li><li>Detachable adjustable webbing shoulder strap </li><li>Carry handle</li></ul>" ]; const sheetNames = ["Sheet1", "Sheet2", "Sheet3"]; // Please set the sheet names. samples.forEach((sample, i) => { const root = XmlService.parse(sample).getRootElement(); const values = root.getChildren("li", root.getNamespace()).map(e => { const temp = e.getValue().split(":"); return temp.length == 1? [temp[0].trim(), ""]: temp.map(f => f.trim()); }); const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetNames[i]); sheet.getRange(1, 1, values.length, values[0].length).setValues(values); }); }</pre><p> 请参阅下面的输入和首选 output。</p><p> 每当有一行带有冒号的文本时,比如“材料:100% 聚酯与聚氨酯涂层”,我希望它在表中分成两列,这样“材料:”在第 1 列,“带聚氨酯涂层的 100% 聚酯”在第 2 栏中。</p><p> <strong>输入:</strong></p><pre> /** List 1 **/ <ul> <li>Material: 100% polyester with polyurethane coating</li> <li>Lining: 100% polyester</li> <li>Insulation: 100% polyester</li> <li>Measurements: H160cm x W140cm x D1cm / H63 x W55.1 x 0.4 inches</li> <li>When packed: H13cm x W47cm x D25cm / H5.1 x W18.5 x D9.8 inc </li> <li>Pack-carry-store system with buckles and adjustable webbing straps</li> <li>Soft, quilted and padded side</li> <li>Waterproof upper on reverse</li> </ul> /** List 2 **/ <ul> <li>Material: 100% polyester with polyurethane coating</li> <li>Water column pressure: 4000mm</li> <li>Circumference: S1 – 61.5 cm / 24.2 inches, / S2 - 66 cm / 26 inches</li> <li>Soft mesh lining</li> </ul> /** List 3 **/ <ul> <li>Material: 100% polyester with polyurethane coating</li> <li>Lining: 100% polyester </li> <li>Water column pressure: 8000mm</li> <li>Measurements: H16 x W21 x D8.5cm / H6.3 x W8.3 x D3.3 inches</li> <li>Volume: 3 liters / 0.8 gallons</li> <li>Coated tonal zip closure</li> <li>Single main compartment </li> <li>Detachable adjustable webbing shoulder strap </li> <li>Carry handle</li> </ul></pre><p> <strong>通缉output:</strong></p><pre> /** Table 1 (converted from List 1) **/ <table> <tbody> <tr> <td>Material:</td> <td>100% polyester with polyurethane coating</td> </tr> <tr> <td>Lining:</td> <td>100% polyester</td> </tr> <tr> <td>Insulation:</td> <td>100% polyester</td> </tr> <tr> <td>Measurements:</td> <td>H160cm x W140cm x D1cm / H63 x W55.1 x 0.4 inches</td> </tr> <tr> <td>When packed:</td> <td>H13cm x W47cm x D25cm / H5.1 x W18.5 x D9.8 inc</td> </tr> <tr> <td>Pack-carry-store system with buckles and adjustable webbing straps</td> <td></td> </tr> <tr> <td>Soft, quilted and padded side</td> <td></td> </tr> <tr> <td>Waterproof upper on reverse</td> <td></td> </tr> </tbody> </table> /** Table 2 (converted from List 2) **/ <table> <tbody> <tr> <td>Material:</td> <td>100% polyester with polyurethane coating</td> </tr> <tr> <td>Water column pressure:</td> <td>4000mm</td> </tr> <tr> <td>Circumference:</td> <td>S1 – 61.5 cm / 24.2 inches, / S2 - 66 cm / 26 inches</td> </tr> <tr> <td>Soft mesh lining</td> <td></td> </tr> </tbody> </table> /** Table 3 (converted from List 3) **/ <table> <tbody> <tr> <td>Material:</td> <td>100% polyester with polyurethane coating</td> </tr> <tr> <td>Lining:</td> <td>100% polyester</td> </tr> <tr> <td>Water column pressure:</td> <td>8000mm</td> </tr> <tr> <td>Measurements:</td> <td>H16 x W21 x D8.5cm / H6.3 x W8.3 x D3.3 inches</td> </tr> <tr> <td>Volume:</td> <td>3 liters / 0.8 gallons</td> </tr> <tr> <td>Coated tonal zip closure</td> <td></td> </tr> <tr> <td>Single main compartment</td> <td></td> </tr> <tr> <td>Detachable adjustable webbing shoulder strap</td> <td></td> </tr> <tr> <td>Carry handle</td> <td></td> </tr> </tbody> </table></pre></div>)<table> </table></ul> - Convert unordered lists (<ul>) into HTML-formatted tables (<table>) 无序列表和可访问性 - Unordered lists and accessibility 无序列表之间的空间 - Space Between Unordered Lists 双无序列表 - Twin unordered lists 替换无序列表中的列表项 - replacing list item in unordered list 使用jQuery序列化无序列表 - Serializing unordered lists using jquery 嵌套无序列表的IE问题 - IE Issue With Nested Unordered Lists 中心无容器的无序列表 - center unordered lists without container 将 css 无序列表样式化为图像 - styling css unordered lists as image 使用无序列表创建表单? - Using unordered lists to create forms?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM