1. 程式人生 > 其它 >css flex佈局文字過長,寬度被撐開的解決辦法

css flex佈局文字過長,寬度被撐開的解決辦法

技術標籤:css

先上問題圖
在這裡插入圖片描述

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>flex超出省略問題</title>
	<style>
		.flex{
			display: flex;
		}
		.left{
			flex:1 1 auto;
			background: red;
		}
		.left p{
			width: 100%;
			text-overflow:ellipsis;
			overflow
:hidden; white-space:nowrap; } .right{ background:green; width: 200px; }
</style> </head> <body> <div class="flex"> <div class="left"> <p>我在左邊,自適應佈局我在左邊,自適應佈局我在左邊,自適應佈局我在左邊,自適應佈局</p></div> <div class="
right"
>
我在右邊,定寬</div> </div> <div class="flex"> <div class="left" style="width:0"> <p>我在左邊,自適應佈局我在左邊,自適應佈局我在左邊,自適應佈局我在左邊,自適應佈局</p> </div> <div class="right">我在右邊,定寬</div> </div> </
body
>
</html>