- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
让我用以下 HTML 演示问题:
<section style="text-align: center;">
<header style="margin: 0px auto; width: 300px; background: orange;"> </header>
<div>
<article style="overflow-x: auto; width: 100%; background: pink;">
<img src="http://placekitten.com/10000/10" />
</article>
</div>
</section>
其中的“article
”元素;我希望其中的 IMG
元素与页面左侧的距离与 header
元素的距离相同。无论用户调整浏览器的大小如何,我都希望这是真的。
我只想用 CSS 来完成。 您可以添加新元素,但不能在“article
”标签内添加。
我想这即使不是很困难,也是不可能的。我有一些想法,但你能帮忙吗?
最佳答案
calc()
方法这可以通过(实验性的)calc
来完成属性:
div article {
margin-left: calc(50% - 300px/2);
}
在这里您必须输入 <header>
的宽度(在本例中为 300px
),它将自动确定 50% - (width) / 2
是什么是。如果您更改 <header>
的样式,这不会自动更改虽然,和it is not supported in too many browsers .
margin-left
和 left
方法这是一种适用于所有现代浏览器的方法:定义一个 left
定位,然后负左margin
:
div article {
position:relative;
left: 50%;
margin-left: -150px;
}
这首先将元素移动到页面宽度的 50%,然后通过其负边距将其向左移动 150 像素。您必须输入 <header>
的宽度, 比如 calc()
方法,但在这里你必须自己将它除以 2(应该不会太难 :P)
关于html - Margin : auto-ed elements = to padding left of 100%-width overflow item 的左边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21466502/
当我设置 margin-right: 50px;我没有看到任何效果,但是当我替换 margin-right: 50px; 时左边距:50px;或 margin-top: 50px;我确实看到了效果。这
CSS .title{ margin-top: 200px; // does not work! margin-left: 20px; font-weight: bold;
我不知道,但是 li 元素的 margin-top 只有在它大于 h2 元素的 margin-bottom 时才会起作用,我想知道为什么? Test1 Test2 谢谢。 最佳答案 您所描述的听起
我有 2 个 div 的问题 - 两个呈现为 block 的边距均为 15px(顶部 div 有底部边距,底部有顶部),因此我预计两者之间的差距是 30px 而不是 15px,这是正确的假设还是我要疯
我一直以为我了解利润率和负利润率,但显然我不了解!我刚刚开始一个新的设计并且已经遇到了问题。 我有一个 div (hill3Cont) 和另一个嵌套在里面的 div (hill3Hill),这是它们的
我有一系列这样的元素: ... ....... ... ....... h1 上边距为 5px,p 上边距为 10px。但是产生的边距只有 10px。如果我将底部边距增加到 50px,将顶部边距增加
由于 margin-right: auto 和 margin-left: auto 水平居中元素,我希望它们的垂直对应物以相同的方式运行。 但我知道这不会发生,根据 CSS 规范: 10.6.2 In
我在让我的 div 将我的页面向下移动 30 像素/在我的 div 顶部添加边距 30 像素时遇到问题。我的 div 使用 margin auto 在页面中心对齐。 然而,当我尝试添加这行代码时:边距
这个问题在这里已经有了答案: CSS margin terror; Margin adds space outside parent element [duplicate] (7 个答案) 关闭
我有一个 div 在另一个之上。顶部的 div 有 margin-bottom: 10px,底部的 div 有 margin-top: 10px,但两个 div 之间只有 10px 的空间。 实例:h
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 2 年前。 我的 CSS 边距没有按照我想要或期望的方
在此website我正在尝试减少横幅和文本之间ON MOBILE 底部和顶部的边距。 如果您在智能手机和平板电脑上查看,横幅的顶部和底部似乎有一些边距。 这是我的 CSS: .page-id-996
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
这个问题在这里已经有了答案: Why does this CSS margin-top style not work? (14 个答案) 关闭 3 年前。
我是一名优秀的程序员,十分优秀!