Html:DIv+CSS实现最简单的表格效果

DIv+CSS实现最简单的表格效果

1.html代码如下:

<html>
<head>
    <title>div+CSS</title>
    <style>
        .table{
            /*此元素会作为块级表格来显示(类似 <table>),表格前后带有换行符。*/
            display:table;
            /*border-collapse:collapse;*/
            border-collapse:separate;
            border:1px solid #ccc;
        }
        .table-caption{
            /*此元素会作为一个表格标题显示(类似 <caption>)*/
            display:table-caption;
            margin:0;
            font-size:16px;
        }
        .table-header-group{
            /*此元素会作为一个或多个行的分组来显示(类似 <thead>)。*/
            display:table-header-group;
            background:#eee;
            font-weight:bold;
        }
        .table-row-group{
            /*此元素会作为一个或多个行的分组来显示(类似 <tbody>)。*/
            display:table-row-group;
        }
        .table-footer-group{
            /*此元素会作为一个或多个行的分组来显示(类似 <tfoot>)。*/
            display:table-footer-group;
        }
        ul{
            list-style:none;
        }
        .table-row{
            /*此元素会作为一个表格行显示(类似 <tr>)。*/
            display:table-row;
        }
        .table-cell{
            /*此元素会作为一个表格单元格显示(类似 <td> 和 <th>)*/
            display:table-cell;
            padding:0 5px;
            border:1px solid #ccc;
        }
        .table-row-group .table-row:hover,
        .table-footer-group .table-row:hover{
            background:#f6f6f6;
            color:green;
            font-weight: bold;
        }
 
        .table-column-group{
            /*此元素会作为一个或多个列的分组来显示(类似 <colgroup>)。*/
            display:table-column-group;
        }
        .table-column{
            /*此元素会作为一个单元格列显示(类似 <col>)*/
            display:table-column;
            width:100px;
        }
    </style>
</head>
<body>
    <div class="table">
        <h2 class="table-caption">表名</h2>
        <!--此行代码用于,控制列的样式。-->
        <div class="table-column-group">
            <div class="table-column"></div>
            <div class="table-column"></div>
            <div class="table-column"></div>
        </div>
        <div class="table-header-group">
            <ul class="table-row">
                <li class="table-cell">序号</li>
                <li class="table-cell">姓名</li>
                <li class="table-cell">年龄</li>
            </ul>
        </div>
        <div class="table-row-group">
            <ul class="table-row">
                <li class="table-cell">1</li>
                <li class="table-cell">AA</li>
                <li class="table-cell">123</li>
            </ul>
            <ul class="table-row">
                <li class="table-cell">2</li>
                <li class="table-cell">BB</li>
                <li class="table-cell">222</li>
            </ul>
            <ul class="table-row">
                <li class="table-cell">3</li>
                <li class="table-cell">CC</li>
                <li class="table-cell">333</li>
            </ul>
        </div>
        <div class="table-footer-group">
            <ul class="table-row">
                <li class="table-cell">表格底部1</li>
                <li class="table-cell">表格底部2</li>
                <li class="table-cell">表格底部3</li>
            </ul>
        </div>
    </div>
</body>

2.运行效果

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
很好,以下是简单的步骤: 1. 首先创建一个 HTML 文件,命名为 index.html。在文件中添加一个 head 和 body 标签,以及一个导航栏和一个 footer。 2. 在 head 标签中添加一个标题和一个链接到你喜欢的字体库。你可以使用 Google 字体库,如下所示: ```html <head> <title>My Music Site</title> <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"> </head> ``` 3. 在 body 标签中创建一个 div,用于包含所有的内容。在这个 div 中添加一个标题和一个搜索栏。 ```html <body> <div class="container"> <h1>My Music Site</h1> <form> <input type="text" placeholder="Search for music..."> <button type="submit">Search</button> </form> </div> </body> ``` 4. 接下来,添加一些样式到你的网页中。在 head 标签中添加一个样式标签,并为你的元素添加样式: ```html <style> body { margin: 0; padding: 0; font-family: 'Open Sans', sans-serif; } .container { max-width: 800px; margin: 0 auto; padding: 20px; } h1 { text-align: center; } form { display: flex; margin-top: 20px; } input[type="text"] { flex: 1; border: none; padding: 10px; font-size: 16px; } button[type="submit"] { background-color: #F44336; border: none; color: white; padding: 12px 20px; font-size: 16px; cursor: pointer; } button[type="submit"]:hover { background-color: #FFC107; } </style> ``` 5. 现在,我们需要添加一些音乐到我们的网站中。你可以使用 HTML5 的音频标签来嵌入音频。 ```html <audio src="music.mp3" controls></audio> ``` 6. 在你的容器 div 中添加一些音乐。你可以使用一个表格来列出你的音乐,并为每一行添加一个音频标签。 ```html <table> <thead> <tr> <th>Title</th> <th>Artist</th> <th>Album</th> <th>Length</th> </tr> </thead> <tbody> <tr> <td><audio src="music1.mp3" controls></audio></td> <td>Artist 1</td> <td>Album 1</td> <td>3:45</td> </tr> <tr> <td><audio src="music2.mp3" controls></audio></td> <td>Artist 2</td> <td>Album 2</td> <td>4:23</td> </tr> <tr> <td><audio src="music3.mp3" controls></audio></td> <td>Artist 3</td> <td>Album 3</td> <td>3:12</td> </tr> </tbody> </table> ``` 7. 最后,我们需要添加一些 JavaScript 代码来使我们的搜索栏工作。当用户提交表单时,我们将使用 JavaScript 过滤我们的音乐列表。 ```html <script> const form = document.querySelector('form'); const input = document.querySelector('input[type="text"]'); const table = document.querySelector('table'); form.addEventListener('submit', (event) => { event.preventDefault(); const searchTerm = input.value.toLowerCase(); for (let i = 1; i < table.rows.length; i++) { const title = table.rows[i].cells[0].innerText.toLowerCase(); const artist = table.rows[i].cells[1].innerText.toLowerCase(); const album = table.rows[i].cells[2].innerText.toLowerCase(); if (title.indexOf(searchTerm) > -1 || artist.indexOf(searchTerm) > -1 || album.indexOf(searchTerm) > -1) { table.rows[i].style.display = ''; } else { table.rows[i].style.display = 'none'; } } }); </script> ``` 现在你就可以打开你的网站并享受听歌的乐趣了!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奋斗鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值