媒体查询图像无法正常工作

在我的项目中,如果屏幕尺寸达到一定宽度,我想移动图像。目前,图片停留在静态位置,我不确定为什么。

这是我的代码:

 <div style="height: 630px; width: 350px;" class="formContainer" >

CSS:

 @media screen and (max-width: 1332px) {
     .formContainer {
         left: 100;
         top: 40px;
     }
}

但是,如果我将left属性设置为0,则div会移动,但是我不想将div移得那么远。有人知道这个问题吗?

elle_131 回答:媒体查询图像无法正常工作

此代码段可以为您指明正确的方向:

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

首先,您没有为.formContainer { position: relative; // position is 'static' by default left: 100px; // you missed unit here (was 'left: 100') top: 40px; } 属性指定单位。当您使用值left时,确实可以忽略单位,因为任何单位的零仍然只是零。如果您使用非零值(例如0),则需要指定单位,因为现在无论是100还是100px都会有所不同。

第二,该位置默认为100remstaticleft对静态定位的元素没有任何影响。对于您的用例,我认为top位置比较合适。

本文链接:https://www.f2er.com/3121934.html

大家都在问