CSS常用设置

2025-08-16 11:15:05

  • 强制不换行
  • <div class="test">
       <div class="con">这里的文字就算很长也不会换行</div>
    </div>
    
    <style>
    .test{
    	white-space: nowrap;  //禁止换行
    	.con{
    		display: inline-block; //设置成行级块
    	}
    }
    </style>
  • position定位,计算中间距离,假设div宽度为100px,那么left:calc(50% - 50px)
  • <template>
    	<view class="test">
    		<view class="con">上下左右居中</view>
    	</view>
    </template>
    
    <script setup>
    	
    </script>
    
    <style lang="scss" scoped>
    .test{
    	position: relative;
    	width: 100%;
    	height: 100px;
    	background-color: #ff4141;
    	.con{
    		position: absolute;
    		width: 100px;
    		height: 50px;
    		background-color: #fff654;
    		top: calc(50% - 25px);
    		left: calc(50% - 50px);
    		font-size: 12px;
    	}
    }
    </style>
    
本文为"鸡肉"原创文章,转载无需和我联系,但请注明来自鸡肉
您的浏览器不支持canvas标签,请您更换浏览器