gpt4 book ai didi

html - 如何将 2 个 div 并排放置

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

我尝试将 2 个 div 并排放置,但不知何故它们将它们放在了彼此的下面。

我已经在这个论坛上查找并复制了它的 css 代码,但它仍然无法工作,我认为这与我在其中使用的 php 代码有关。

<html>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<header>
<nav>
<p><a href="index.php"><img src="img/handboeklogo.png"></a></p>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="#">Checklist</a>
<ul>
<li><a href="#">Desktops</a></li>
<li><a href="#">Laptops</a></li>
<li><a href="#">Monitoren</a></li>
</ul>
</li>
<li><a href="#">Handboek</a>
<ul>
<li><a href="#">Desktops</a></li>
<li><a href="#">Laptops</a></li>
<li><a href="#">Monitoren</a></li>
<li><a href="#">Printers</a></li>
<li><a href="#">Mobiele Telefoons</a></li>
</ul>
</li>
<li><a href="#">Classificatielijst</a><ul>
<li><a href="#">Desktops</a></li>
<li><a href="#">Laptops</a></li>
<li><a href="#">Monitoren</a></li>
<li><a href="#">Printers</a></li>
<li><a href="#">Mobiele Telefoons</a></li>
</ul>
</li>


<form class='logout' method='POST' action=''>
<button type='submit' name='logoutSubmit'>Logout</button>
</form>
</nav>
</header>
<br><br>


<div id='maindiv'><div id='first'>





<form method='POST' action=''>
<input type='hidden' name='uid' value='1'>
<input type='hidden' name='date' value='2019-07-02'>
<textarea name='message'></textarea><br>
<button type='submit' name='commentSubmit'> Comment </button>
</form></div>

<div id='second'>



<form method='POST' action=''>
<input type='hidden' name='uid' value='1'>
<input type='hidden' name='date' value='2019-07-02'>
<textarea name='message'></textarea><br>
<button type='submit' name='Generalcommentsubmit'> Comment </button>
</form></div></div>
</body>
</html>

CSS 代码:

body {
background-color: #edf0f2;
}

textarea {
display: inline-block;
width: 630px;
height: 120px;
background-color: #fff;
border-color: #5bb112;
margin-top: 10px;
margin-left: 15px;
position: relative;
resize: none;
}

.Changelog {
margin-left: 15px;
width: 800px;
}

.logout {
display: inline-block;
float: right;
position: absolute;
margin-top: 27px;
margin-right: 20px;
margin-left: 680px;
}

.login {
display: inline-block;
float: right;
position: absolute;
margin-top: 27px;
margin-right: 20px;
margin-left: 330px;
}
/*
button {
width: 100px;
height: 30px;
background-color: #5bb112;
border: none;
color: #e2e2e2;
font-family: arial;
font-weight: 400;
cursor: pointer;
margin-bottom: 19px;
margin-left: 15px;
margin-top: 3px;
}

.comment-box {
width: 630px;
padding-top: 5px;
margin-bottom: 4px;
background-color: #fff;
border-radius: 1px;
position: absolute;
border: 1px solid #5bb112;
margin-top: 8px;
align-content: left;
}

.comment-box p {
font-family: arial;
font-size: 14px;
line-height: 16px;
color: #282828;
font-weight: 100;
margin-bottom: 10px;
margin-left: 5px;
}

.edit-form {
position: absolute;
top: 3px;
right: 3px;
}

.edit-form button {
width: 40px;
height: 20px;
color: #282828;
background-color: #fff;
opacity: 0.7;
}

.edit-form button:hover {
opacity: 1;
}

.delete-form {
position: absolute;
top: 3px;
right: 58px;
}

.delete-form button {
width: 40px;
height: 20px;
color: #282828;
background-color: #fff;
opacity: 0.7;
}

.delete-form button:hover {
opacity: 1;
}*/

* {
margin: 0;
padding: 0;
}

header nav {
width: 100%;
height: 80px;
background-color: #343131;
}

header nav p {
font-family: arial;
color: #b3b3b3;
font-size: 24px;
line-height: 55px;
float: left;
padding: 10px 20px;
}

header nav ul {
float: left;
z-index: 2;
}

header nav ul li {
float: left;
list-style: none;
position: relative;
margin-top: 15px;
margin-right: auto;
margin-left: 30px;
}

header nav ul li a {
display: block;
font-family: arial;
color: #b3b3b3;
font-size: 20px;
padding: 21px 14px;
text-decoration: none;
}

header nav ul li ul {
display: none;
position: absolute;
background-color: #343131;
border-radius: 0px 0px 4px 4px;
padding: 8px;
}

header nav ul li:hover ul {
display: block;
}

header nav ul li ul li {
width: 180px;
border-radius: 4px;
}

header nav ul li ul li a {
padding: 9px 14px;
}

header nav ul li ul li a:hover {
background-color: #343131;
}

header nav p img {
width: 210px;
height: 55px;
margin-top: 5px;
margin-bottom: 5px;
}


header nav ul li a:hover {opacity: 1}

header nav ul li a {
background-color: #343131;
border: none;
color: white;
opacity: 0.6;
transition: 0.3s;
}


.down {
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}

i {
border: solid white;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 3px;
margin-left: 10px;
margin-bottom: 3px;
}

/*-------Changelog---------*/

#maindiv {
display: flex;
width: auto;
border: 1px solid black;
overflow: hidden;
}
#first {
width: auto;
float:left;

}
#second {
float: left;
}


我想将 div 彼此相邻放置,这样我就可以在彼此旁边得到 2 个评论部分。

最佳答案

要将 2 个 div 彼此靠近放置,将它们包裹在另一个 div 中并将显示设置为“flex”

<div id="maindiv'>
<div id='first'>
//content here
</div>
<div id='second'>
//content here
</div>
</div>

在 CSS 中

#maindiv {
display: flex;
width: 500px;
border: 1px solid black;
overflow: hidden;
}
#first {
width: 300px;
}
#second {

}

关于html - 如何将 2 个 div 并排放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56853088/

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