请问使用浮动实现一下效果该怎么实现?外部不想让其浮动是要加一个div吗?
3条回答 默认 最新
关注
这个不需要用浮动,绝对定位就可以。
<style> #contain { display: inline-block; position: relative; width: 150px; height: 150px; } img { width: 100%; height: 100%; } #content { position: absolute; bottom: 0; left: 0; width: 100%; height: 30px; background-color: black; text-align: center; line-height: 30px; color: white; } </style> <body> <div id="contain"> <img/> <div id="content"> 这是文字部分 </div> </div> </body>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用 1