gpt4 book ai didi

html - 尽管有 "display:inline-block",为什么这些 div 没有显示在同一行中?

转载 作者:太空宇宙 更新时间:2023-11-03 21:28:35 26 4
gpt4 key购买 nike

JSFiddle

在接下来的 SSCCE 中,我将 display:inline-block 应用于 div.content-textdiv.content-image。但它们仍然没有显示在同一行中。相反,它们显示如下:

enter image description here

我希望它们显示在同一行的蓝色框中。尽管有 display:inline-block;,为什么他们不呢?我应该如何让它发挥作用?

.content-box {
display: inline-block;
width: 350px;
height: 250px;
border: 5px solid blue;
}
.content-box .content-image {
width: 35%;
height: 100%;
background-size: cover;
/*border: 5px solid orange;*/
}
.content-box .content-text {
background-color: rgb(255, 255, 255);
color: #1c1a1a;
font-family: sans-serif;
font-size: 15px;
font-weight: 100;
overflow-y: auto;
/*border: 5px solid #52e007;*/
height: 100%;
width: 65%;
}
<!DOCTYPE>

<html>

<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>

<body>

<div class="content-box">


<div class="content-text">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>


<div class="content-image" style="background-image:url(http://www.penttila-gardens.com/activities/walking/countryside/images/02-harvest.jpg)"></div>


</div>

</body>

</html>

最佳答案

您应该将此 inline-block 布局应用于内部元素 .content-box .content-image.content-box .content-text,而不是容器 .content-box。之后,您应该删除元素之间的空格(它们由于内联布局而出现),例如,通过将 font-size: 0 (或 word-spacing: -100% )应用于 .content -box.

JSFiddle

关于html - 尽管有 "display:inline-block",为什么这些 div 没有显示在同一行中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31095098/

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