gpt4 book ai didi

css - 垂直和水平对齐同时不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 09:23:56 25 4
gpt4 key购买 nike

我正在使用 Bootstrap 来布局我的网站。除了文本“THIS IS TEST”的垂直对齐外,一切都很好。我使用了我在网上找到的不同方式,例如垂直对齐的组合:中间和文本对齐:中心和 flexbox 。这些都没有产生正确的垂直对齐。这是我的代码:

 <!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
<style>
.header{

font-weight: bold;
font-size: 30px;
background-color: #4070CB;
color: #EFF0F2;
height:60px;

}
.txt{
align-items :center;
display : flex;
text-align: center;
justify-content: center;
}
.rightImg{
margin-right:30px;
margin-left:12px;
}
.leftImg{
margin-right:12px;
margin-left:30px;
}

</style>
</head>
<body>

<div class="container col-sm-offset-1">
<div class="row">
<div class="col-sm-10 header">
<div class="row">
<div class="col-sm-1 leftImg"><img src="http://image.flaticon.com/sprites/authors/28-simpleicon.png" alt="Smiley face" height="36" width="36"></div>
<div class="col-sm-8 txt">THIS IS A TEST</div>
<div class="col-sm-1 rightImg"><img src="http://image.flaticon.com/sprites/authors/28-simpleicon.png" alt="Smiley face" height="36" width="36"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3" style="background-color:lavender;">.col-sm-4</div>
<div class="col-sm-4" style="background-color:lavenderblush;">.col-sm-4</div>
<div class="col-sm-3" style="background-color:lavender;">.col-sm-4</div>
</div>

这里还有指向我的代码的 jfiddle 链接: jfiddle

有人可以帮忙吗?如何垂直对齐页眉中的文本?

最佳答案

您的文本垂直居中,但相对于行,而不是标题。

要垂直对齐标题中的所有内容,您可以用填充替换高度。

.header {
padding: 15px 0;
}

或者,您可以为文本应用边距。

.txt {
margin-top: 10px;
}

关于css - 垂直和水平对齐同时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41291755/

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