f9yx0du 发表于 2024-6-30 09:45:27

css使元素怎么样居中暗示?


    <div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">
            <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1、</span>已知宽度的元素居中</p>
            <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">思路:居中元素父级设置相对定位,居中元素绝对定位,距离顶部 top:50%,左边left:50%,<span style="color: black;">经过</span>margin-top、margin-left等于负的居中元素宽高的一半。</p>



            <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">.box{position:relative;width:200px;height:300px;}</p>
            <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> .a{position:absolute;top:50%;left:50%;margin-top:-150px;margin-left:-100px;}</p>
            <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2、</span>未知宽度的元素居中</p>思路:居中元素父级设置相对定位,居中元素绝对定位,距离顶部 top:50%,左边left:50%,<span style="color: black;">而后</span><span style="color: black;">运用</span><a style="color: black;">css</a>
            <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3 transform:translate(-50%; -50%)使元素居中。</p>



            <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> .box{position:relative;width:200px;height:300px;}</p>.
      </span></div>




情迷布拉格 发表于 2024-8-21 15:30:38

“BS”(鄙视的缩写)‌

j8typz 发表于 2024-10-5 13:12:57

外链发布社区 http://www.fok120.com/
页: [1]
查看完整版本: css使元素怎么样居中暗示?