带有文本的圆形Div内的图像

huangapple go评论72阅读模式
英文:

Image inside rounded Div with Text

问题

我正在制作一个圆角的 div,其中包含一个已经是圆角的图像,右侧有文本。

文本一直溢出了 div。而且,文本从 div 的中心开始。我希望它靠近图像。

如您所见的图片:图像离边缘不够近,文本离图像很远。

Screenshot

这是我尝试做的:

<div class="container2">
    <div class="image-container">
        <img src="test.svg" alt="Image" />
    </div>
    <div class="text-container">
        <p>文本。</p>
    </div>
</div>
.container2 {
    padding-top: 20px;
    height: 140px;
    background: #FFFFFF;
    box-shadow: 3px 3px 7px #00000029;
    border-radius: 94px;
    opacity: 1;
    display: flex;
}

.image-container {
    flex: 1;
    overflow: hidden;
}

.image-container img {
    padding: 4px;
    width: 60%;
    height: 100%;
}

.text-container {
    flex: 1.5; 
    padding: 10px;
    overflow: hidden;
    word-wrap: break-word;
}
英文:

I was making a rounded div , with an image (already rounded) with text on the right side.

The text keeps overflowing the div . Also , the text is starting from the center of the div . I want it to be close to the image .

As you can see the picture : the image is not close to the edge , and the text is far from the image .

Screenshot

This is what I tried to do :

&lt;div class=&quot;container2&quot;&gt;
                &lt;div class=&quot;image-container&quot;&gt;
                    &lt;img src=&quot;test.svg&quot; alt=&quot;Image&quot; /&gt;
                &lt;/div&gt;
                &lt;div class=&quot;text-container&quot;&gt;
                    &lt;p&gt;Text.&lt;/p&gt;
                &lt;/div&gt;
            &lt;/div&gt;
.container2 {
    padding-top:20px;
    height: 140px;
    background: #FFFFFF;
    box-shadow: 3px 3px 7px #00000029;
    border-radius: 94px;
    opacity: 1;
    display: flex;
}

.image-container {
    flex: 1;
    overflow: hidden;
}

    .image-container img {
        padding: 4px;
        width: 60%;
        height: 100%;
    }

.text-container {
    flex: 1.5; 
    padding: 10px;
    overflow: hidden;
    word-wrap: break-word;
}

答案1

得分: 0

这是你想要的设计示例:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin:0;
      padding:0;
    }

    body,html {
      width:100%;
      height:100%;
    }

    .container {
      width:100%;
      height:100%;
      display:flex;
      justify-content:center;
    }

    .wrapper {
      min-width:90%;
      height:60px;
      box-shadow:2px 2px 12px 2px #efefef;
      border-radius:50px;
      margin:10px;
      display:flex;
      align-items:center;
      padding:12px;
      overflow: hidden;
    }

    .wrapper .image {
      min-width:60px;
      height:60px;
      border-radius:50%;
    }

    .image img {
      width:100%;
      height:100%;
      border-radius:50%;
    }

    .wrapper .text {
      margin:12px;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="wrapper">
      <div class="image">
        <img src="../images/favicon.png">
      </div>
      <div class="text">
        <p>Hello Mcdonalds triad again</p>
      </div>
    </div>
  </div>
</body>
</html>

这是你的代码应该结构化的方式,它使用了 flexbox,有助于确保你的代码整齐有序,并且可以轻松排列和移动元素。同时,请用你自己的图片替换图像。为了防止溢出,如果你希望用户输入文本,你可能需要使用JavaScript或其他技术来限制文本输入。

英文:

This is an example of the design your going for:

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;title&gt;Document&lt;/title&gt;
&lt;style&gt;
* {
margin:0;
padding:0;
}
body,html {
width:100%;
height:100%;
}
.container {
width:100%;
height:100%;
display:flex;
justify-content:center;
}
.wrapper {
min-width:90%;
height:60px;
box-shadow:2px 2px 12px 2px #efefef;
border-radius:50px;
margin:10px;
display:flex;
align-items:center;
padding:12px;
overflow: hidden;
}
.wrapper .image {
min-width:60px;
height:60px;
border-radius:50%;
}
.image img {
width:100%;
height:100%;
border-radius:50%;
}
.wrapper .text {
margin:12px;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;wrapper&quot;&gt;
&lt;div class=&quot;image&quot;&gt;
&lt;img src=&quot;../images/favicon.png&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;text&quot;&gt;
&lt;p&gt;Hello Mcdonalds triad again&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

This is how your code should be structured, it's using flexbox and it'll help make sure your code is neatly organized and that you have easy access to arrange and move around elements. Also, replace the image with yours. To stop overflowing, you might want to limit the text input, if you want to use it for users to input, you'll need to use javascript or some other techniques to limit the text input.

答案2

得分: 0

.container2 {
  padding-top: 20px;
  height: 140px;
  background: #FFFFFF;
  box-shadow: 3px 3px 7px #00000029;
  border-radius: 100svh;
  opacity: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  /* Increase gap value to make space between image and text*/
  padding: .5rem;
}

.image-container {
  padding: 4px;
  height: 90%;
  overflow: hidden;
}

.image-container img {
  height: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 50%;
}

.text-container {
  flex: 1;
  padding-right: 10px;
  overflow: hidden;
  word-wrap: break-word;
}
<div class="container2">
  <div class="image-container">
    <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTEsQLvSHMFPa9yV2y_i9ifBdBA-vuFedWFHFLjUrDVB1OW1gppTwzM45Rl-l1yw09WtHs&amp;usqp=CAU" alt="Image" />
  </div>
  <div class="text-container">
    <p>Nous construisons des architectures bas&#233;es sur le Cloud, qui vous fournissent s&#233;curit&#233; et adaptabilit&#233; afin de surmonter les d&#233;fis communs qui d&#233;coulent d'architectures rigides ou obsol&#233;tes.</p>
  </div>
</div>
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.container2 {
padding-top: 20px;
height: 140px;
background: #FFFFFF;
box-shadow: 3px 3px 7px #00000029;
border-radius: 100svh;
opacity: 1;
display: flex;
align-items: center;
justify-content: space-between;
gap: .5rem;
/* Increase gap value to make space between image and text*/
padding: .5rem;
}
.image-container {
padding: 4px;
height: 90%;
overflow: hidden;
}
.image-container img {
height: 100%;
aspect-ratio: 1;
object-fit: cover;
border-radius: 50%;
}
.text-container {
flex: 1;
padding-right: 10px;
overflow: hidden;
word-wrap: break-word;
}

<!-- language: lang-html -->

&lt;div class=&quot;container2&quot;&gt;
&lt;div class=&quot;image-container&quot;&gt;
&lt;img src=&quot;https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTEsQLvSHMFPa9yV2y_i9ifBdBA-vuFedWFHFLjUrDVB1OW1gppTwzM45Rl-l1yw09WtHs&amp;usqp=CAU&quot; alt=&quot;Image&quot; /&gt;
&lt;/div&gt;
&lt;div class=&quot;text-container&quot;&gt;
&lt;p&gt;Nous construisons des architectures bas&#233;es sur le Cloud, qui vous fournissent s&#233;curit&#233; et adaptabilit&#233; afin de surmonter les d&#233;fis communs qui d&#233;coulent d&#39;architectures rigides ou obsol&#233;tes..&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年8月4日 23:57:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76837501.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定