CSS3属性:width:fit-content 水平居中

本文介绍了一种使用CSS实现响应式水平居中的导航栏的方法,适用于谷歌和火狐浏览器。通过`.centerul`样式设置宽度并使导航栏居中显示,`.centerli`样式则让各个菜单项水平排列。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

css code:


.center ul{

    width: -moz-fit-content;
    width: -webkit-fit-content;
    width: fit-content;
    margin: 0 auto;   
}
.center li{
    
    float: left;

}


html:

<div class="center">
    <ul>
        <li><a href="/">首页</a></li>
        <li><a href="/">关于我们</a></li>
        <li><a href="/">产品展示</a></li>
        <li><a href="/">客户支持</a></li>
        <li><a href="/">联系我们</a></li>
    </ul>
</div>

说明:仅支持谷歌、火狐浏览器,在移动端开发时可放心使用。


<template> <!-- <view class="modal-overlay" @tap.stop="hideModal" v-if="visible" @touchmove.stop.prevent> --> <view class="modal-overlay" @tap.stop="hideModal" @touchmove.stop.prevent> <view class="modal-content"> <swiper class="swiper" :class="advData.value.length==1?&#39;on&#39;:&#39;&#39;" :autoplay="autoplay" :duration="duration" @change="stopChange" v-if="advData.type == &#39;pic&#39; && advData.value.length"> <swiper-item v-for="(item,index) in advData.value" :key="index" @click="jump(item.link)"> <!-- <view class="swiper-item"> --> <view class="swiper-item-img"> <image :src="item.img" mode="aspectFit"></image> </view> <!-- </view> --> </swiper-item> </swiper> <text class="iconfont icon-ic_close1 fs-40 text--w111-fff"></text> </view> </view> </template> <style scoped> .modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.6); display: flex; height: 100%; justify-content: center; align-items: center; z-index: 1000; -webkit-overflow-scrolling: touch; /* 禁用 iOS 弹性滚动 */ } .modal-content { background-size: contain; background-repeat: no-repeat; position: fixed; top: 45%; left: 50%; transform: translate(-50%, -50%); height: 50%; z-index: 1001; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; } .modal-content-mobile { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); height: 30%; background-size: cover; background-position: center; z-index: 1001; } .modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10rpx; } .modal-footer1 { position: relative; top: 32%; transform: translate(-50%, -50%); margin-left: 48%; align-items: center; } .modal-footer2 { position: relative; top: 28%; margin-left: 50%; transform: translate(-50%, -50%); align-items: center; } .modal-footer3 { position: relative; top: 55%; margin-left: 50%; transform: translate(-50%, -50%); align-items: center; } .modal-body { font-size: 25rpx; position: relative; margin: 0 auto; top: 19%; width: 75%; align-items: center; } .modal-body-mobile { font-size: 35rpx; position: relative; margin: 0 auto; top: 35%; width: 80%; align-items: center; } .modal-body view { margin-top: 5%; justify-content: center; align-items: center; } .modal-body-mobile view { margin-top: 5%; justify-content: center; align-items: center; } input { justify-content: center; margin-top: 3%; width: 80%; background: #FFFFFF; border-radius: 8px 8px 8px 8px; padding: 14rpx 32rpx; font-size: 30rpx; } .swiper-item { height: 100%; text-align: center; position: relative; display: flex; align-items: flex-end; flex-direction: column-reverse } .jump-over { position: absolute; height: 325rpx; text-align: center; padding: 0 15rpx; font-weight: bold; z-index: 999; bottom: 20rpx; top: 50%; left: 50%; transform: translate(-50%, -50%); } .jump_img { position: absolute; bottom: 80rpx; left: 50%; transform: translateX(-50%); z-index: 1002; } .swiper-item { height: 100%; text-align: center; position: relative; display: flex; align-items: flex-end; flex-direction: column-reverse } .swiper-item-img { width: 60%; max-width: 800px; margin: 0 auto; height: 100%; position: relative; width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; } .swiper-item-img image { width: 100%; height: 100%; object-fit: contain; } .modal-content { /* position: relative; */ width: 50vw; /* height: 60vh; */ /* max-width: 800px; */ /* display: flex; */ /* flex-direction: column; */ /* align-items: center; */ /* justify-content: center; */ } .swiper { width: 100%; height: 100%; } .icon-ic_close1 { position: absolute; z-index: 1002; } </style> 修改代码:要求:这是一个uniapp的开屏弹窗 根据代码写出来css样式,关闭按钮要放在图片的下方并和图片保持间隔
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值