html - 尝试使用 CSS 和媒体查询进行 float 更改

标签 html css

我正在尝试使图像 float 在左侧,以便在横向和纵向移动设备上方的所有媒体查询以及移动设备和下方然后图像完全显示 block ,即中心位置。

总结:

移动设备或以下设备(最小设备宽度:320 像素)= 图像为完整 block (中心)

高于 320 像素 = 向左浮动的图像。

虽然我无法让它工作......

这是我的 CSS:

.img-float {
  float:left;margin:0 20px 20px 0;
  }

@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
  .img-float {
   display:block;
   margin-left: auto;
   margin-right: auto;
 }
}

这是标记:

<p>
    <img src="https://dummyimage.com/175x80/000/fff" class="img-float">

    FutureCon put on a great show and they&#8217;re touring the US at the moment with over a dozen different IT Security Events throughout the United States. These events are particularly good for networking and advancing your career.
</p>

我为图像使用类是否做错了?

不确定如何进行这项工作。

感谢所有帮助。

最佳答案

如果图像没有 float ,则 displaymargin 会将其居中。

……但它 float 的。

你也需要阻止它 float :

float: none

关于html - 尝试使用 CSS 和媒体查询进行 float 更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57031583/

相关文章:

html - 带有内联 block 的 CSS Div 元素不起作用

css - 垂直堆叠的 div 之间有空间 (firefox)

css - Chrome Mac 和 Chrome Window 的字体间距不同

javascript - 使用智能手机键盘外观处理绝对布局

html - IE 11 多选溢出时不显示所选值

html - 表格行背景颜色未填满整行

javascript - wkhtmltopdf 不接受网址中的值?

android - phonegap 应用程序中的某些 android 设备不支持输入类型日期

jquery - 侧边菜单中的 HTML 元素未缩放到父级的内容

html - 文本垂直居中对齐 CSS