简体   繁体   English

如何将 HTML 音频元素缩小到表格单元格中?

[英]How do I shrink the HTML audio element into a table cell?

I want the audio player to shrink if it doesn't have enough space.如果没有足够的空间,我希望音频播放器缩小。

Not to obscure the author column!不要掩盖作者栏目!

What am I missing here please?请问我在这里缺少什么?

 table { width: 100%; table-layout: fixed; }
 <table> <thead> <td>Audio</td> <td>Author</td> <td>Title</td> <td>Distance (m)</td> <td>Uploaded (mins)</td> </thead> <tbody> <tr> <td> <audio controls> <source src="https://local-audio-test.s3.ap-southeast-1.amazonaws.com/%5B%3A%3A1%5D%3A37588/2022-01-02/test.m4a" type="audio/x-m4a" /> </audio> </td> <td>[::1]:37588</td> <td>hahaha</td> <td>0</td> <td>224m ago</td> </tr> <tr> <td> <audio controls> <source src="https://local-audio-test.s3.ap-southeast-1.amazonaws.com/%5B%3A%3A1%5D%3A37562/2022-01-01/audio.m4a" type="audio/x-m4a" /> </audio> </td> <td>[::1]:37562</td> <td></td> <td>11566426</td> <td>906m ago</td> </tr> </tbody> </table>

Set your audio width to 100%:将音频宽度设置为 100%:

audio {
  width: 100%;
}

It then takes up the full width of the parent cell, shrinking if appropriate.然后它会占据父单元格的整个宽度,并在适当时缩小。

You may add audio width to your but it some times doesn't show the entire control, so you use width property as well as the hover to show the full control when needed.您可以添加音频宽度,但有时它不会显示整个控件,因此您可以使用 width 属性以及 hover 在需要时显示完整控件。

 audio {
  width: 100%;
 }

 .float:hover {
   width:300px;
}

Or you should change the cell width of the whole audio column.或者您应该更改整个音频列的单元格宽度。

 .head-audio {
   width:400px;  
 }

Don't forget to add the class in HTML,不要忘记在 HTML 中添加 class,

 <table >
     <thead>
         <td class = "head-audio">Audio</td>
         <td>Author</td>
         <td>Title</td>
         <td>Distance (m)</td>
         <td>Uploaded (mins)</td>
     </thead>
  <tbody>
  <tr>
      <td class = "head-audio">
          <audio class = "float" controls>
              <source src="https://local-audio-test.s3.ap-southeast- 
                      1.amazonaws.com/%5B%3A%3A1%5D%3A37588/2022-01-02/test.m4a" 
                      type="audio/x-m4a" />
          </audio>
       </td>
       <td>[::1]:37588</td>
       <td>hahaha</td>
       <td>0</td>
       <td>224m ago</td>
   </tr>
   <tr>
   <td>
    <audio class = "head-audio" controls>
      <source src="https://local-audio-test.s3.ap-southeast-1.amazonaws.com/%5B%3A%3A1%5D%3A37562/2022-01-01/audio.m4a" type="audio/x-m4a" />
    </audio>
  </td>
  <td>[::1]:37562</td>
  <td></td>
  <td>11566426</td>
  <td>906m ago</td>
</tr>

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

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