gpt4 book ai didi

html - 文本未居中对齐

转载 作者:太空宇宙 更新时间:2023-11-04 15:46:20 24 4
gpt4 key购买 nike

我创建了 4 列。前 3 列应该包含垂直方向的文本。问题是我无法对齐它。 justify-content 和 align-items 没有将文本定位在列的中心。如果您运行代码,您会看到它位于右侧。我希望它正好位于中心。

body{
margin:0;
padding: 0;
height: 100vh;
width: 100vw;
}
.forAll{
height: 100vh;
display: flex;
justfiy-content: center;
align-items: center;
text-align: center;
padding: 0;

}
.verticalOption{
transform: rotate(270deg);
line-height: 10px;
}
.verticalOption a{
text-decoration: none;
color: white;
font-size: 10px;
line-height: 5px;
white-space: nowrap;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<body>
<div class="no-gutters">
<div class="fluid-container d-flex flex-row-reverse">
<div class="container col-xl-9 col-9 col1 forAll bg-primary"></div>

<div class="container col-xl-1 col-1 col2 forAll bg-warning">
<h1 class="verticalOption"><a href="#">Sample Text</a></h1>
</div>

<div class="container col-xl-1 col-1 col3 forAll bg-danger">
<h1 class="verticalOption"><a href="#">Sample Text</a></h1>
</div>

<div class="container col-xl-1 col-1 col4 forAll bg-success">
<h1 class="verticalOption"><a href="#">Sample Text</a></h1>
</div>
</div>
</div>
</body>

最佳答案

我在列中添加了另一个 flex 容器,因此可以在 HTML 嵌套中进一步控制对齐方式。我还将列的内容对齐到 center。我还使 h1 显示 inline-flex 以删除所有额外的空白。

这里是添加所有类的地方:

<div class="container col-xl-1 col-1 col2 forAll bg-warning d-flex justify-content-center">
<h1 class="verticalOption d-inline-flex m-0">
<a href="#">Sample Text</a>
</h1>
</div>

演示

body{
margin:0;
padding: 0;
height: 100vh;
width: 100vw;
}
.forAll{
height: 100vh;
display: flex;
justfiy-content: center;
align-items: center;
text-align: center;
padding: 0;
}
.verticalOption{
transform: rotate(270deg);
line-height: 10px;
}
.verticalOption a{
text-decoration: none;
color: white;
font-size: 10px;
line-height: 5px;
width: 200px;
white-space: nowrap;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<body>
<div class="no-gutters">
<div class="fluid-container d-flex flex-row-reverse">
<div class="container col-xl-9 col-9 col1 forAll bg-primary"></div>

<div class="container col-xl-1 col-1 col2 forAll bg-warning d-flex justify-content-center">
<h1 class="verticalOption d-inline-flex m-0"><a href="#">Sample Text</a></h1>
</div>

<div class="container col-xl-1 col-1 col3 forAll bg-danger d-flex justify-content-center">
<h1 class="verticalOption d-inline-flex m-0"><a href="#">Sample Text</a></h1>
</div>

<div class="container col-xl-1 col-1 col4 forAll bg-success d-flex justify-content-center">
<h1 class="verticalOption d-inline-flex m-0"><a href="#">Sample Text</a></h1>
</div>
</div>
</div>
</body>

关于html - 文本未居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55464442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com