gpt4 book ai didi

html - 防止文本溢出到 DIV 之外

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

我有 2 个并排的 div。在每个 div 中是另一个 div。然后我将我的文本放在两个内部 div 中。框和文本在宽屏桌面 View 中看起来很棒,但是一旦达到 1024 及以下,文本就会开始超出 div。

我希望 div 根据需要展开和折叠以包含文本并在边框和文本之间留出适当的间距。我不想使用 overflow hidden ,因为我需要显示所有文本。

<style>
.hometext {
box-sizing: border-box;
}

.hometext {
margin: 0;
}

/* Create two equal columns that floats next to each other */
.hometext {
float: left;
width: 50%;
padding: 10px;
height: 300px; /* Should be removed. Only for demonstration */
}

.hometextinner {
border:1px solid #999;
padding-top:10px;
padding-left:20px;
padding-right:20px;
height:100%;
}

/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}

/* Responsive layout - makes the two columns stack on top of each other instead of next to each other */
@media (max-width: 600px) {
.hometext {
width: 100%;
}
.hometextinner {
border:1px solid #999;
padding-top:10px;
padding-left:20px;
padding-right:20px;
height:100%;
}
}
</style>
<body>
<div class="row">
<div class="hometext">
<div class="hometextinner"><h2>Column 1</h2>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p></div>
</div>
<div class="hometext">
<div class="hometextinner"><h2>Column 2</h2>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p></div>
</div>
</div>
</body>

最佳答案

如果您想要等高,请使用flexbox

例子

.row {
display: flex;
}

.row>.hometext {
flex: 1;
padding: 20px;
border: 1px solid;
}

@media screen and (max-width: 600px) {
.row {
flex-direction: column;
}
}
<body>
<div class="row">
<div class="hometext">
<div class="hometextinner">
<h2>Column 1</h2>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked
up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from
a line in section 1.10.32.</p>
</div>
</div>
<div class="hometext">
<div class="hometextinner">
<h2>Column 2</h2>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked
up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from
a line in section 1.10.32.</p>
</div>
</div>
</div>
</body>

提示

一个优点是您不必处理floatclear

关于html - 防止文本溢出到 DIV 之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48328331/

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