简体   繁体   English

浮动图像,自动换行文本,最小自动换行大小

[英]Float Image, wrap text, minimum wrap size

I have a 320px width image. 我有一个320像素宽的图片。 The image is floated left and the text is wrapped around. 图像向左浮动,文字环绕。 Easy enough. 很简单。 Here is my HTML: 这是我的HTML:

<div>
    <img src="https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png" style="width:320px; float:left; margin:0 10px 4px 0;">
    a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg a bb ccc ddd eeee fffff gggggg  
</div>

The issue: 问题:

When the window is sized to 321-400-ish pixels, it looks weird. 当窗口的大小设置为321-400像素时,它看起来很奇怪。 The little words kind of float right and stick to the top, but it just looks bad. 这些小词会向右浮动并停留在顶部,但看起来很糟糕。 What I want, is to define a minimum width for the text (to the right only), say 100 pixels. 我想要的是定义文本的最小宽度(仅在右侧),例如100像素。 So 100px wide wraps down the right, then 420 pixels wide under the floated image. 因此,100px宽环绕右移,然后在浮动图像下宽420像素。

So, if the screen is 320px, image on top, text below. 因此,如果屏幕为320像素,则图片在顶部,文字在下面。

If the screen is 370px, image on top, text below. 如果屏幕为370像素,则图片在顶部,文字在下面。

If the screen is 420px+, image floated left, text wrapped around, to the right and under. 如果屏幕为420px +,则图像向左浮动,文字环绕在右侧和下方。

I hope that's clear enough. 我希望这很清楚。 I've been trying various combinations of float and flexbox without the desired result. 我一直在尝试float和flexbox的各种组合,但均未获得理想的结果。

I'm not looking for a complex javascript screen-resolution size-adjusting solution. 我不是在寻找复杂的javascript屏幕分辨率大小调整解决方案。 I could write that up and change the code based on screen size... But that's not how I'd like to tackle this issue. 我可以写出来并根据屏幕大小更改代码...但是那不是我想要解决的问题。 I'm just looking for a simple CSS solution. 我只是在寻找一个简单的CSS解决方案。

Thank you 谢谢

😊 😊

Edit: 编辑:

Here's a fiddle . 这是一个小提琴

Resize the window, so only the a and bb show on the right. 调整窗口大小,以便仅在右侧显示a和bb。

Use CSS for the screen resolution with media styles. 将CSS用于具有媒体样式的屏幕分辨率。

@media screen and (max-width: 420px) {
img {
   float:none !important;
}}

if the screen size is below 420 the css in the block will apply. 如果屏幕尺寸小于420,则将使用该块中的CSS。

https://jsfiddle.net/manukarki/12syovj0/2/ https://jsfiddle.net/manukarki/12syovj0/2/

Use media query. 使用媒体查询。

img{
  width:320px; 
  float:left; 
  margin:0 10px 4px 0;
}
@media only screen and (max-width:370px){
  img{
    float: none;
  }
}

And your question isn't clear. 您的问题还不清楚。 You said you want image only <370px and image+text >470. 您说您只希望图像<370px和图像+文本> 470。 What about the res inbetween them? 他们之间的资源如何?

And 370 isn't going to give you desired result. 370不会给您想要的结果。 420px is the way to go. 420px是要走的路。

@media only screen and (max-width: 420px){

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

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