css 媒体查询 margin-top 元素 div

标签 css media-queries margin

我有以下 javascript 。我想更改 div 元素的 margin-top 和 margin-left。我使用这个媒体查询

@media screen and (max-width:1024px) {
  .my-list {
    margin-top: 120px;
    margin-left: 350px;
  }
}
<div class="my-list">
  test message
</div>

最终画面是

enter image description here

如何更改 div 元素的 margin-top 和 margin-left?

最佳答案

I want to change the margin-top and margin-left of a div element

您所做的是正确的。现在这取决于您的要求。根据您的媒体查询,它将为小于 1024 像素的所有分辨率屏幕应用 css。

因为您在媒体查询中应用了:max-width:1024px。现在,如果你想设置高于 1024,那么你可以使用 'min-width: 1024px'

检查 this fiddle 。行得通

关于css 媒体查询 margin-top 元素 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42619314/

相关文章:

html - 隐藏表单标签会影响 Web 可访问性吗?

专门针对平板电脑的 Css 媒体查询

html - Bootstrap移动端断点展开nav

css - 媒体查询不适用于 Safari,但适用于 IE、Firefox 和 Chrome

CSS - 将 div 推到右侧 float 内容下方

html - 更改 <select> 选项默认颜色

css - 行高属性是否继承自body

html - 将父 div 相对的 div 居中

python - 如何从PDF中删除边距? (使用 Wea​​syPrint 生成)

twitter-bootstrap - 更改 Bootstrap 表单输入文本区域的颜色?