简体   繁体   English

HTML/CSS 使表格全宽,同时具有浮动右图像

[英]HTML/CSS Make table full width while having float right image

I would like to make a table full (remaining) width without getting pushed away by an "float: right" image.我想制作一张完整(剩余)宽度的桌子,而不会被“浮动:正确”图像推开。 The (simplified) code is like this: (简化的)代码是这样的:

<div>
<img style="float: right;">
<table>
...
</table>
<p>Some text</p>
<p>Even more text</p>
...
</div>

If give the table the style "width: 100%" it is displayed below the image with the full width.如果为表格指定样式"width: 100%" ,它将以全宽显示在图像下方。 If I do not set the width it has the minimum size to fit the text without line breaks.如果我没有设置宽度,它的最小尺寸可以适合没有换行符的文本。 I would like to have it fill out all space left of the image (with a minimum size so it gets pushed away in extreme cases).我想让它填满图像剩下的所有空间(最小尺寸,所以在极端情况下它会被推开)。 I couldn't find any solution for this.我找不到任何解决方案。

Edit: sorry, maybe I wasn't clear what I would like the result to look like, I created an image.编辑:对不起,也许我不清楚我希望结果是什么样的,我创建了一个图像。 The tricky part is the table should extend all over to the image and the text should start directly below the table, even if the image is bigger (that's the part I cannot get working using flex)棘手的部分是表格应该延伸到图像并且文本应该直接在表格下方开始,即使图像更大(这是我无法使用 flex 工作的部分) 网站示例

you wanna try this solution, you can change the size of the image all you want你想试试这个解决方案,你可以随意改变图像的大小

<div style="display: flex;">
<img src="img.png" style="float: right; width: 90%">
<table style=" width: 100%; border: 1px solid; ">
    <tr>
        <td style="border: 1px solid;">Some text</td>
        <td style="border: 1px solid;">Some text</td>
        <td style="border: 1px solid;">Some text</td>
        <td style="border: 1px solid;">Some text</td>
        <td style="border: 1px solid;">Some text</td>
    </tr>
    <tr>
        <td style="border: 1px solid;">Even more text</td>
        <td style="border: 1px solid;">Even more text</td>
        <td style="border: 1px solid;">Even more text</td>
        <td style="border: 1px solid;">Even more text</td>
        <td style="border: 1px solid;">Even more text</td>
    </tr>


</table>

<p>Some text</p>
<p>Even more text</p>
...
</div>
<div style="width:100%;">
<div style="max-width:50%; 
float:left;display:block;">
<table border=1 
 cellpadding=60px>
 <tr>
 <th>1</th>
 <th>2</th>
 <th>3</th>
 </tr>
 <tr>
 <td>1</td>
 <td>2</td>
 <td>3</td>    
 </table>

<p>Some text</p>
<p>Even more text</p>
 ...
</div>
<div style="max-width:50%; float:right;">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ37waf3hj3eVvTy40XYee0lQ6uVGJTx7m3Q&usqp=CAU" 
style="float:right; 
height:auto; 
width:100%; display:block;">
 </div>
 </div>

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

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