gpt4 book ai didi

html - CSS:当我在 div 内的

内添加文本时,防止 div Y 轴移动

转载 作者:行者123 更新时间:2023-11-28 05:03:34 25 4
gpt4 key购买 nike

看看 div#1,为什么当我在 div#2 中添加一些文本时它会下降>p我一直在想办法,但一无所获。我是 CSS 新手。我无法理解这个 css3 是如何工作的,我不是设计师我是程序员,这让我很头疼。

p.n: 代码里面没有div#1/2,都是同一个类:container, Danke

.img {
width: 170px;
height:150px;
background: orange;
}
.contenedor:not(:first-child) {
margin: 0 50px;
}
.contenedor {
display: inline-block;
box-shadow: 0 4px 8px 0px rgba(0,0,0,0.4);
transition: .1s;
cursor: pointer;
resize: none;
max-width: 170px;
}
.contenedor:hover {
box-shadow: 0 8px 16px 0px rgba(0,0,0,0.4);
}
.leyenda {padding:0 10px 20px 10px;}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style>

</style>
<body>
<div class="contenedor">
<div class="img">DIV #1</div>
<div class="leyenda">
<h4><b>John Doe</b></h4>
<p><b>This should be up.</b></p>
</div>
</div>

<div class="contenedor">
<div class="img">DIV #2</div>
<div class="leyenda">
<h4><b>Jane Doe</b></h4>
<p>Post you charge here.Post you
charge here.Post you charge here.</p>
</div>
</div>

</body>
</html>

最佳答案

vertical-align: top;添加到.contenedor(它有display: inline-block;,所以它沿基线对齐默认情况下):

.img {
width: 170px;
height:150px;
background: orange;
}
.contenedor:not(:first-child) {
margin: 0 50px;
}
.contenedor {
display: inline-block;
box-shadow: 0 4px 8px 0px rgba(0,0,0,0.4);
transition: .1s;
cursor: pointer;
resize: none;
max-width: 170px;
vertical-align: top;
}
.contenedor:hover {
box-shadow: 0 8px 16px 0px rgba(0,0,0,0.4);
}
.leyenda {padding:0 10px 20px 10px;}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style>

</style>
<body>
<div class="contenedor">
<div class="img">DIV #1</div>
<div class="leyenda">
<h4><b>John Doe</b></h4>
<p><b>This should be up.</b></p>
</div>
</div>

<div class="contenedor">
<div class="img">DIV #2</div>
<div class="leyenda">
<h4><b>Jane Doe</b></h4>
<p>Post you charge here.Post you
charge here.Post you charge here.</p>
</div>
</div>

</body>
</html>

关于html - CSS:当我在 div 内的 <p> 内添加文本时,防止 div Y 轴移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39948854/

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