【问题标题】:Can't get margin-bottom to work on search box?无法让 margin-bottom 在搜索框上工作?
【发布时间】:2015-09-15 10:13:41
【问题描述】:

唯一有效的边距属性是我的搜索框上的左边距。当我尝试添加底部边距时,搜索框不会移动。然后我尝试将显示更改为“阻止”,但搜索框一直移动到我的屏幕左侧,并一直卡住。

是否可以腾出边距以便我可以在屏幕周围 360 度移动我的搜索框?

这是卡在左边距的代码:

<input class="search" type="text" name="q" id="q" size="40" maxlength="50" style=  "display:block; position:relative;margin-left:-15%";>

这里是代码:https://jsfiddle.net/4d4c2zdn/1/

【问题讨论】:

  • 如果您使用内联样式,style= "display:block"; "position:relative";"margin-left:-15%"; 无效。应该是:style="display:block; position:relative; margin-left: -15%;"
  • 我修好了,但margin-bottom仍然无法正常工作。
  • 搜索框卡住了,动不了了。
  • margin-bottom 正在工作,但是给 3000px ,你会看到滚动条从底部移动到 3000px 位置...
  • 最好在这个上创建一个小提琴或一个 sn-p

标签: javascript jquery html css


【解决方案1】:

您是否知道您的 margin-left 被赋予了一个负值? margin-bottom 只会在布局中将其下方的东西向下推。您要向上移动搜索框吗?

当使用position:relative; 相对定位元素时,您也可以使用left:15%;right: -15%; 等基本定位。这应该可以释放您的利润。

I made a pen to better explain the situation.

【讨论】:

  • 是的,我知道负值。我正在尝试将搜索框向下推,但它不适用于 margin-bottom。我对它进行了更多的修改,只有 margin-top 和 margin-left 有效。 Margin-bottom 和 Margin-right 不起作用。矛盾的是,“左”、“右”、“上”和“下”确实有效,只要我不在那里设置边距。知道这是为什么吗?
  • 这提供了一个很好的解释:stackoverflow.com/questions/6419411/…
猜你喜欢
  • 1970-01-01
  • 2014-04-05
  • 2019-02-24
  • 2011-07-07
  • 1970-01-01
  • 2010-09-22
  • 2021-12-10
  • 1970-01-01
相关资源
最近更新 更多