两个并排的 div,左边一个包含文本,右边一个包含图像。

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

Two divs next to each other, the left one containing text, the right one an image

问题

I understand the two variants you want to achieve. Here's the translated code for your HTML structure:

<div id="wrapper" style="background-color: red;">
  <div id="left-side" style="background-color: blue;">
    <div id="text" style="max-width: 750px; min-width: 250px; background-color: orange; float: right; overflow-wrap: break-word;">
      这个文本不应超过750像素
    </div>
  </div>
  <div id="right-side" style="background-color: blue; max-width: 50%; overflow: auto;">
    图片
  </div>
</div>

The translated code should work for both variants you mentioned: text and image side by side at 50% width and text above the image with both centered and at 100% width.

英文:

I try to set up a website with an image of a letter and a transcription. So basically:

&lt;div id=&quot;wrapper&quot; style=&quot;background-color:red&quot;&gt;
  &lt;div id=&quot;left-side&quot; style=&quot;background-color:blue&quot;&gt;
    Text
  &lt;/div&gt;
  &lt;div id=&quot;right-side&quot; style=&quot;background-color:blue; min-width=50%; overflow: auto;&quot;&gt;
    Image
  &lt;/div&gt;
&lt;/div&gt;

The image can either take up 50% of the width if the two divs are next to each other in the same line and 100% if the screen is too small so that the 2nd div is in the next line.

The text should not exceed a max-width of 750px and align to the right of the center page. If the divs are in two rows the text-div should be in the center.

This is what I have so far:

&lt;div id=&quot;wrapper&quot; style=&quot;background-color:red&quot;&gt;
  &lt;div id=&quot;left-side&quot; style=&quot;background-color:blue&quot;&gt;
    &lt;div id=&quot;text&quot; style=&quot;max-width:750px; min-width: 250px; background-color:orange; float:right; overflow-wrap: break-word;&quot;&gt;
      This text should not be longer than 750px
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div id=&quot;right-side&quot; style=&quot;background-color:blue; max-width=50%;overflow: auto;&quot;&gt;
    Image
  &lt;/div&gt;
&lt;/div&gt;

The problem is: Dealing with the two variants:

  1. text and image next to each other, each 50% of the width
  2. text above and image below, both divs in the center and width=100%

答案1

得分: 1

这是代码的翻译部分:

#wrapper {
    background-color: red;
}

#left-side {
    background-color: yellow;
    text-align: right;
    width: 49%;
}

#right-side {
    background-color: green;
}

#text {
    display: inline-block;
    max-width: 750px;
    text-align: right;
    background-color: orange;
}

@media (min-width: 1500px) {
    #left-side {
        display: inline-block;
    }

    #right-side {
        display: inline-block;
        width: 49%;
    }
}

希望这有帮助。

英文:

Probably what you want to use a @media rule based on the screen width. Here is an example that would limit the image to 49% and show beside the text if the screen where 1500 px or wider. (Eliminate the inline styling.)

#wrapper {
    background-color: red;
}

#left-side {
    background-color: yellow;
    text-align: right;
    width: 49%;
}

#right-side {
    background-color: green;
}

#text {
    display: inline-block;
    max-width: 750px;
    text-align: right;
    background-color: orange;
}

@media (min-width: 1500px) {
    #left-side {
        display: inline-block;
    }

    #right-side {
        display: inline-block;
        width: 49%;
    }
}

huangapple
  • 本文由 发表于 2023年3月31日 04:08:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892573.html
匿名

发表评论

匿名网友

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

确定