You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

实现图片脱离背景效果并设置图片居中及底部溢出的方法

解决方案

修改后的代码

<div class="text-center flex flex-col relative">
  <div class="hidden md:flex mx-auto flex-row items-center">
    <p class="mr-4 text-white font-extrabold leading-tight text-4xl">Let the music</p>
    <div class="bg-other h-48 w-48 rounded-full relative shadow-lg z-10">
      <img 
        src="Sources/img/assets/people_music_login.png" 
        alt="people" 
        class="object-cover h-[14rem] absolute left-1/2 transform -translate-x-1/2 top-[-1rem]" 
      />
    </div>
    <p class="ml-4 text-white font-extrabold leading-tight text-4xl">carry you away</p>
  </div>
</div>

关键修改点说明

  • 圆形背景容器:
    • 移除overflow-hidden:让图片能突破圆形边界实现底部溢出效果
    • 添加relative:使内部绝对定位的图片以该容器为参考坐标
  • 图片元素:
    • 替换固定偏移left-12为left-1/2 + transform -translate-x-1/2:实现图片水平居中,适配容器尺寸变化
    • 增大图片高度(如h-[14rem])并设置top-[-1rem]:让图片向上偏移,底部自然溢出圆形容器
    • 保留object-cover:确保图片比例正常,避免拉伸变形

额外优化提示

  • 可调整top数值或图片高度,精准控制底部溢出的幅度
  • 若需突出图片底部内容,可添加object-position:center bottom属性,优先显示图片下半部分

内容的提问来源于stack exchange,提问作者Peter_Griffindor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 06:45:34