媒体查询之变化导航

要求很简单

屏幕宽>= 768px 就一行显示

小于<768px 就每行显示3个tab

<!DOCTYPE html>
<html>
<head>
	<title>响应式导航栏</title>

	<style type="text/css">
			*{
				padding: 0;
				margin:0;
				/*width: 750px;*/
			}
			/* 不变的写在最上面,变的写在媒体查询器中!*/
			ul{
				height: 60px;
				margin: 0 auto;
				list-style: none;
			}
			ul li{ 
				height: 60px;
				line-height: 60px;
				color:white;
				background-color: pink;
				float: left;
				text-align: center;
			}


			@media screen and (max-width: 767px){
				ul {
					width: 100%;
				}
				ul li {
					width: 33.33%;
				}
			}		

			@media screen and (min-width: 768px) {
				ul{
					width: 750px;
				}
				ul li{
					width:93.75px; 
				}
	</style>
</head>
<body>
		<ul>
			<li>1</li>
			<li>2</li>
			<li>3</li>
			<li>4</li>
			<li>5</li>
			<li>6</li>
			<li>7</li>
			<li>8</li>
		</ul>
</body>
</html>

代码就不多介绍了,这里有个小心得,就是

不变的代码写在媒体查询的外边,变得,写在媒体查询里面!

uni-app 中的 H5 底部导航栏(TabBar)通常用于构建底部固定的 UI 元素,比如小程序常见的底部菜单。要在 H5 页面上使用媒体查询设置 TabBar 的宽度,你需要考虑屏幕尺寸的变化。下面是一个基本的示例: ```html <!-- index.html --> <template> <view class="tab-bar"> <uni-tabbar :options="tabBarOptions" /> </view> </template> <script> export default { data() { return { tabBarOptions: { // 根据屏幕宽度动态设置样式 activeColor: '#007aff', itemColor: '#fff', selectedIconPath: '../static/tab-icon-active.png', // 活跃图标路径 unselectedIconPath: '../static/tab-icon-unactive.png', // 非活跃图标路径 items: [ { text: '首页', iconPath: '../static/home-icon.png', pagePath: '/pages/home/home' }, // 更多选项... ] } }; }, computed: { // 使用 Vue 的计算属性,在页面加载时根据 window.innerWidth 计算 tabbar 宽度 calculatedWidth: function () { return document.documentElement.clientWidth < 640 ? '100%' : 'auto'; } }, ready() { this.tabBarOptions.window = { width: this.calculatedWidth }; } }; </script> <style scoped> .tab-bar { position: fixed; bottom: 0; width: {{ calculatedWidth }}; /* 使用计算属性设置宽度 */ } </style> ``` 在这个例子中,`calculatedWidth` 利用了 `window.innerWidth` 来判断设备宽度,如果是小屏设备(如 iPhone SE),宽度设为 100%,在大屏设备上则使用自动宽度 (`auto`)。请注意替换实际的图片路径和页面路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值