代码之家  ›  专栏  ›  技术社区  ›  Hoseong Jeon

如何用CSS设置图片旁边的表格位置?

  •  0
  • Hoseong Jeon  · 技术社区  · 6 年前

    我想把桌子的位置设置在我的图像的右边。

    以下是我的代码:

    <html>
    <head>
    	<style type="text/css">
    		.podium { display: block; margin-left: 300; margin-top: 500; position: static; }
    		table { position: relative; left: 100px; }
    	</style>
    </head>
    <body>
    	<img src="podium.jpg" class="podium">
    	<table border="5px">
    		<tr>
    			<td>aaa</td>
    		</tr>
    	</table>
    </body>
    </html>

    我试过了,但没用。

    我怎么能做到?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Code Maniac    6 年前

    将图像和表包装在一个DIV中,然后可以使用的flex和flex order属性 Flex order .

    #wrapper{ display: flex; }
    #image{ order:2; width: 100px; height:100px; margin-left:15px}
    #table{ order:1; }
    <div id='wrapper'>
    <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSNyNcwf4fDjX_2L4mUcJNmg92fOmWlDTYxcefggBG0VAr6MX32" class="podium" id='image'>
    <table border="5px" id='table'>
      <tr>
        <td>aaa</td>
      </tr>
    </table>
    </div>