在将一个DIV与DIV居中时,我需要帮助。 我想要一个容器DIV,它是自动宽度的,它占据了屏幕的整个宽度(我们称它为headerContainer。 在headerContainer中,我想要再添加3个DIV: 左DIV(400像素宽) 中心DIV(100像素宽) ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我的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;
}
这是一个图片或问题。
因此,我希望橙色框在它们所在的div的中心中彼此相邻漂浮。可以提供任何帮助:) Thanks1
由于您在#basicInfo
和#langs
上使用display: inline-block
, #langs
仅在父.items
上调用text-align: center
:
.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
}
在您的.items类中添加text-align:center( http://jsfiddle.net/cz19q7a9/ )
.items
{
text-align: center;
}
只需做一下margin: auto
在div
内部margin: auto
设置,它将根据其父级居中。 这是一个例子 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.