首页 > 解决方案 > 你能把跨度放在css的中心吗?

问题描述

我想知道,有没有一种方法可以让跨度标签使用 css 移动到中心?

我需要问这个问题,因为每当我text-align输入跨度时,它都不起作用。

html

<span>
This is span.
</span>`

CSS

span {
text-align:center;
}

标签: htmlcss

解决方案


要使元素内的文本水平居中,请使用text-align: center;. 对于两个文本:

<!DOCTYPE html>
<html>
<head>
<style>
.center {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
  border: 3px solid green; 
}
</style>
</head>
<body>

<div class="center">
  <p>I am vertically and horizontally centered.</p>
</div>

</body>
</html>


推荐阅读