英文:
HTML Text Wrapping
问题
以下是您要翻译的部分:
我正在为我的网站设计一个图像/文本框,我希望图像保持在文本的左侧,我已经成功实现了只有1或2行文本位于图像旁边的效果:
它保持在图像旁边
然而,一旦我添加更多文本,整个文本就会跳到底部。
全部跳到底部
以下是它的CSS/HTML代码:
HTML:
<div class="textBox">
<img src="bg.jpg" class="textBoxImg">
<div class="textBoxContent">
<p class="textBoxTitle">Chicago</p>
<p class="textBoxText">这里有更多关于芝加哥的信息!</p>
</div>
</div>
CSS:
.textBox {
background: white;
padding: 8px;
margin-left: 20%;
margin-right: 20%;
border-radius: 10px;
}
.textBoxContent {
display: inline-block;
vertical-align: top;
}
.textBoxTitle {
font-size: 30px;
line-height: 0px;
}
.textBoxText {
font-size: 15px;
overflow-wrap: break-word;
word-wrap: break-word;
}
.textBoxImg {
border-radius: 10px;
max-width: 40%;
height: auto;
}
我想知道如何修复这个问题,使得换行符将文本保持在图像的旁边,而不是下面。
我明白这可能不是最有效的方法来做这些事情,如果这是一个非常简单的问题,我也为此道歉,我还在学习中,对这个问题感到非常困惑。
英文:
I am working on an image/text box for my website, and I want the image to stay to the left of the text, which I got working with only 1 or 2 lines of text beside it:
It stays beside the image
However the second I add more text the whole text jumps to the bottom.
It all jumps to the bottom
Here is the CSS/HTML code for it:
HTML:
<div class="textBox">
<img src="bg.jpg" class="textBoxImg">
<div class="textBoxContent">
<p class="textBoxTitle">Chicago</p>
<p class="textBoxText">Here is more information about chicago!</p>
</div>
</div>
CSS:
.textBox {
background: white;
padding: 8px;
margin-left: 20%;
margin-right: 20%;
border-radius: 10px;
}
.textBoxContent {
display: inline-block;
vertical-align: top;
}
.textBoxTitle {
font-size: 30px;
line-height: 0px;
}
.textBoxText {
font-size: 15px;
overflow-wrap: break-word;
word-wrap: break-word;
}
.textBoxImg {
border-radius: 10px;
max-width: 40%;
height: auto;
}
I am wondering how I can fix that so the line break will keep the text to the side of the image, not below it.
I understand that this may not be the most efficient way to do these things, and I apologize too if this is a very easy question, I am still just learning and got very stumped by this one.
答案1
得分: 0
将以下内容添加到名为textBox的类中:
.textBox {
display: flex;
flex-direction: row;
background: white;
padding: 8px;
margin-left: 20%;
margin-right: 20%;
border-radius: 10px;
}
这将解决问题。如您所见,我添加了flex属性(display: flex;),并设置了方向(flex-direction: row;)。我建议您学习更多关于'Flex'和'Grid'属性的知识,以便更好地组织容器,使其按您的意愿进行布局。希望这有所帮助
英文:
Add this to your class called textBox :
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.textBox {
display: flex;
flex-direction: row;
background: white;
padding: 8px;
margin-left: 20%;
margin-right: 20%;
border-radius: 10px;
}
<!-- end snippet -->
This will fix it. As you can see, I added the flex property (display: flex;) and I gave it a direction (flex-direction: row;). I would recommend you to learn more about 'Flex' and 'Grid' properties to be able to organize better every container as you want it to be. I hope this helped
答案2
得分: 0
以下是您要翻译的内容:
Simplified your css ...make sure bg.jpg and your html are in same folder.
.textBox {
padding: 8px;
}
.textBoxContent {
display: inline-block;
height: 10px;
width: 500px;
vertical-align: top;
}
.textBoxImg {
max-width: 40%;
}
<div class="textBox">
<img src="bg.jpg" class="textBoxImg">
<div class="textBoxContent">
<a>Chicago</a>
<p>Here is more information about chicago!Here is more information about chicago!Here is more information about chicago!Here is more information about chicago!Here is more information about chicago!</p>
</div>
</div>
英文:
Simplified your css ...make sure bg.jpg and your html are in same folder.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.textBox {
padding: 8px;
}
.textBoxContent {
display: inline-block;
height: 10px;
width: 500px;
vertical-align: top;
}
.textBoxImg {
max-width: 40%;
}
<!-- language: lang-html -->
<div class="textBox">
<img src="bg.jpg" class="textBoxImg">
<div class="textBoxContent">
<a>Chicago</a>
<p>Here is more information about chicago!Here is more information about chicago!Here is more information about chicago!Here is more information about chicago!Here is more information about chicago!</p>
</div>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论