html文字一行时靠右,多行时靠左

移动端常用的单元格,经常有这样的布局,左边label,右边内容区域,当内容文字靠右时,需要一行时靠右,多行时靠左。
html文字一行时靠右,多行时靠左_第1张图片

实现1

<div class="cell">
	<div class="cell-label">单元格div>
	<div class="cell-value">内容div>
div>
<div class="cell">
	<div class="cell-label">单元格div>
	<div class="cell-value">内容内容内容内容内容内容内容内容内容内容内容内容div>
div>
.cell {
	display:flex;
	justify-content: space-between;
	padding: 10px 0;
	border-bottom: 1px solid #e5e5e5;
}
.cell .cell-label {
	width: 120px;
}

实现2


<div class="cell">
	<div class="cell-label">单元格div>
	<div class="cell-value">
		<div class="content">内容div>
	div>
div>
<div class="cell">
	<div class="cell-label">单元格div>
	<div class="cell-value">
		<div class="content">内容内容内容内容内容内容内容内容内容内容内容内容div>
	div>
div>
.cell {
	display: flex;
	justify-content: space-between;
	padding: 10px 0;
	border-bottom: 1px solid #e5e5e5;
}
.cell .cell-label {
	width: 120px;
}
.cell .cell-value {
	flex: 1;
	text-align: right;
}
.cell .cell-value .content {
	text-align: justify;
	display: inline-block;
}

实现3

<div class="cell">
	<div class="cell-label">单元格div>
	<div class="cell-value">
		<div class="content">内容div>
	div>
div>
<div class="cell">
	<div class="cell-label">单元格div>
	<div class="cell-value">
		<div class="content">内容内容内容内容内容内容内容内容内容内容内容内容div>
	div>
div>
.cell {
	display: flex;
	justify-content: space-between;
	padding: 10px 0;
	border-bottom: 1px solid #e5e5e5;
}
.cell .cell-label {
	width: 120px;
}
.cell .cell-value {
	flex: 1;
}
.cell .cell-value .content {
	display: flex;
	justify-content: flex-end;
}

你可能感兴趣的:(Notes,html,css,前端)