简体   繁体   English

图片下方的CSS文字包装

[英]CSS Text Wrapping Under Image

I need some help stopping my text from wrapping under my image when the browser window gets smaller. 当浏览器窗口变小时,我需要一些帮助来阻止文本换行。

HTML: HTML:

<div class='article'>
  <img src='images/fakeSlider.png' />
  <h2>Example</h2>
  <p>This is my text.This is my text.This is my text.This is my text.This is my text.This is my text.This is my text.This is my text.This is my text.This is my text.This is my text.This is my text.</p>
</div>

CSS: CSS:

.article {
  min-width: 70%;
  max-width: 100%;
}

.article h2 {
  float: left;
  font-family: Cabin Bold;
  font-size: 22px;
  padding: 5px;
  margin: 5px 10px auto;
}

.article p {
  float: left;
  font-family: Cabin;
  font-size: 18px;
  padding: 5px;
  margin: 5px 10px auto;
  min-width: 50%;
  max-width: 70%;
  display: block;
}

.article img {
  min-width: 20%;
  max-width: 40%;
  float: left;
  height: 120px;
  padding: 5px;
  margin: 5px 10px auto;
}

So; 所以; to be clear... I am wanting it so the image is on the left hand side while the title is to the top right of the image and the text is under the header. 要清楚...我想要它,以便图像位于左侧,而标题位于图像的右上方,文本位于标题下方。 It looks ok until the browser window gets smaller and the text goes under the image. 看起来不错,直到浏览器窗口变小并且文本进入图像下方。 I'm not sure if I'm being stupid and just can't see what's wrong but I've tried some things and still can't get it to work. 我不确定自己是否很愚蠢,只是看不到出了什么问题,但我尝试了一些尝试,但仍然无法正常工作。

Any help is appreciated. 任何帮助表示赞赏。 Thanks. 谢谢。

Use no-wrap: 使用无包装:

.article p
{
    white-space:nowrap;
}

I tested with your code listed above, works perfect. 我使用上面列出的代码进行了测试,效果很好。 Please mark as answer if this helped. 如果有帮助,请标记为答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM