css字体靠盒子两边
时间: 2023-10-20 07:31:17 浏览: 159
css盒子模型
要实现CSS字体靠盒子两边,可以使用text-align属性和justify-content属性。text-align属性用于水平对齐文本,而justify-content属性用于在弹性盒子中对齐子元素。
下面是一个例子,展示了如何将CSS字体靠盒子两边对齐:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
height: 100px;
width: 600px;
border: 1px solid;
display: flex;
justify-content: space-between; /* 使用justify-content属性将子元素分散对齐 */
align-items: center;
}
/* 文字靠盒子两边对齐 */
.box span {
text-align: justify; /* 使用text-align属性将文本两端对齐 */
text-align-last: justify; /* 兼容性设置,保在最后一行也能对齐 */
}
</style>
</head>
<body>
<div class="box">
<span>Left Text</span>
<span>Right Text</span>
</div>
</body>
</html>
```
在上述代码中,我们使用了justify-content: space-between;将子元素分散对齐,同时使用text-align: justify;将文本两端对齐。这样就可以实现CSS字体靠盒子两边的效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [文字两端对齐 文字平均分布在盒子中 css样式](https://blog.csdn.net/different9102/article/details/125097503)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [CSS-弹性盒子](https://blog.csdn.net/weixin_52142992/article/details/126463219)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文