gpt4 book ai didi

html - 在 div 内居中 div

转载 作者:太空宇宙 更新时间:2023-11-03 17:47:09 24 4
gpt4 key购买 nike

我的 HTML 代码有问题,我想将某个分区内的内容居中。我不太确定如何。这是我的代码:HTML 代码(实际上是一个 PHP 文件):

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mateo.css">
<title>Mateo's About Page</title>
</head>
<body>
<div class="items">
<div id="basicInfo">
<img src="images/question.png">
</div>
<div id="langs">
<img src="images/code.jpg">
</div>
</div>
<div id="textSpace">

</div>
<?php
$username = $_POST['username'];
$password = $_POST['password'];


$accounts = mysqli_connect("localhost","root","BKpH7e6k","accounts") or die(mysqli_error());
mysqli_select_db($accounts, "accounts");


$sql = "
SELECT * from users WHERE Username LIKE '{$username}' AND Password LIKE '{$password}' LIMIT 1
";

$results = $accounts->query($sql);
if(!$results->num_rows == 1){
header("Location: http://localhost/aboutPage/login.php");
} else {
echo "<p>Logged in successfully!</p>";
}

?>
</body>
</html>

这是我的 CSS 文件:

body {
background: url("images/background.jpg") repeat;
font-size: 100%;
font-family: Arial;
}

.items {
display: block;
background-color: gray;
max-width: 50%;
max-height: 100%;
border-radius: 20px;
border: 2px solid black;
opacity: .8;
margin-left: auto;
margin-right: auto;

}
#basicInfo{
background-color: orange;
width: 100px;
height: 100px;
display: inline-block;
margin-top: 10px;
margin-bottom: 10px;
}
#basicInfo:hover{
background-color: green;
}
#basicInfo img{
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 16px;
}
#langs{
background-color: orange;
width: 100px;
height: 100px;
display: inline-block;
margin-top: 10px;
margin-bottom: 10px;
}
#langs img{
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 16px;
}
#langs:hover{
background-color: green;
}

这是一张图片或问题。 The problem

所以我希望橙色框在它们所在的 div 的中心彼此相邻 float 。任何帮助都适用 :) 谢谢 1

最佳答案

由于您在 #basicInfo#langs 上使用 display: inline-block 只需调用 text-align: center 在父 .items 上:

.items {
display: block;
background-color: gray;
max-width: 50%;
max-height: 100%;
border-radius: 20px;
border: 2px solid black;
opacity: .8;
margin-left: auto;
margin-right: auto;
text-align: center; //add
}

FIDDLE

关于html - 在 div 内居中 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27951149/

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