如何大小的段落与图像相同的高度

发布于 2025-01-22 03:48:20 字数 765 浏览 0 评论 0原文

试图使段落的大小与右图的大小相同。目前是段落的底部更改大小,但顶部是固定的

带玩具车的孩子

CSS代码是

.kid{
    display: flex;
    position: relative;
    float: right;
    height: auto;
    max-width: 50%;
}


.paragraph{
    display: flex;
    margin-right: 50%;
    font-size-adjust: auto;
    background-color: #3498db;
    color:white;
    font-style: italic;
    font-weight: bold;
}

,我的HTML代码是

<div>       
<img class = "kid" src="kid%20playing%20toy%20pic.jpg">
</div>      
    
       
<div class = "para">    
<section class="paragraph">
    <p> "text" </p>  
</section>
</div> 

Trying to get the paragraph to be the same size as the image on the right as it. currently it is the bottom of the paragraph changes size but the top is fixed

kid with toy cars

my CSS code is

.kid{
    display: flex;
    position: relative;
    float: right;
    height: auto;
    max-width: 50%;
}


.paragraph{
    display: flex;
    margin-right: 50%;
    font-size-adjust: auto;
    background-color: #3498db;
    color:white;
    font-style: italic;
    font-weight: bold;
}

and my HTML code is

<div>       
<img class = "kid" src="kid%20playing%20toy%20pic.jpg">
</div>      
    
       
<div class = "para">    
<section class="paragraph">
    <p> "text" </p>  
</section>
</div> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雪落纷纷 2025-01-29 03:48:20

因为您希望图像的大小在段落的长度上具有动态性,所以我将使用2列flex> flex布局,第二个div包含图像作为background-background-image 。这样做是响应的,因为image-div的高度会随着段落变得越来越大。

.wrapper {
  display: flex;
  width: 100%;
  flex: auto;
}

.paragraph {
  background-color: #3498db;
  color: white;
  font-style: italic;
  font-weight: bold;
  width: 50%;
}

.image-div {
  background-image: url('https://dummyimage.com/600x400/000/fff');
  background-position: center;
  background-size: cover;
  width: 50%;
}
<h6> smaller </h6>
<div class="wrapper">
  <div class="paragraph">
    <p> 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 </p>
  </div>
  <div class="image-div">

  </div>
</div>


<h6> larger </h6>
<div class="wrapper">
  <div class="paragraph">
    <p> 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. 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. Lorem Ipsum
      is simply dummy text of the printing and typesetting industry.</p>
  </div>
  <div class="image-div">

  </div>
</div>

Because you want the size of the image to be dynamic with the length of the paragraph, I would use a 2-column flex layout with the second div containing the image as background-image. Do it this way is responsive because the height of the image-div will change as the paragraph gets smaller or larger.

.wrapper {
  display: flex;
  width: 100%;
  flex: auto;
}

.paragraph {
  background-color: #3498db;
  color: white;
  font-style: italic;
  font-weight: bold;
  width: 50%;
}

.image-div {
  background-image: url('https://dummyimage.com/600x400/000/fff');
  background-position: center;
  background-size: cover;
  width: 50%;
}
<h6> smaller </h6>
<div class="wrapper">
  <div class="paragraph">
    <p> 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 </p>
  </div>
  <div class="image-div">

  </div>
</div>


<h6> larger </h6>
<div class="wrapper">
  <div class="paragraph">
    <p> 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. 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. Lorem Ipsum
      is simply dummy text of the printing and typesetting industry.</p>
  </div>
  <div class="image-div">

  </div>
</div>

多情癖 2025-01-29 03:48:20

尚不清楚您实际想要什么。使用Flex。

.paragraph {
  display: flex; 
  justify-content:space-between;
  background-color: #3498db;
  color: white;
  font-style: italic;
  font-weight: bold;
}
<section class="paragraph">
  <p> "text" </p>
  <img class="kid" src="https://via.placeholder.com/150">
</section>

not entirely clear what you actually want. Use flex.

.paragraph {
  display: flex; 
  justify-content:space-between;
  background-color: #3498db;
  color: white;
  font-style: italic;
  font-weight: bold;
}
<section class="paragraph">
  <p> "text" </p>
  <img class="kid" src="https://via.placeholder.com/150">
</section>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文