英文:
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:
<div id="wrapper" style="background-color:red">
<div id="left-side" style="background-color:blue">
Text
</div>
<div id="right-side" style="background-color:blue; min-width=50%; overflow: auto;">
Image
</div>
</div>
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:
<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;">
This text should not be longer than 750px
</div>
</div>
<div id="right-side" style="background-color:blue; max-width=50%;overflow: auto;">
Image
</div>
</div>
The problem is: Dealing with the two variants:
- text and image next to each other, each 50% of the width
- 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%;
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论