- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
当使用 top, right, bottom, left
css
值时,为什么有时我可以使用百分比,但有时我必须使用像素 ( px
),否则 元素
不会响应。
例如(在给定元素上):
top: 25%
- 没有响应
top: 150px
- 有效
我通常会使用百分比而不是像素 (px
) 来保持响应,但为什么百分比 (%
) 有时不起作用?每种情况在什么情况下效果最好?谢谢。
最佳答案
根据 the WC3 specification对于百分比单位 ( <percentage>
( ref )):
Percentage values are always relative to another value, for example a length unit.
长度单位 ( <length>
( ref )) 是一种 CSS 数据类型,表示距离值,或以相对 ( em
) 或绝对 ( px
) 长度单位定义的值。
百分比单位 ( <percentage>
( ref )) 是一种表示百分比值的 CSS 数据类型。
top: 50%
)值,则在嵌套元素上使用的
百分比单位(例如:height: 200px
)将不适用已定义,因为百分比值总是相对于另一个值。
可以在下面嵌入的代码片段中观察到这种行为。
代码片段演示:
.fixed-height {
height: 200px;
background: #4cbd2f;
}
.auto-height {
background: #d04f38;
}
.nested {
top: 50%;
position: relative;
}
hr {
border: 2px dashed #d4d4d4;
margin: 25px 0px;
}
.fixed-height, .auto-height {
padding: 10px;
box-sizing: border-box;
border: 2px dashed rgba(0, 0, 0, 0.3);
}
<h3>Fixed Height</h3>
<h4><code>height: 200px</code></h4>
<div class="fixed-height">
<div class="nested"><code>top: 50%</code></div>
</div>
<hr>
<h3>Auto Height</h3>
<h4><code>height: auto</code></h4>
<div class="auto-height">
<div class="nested"><code>top: 50%</code></div>
</div>
如上面的代码片段所示,百分比值 将取决于长度值。因此,尽管两个嵌套元素都有一个 top
50%
的属性(property)声明,只有嵌套在包含元素中的元素带有 height
使用 length 值明确定义的属性将产生预期的行为。
Note: Although
<percentage>
values are also CSS dimensions, and are usable in some of the same properties that accept<length>
values, they are not themselves<length>
values. ref
Note: Only calculated values can be inherited. Thus, even if a percentage value is used on the parent property, a real value (such as a width in pixels for a
<length>
value) will be accessible on the inherited property, not the percentage value. ref
关于css - 使用 'px' 与 '%' 时顶部、右侧、底部、左侧 css 值的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47580928/
我正在尝试向图像顶部和底部的 ImageView 添加渐变。我不想在 ImageView 之上添加 TextView 。我该如何实现? 最佳答案 看来您简单而干净的解决方案是用 FrameLayout
我可以寻求帮助吗, 我有日期 - “公司名称”和“日期”,例如 $value |"Comp Name"| "Date" | |:----------|----------:| |computer
我有两个表,我试图从中运行查询以返回每个人的最大(或最高)交易。我应该注意,我无法更改表结构。相反,我只能拉数据。 人 +-----------+| id | name |+-----------+|
所以我有一个用管道打开的 n 个流的数组,但是使用 gdb,我发现当我尝试关闭流或管道的写入端时程序失败。我可以很好地写入管道,但关闭它们不起作用。我在程序上运行 valgrind,它所做的只是打印出
大家好,这是我的难题。我正在尝试创建一个标签栏,该标签栏从上到下锚定在左侧,而不是从左到右锚定在底部。我创建了一个工具栏项目,将栏准确地放置在我想要的位置,但我希望选项卡栏相同,具有相同的功能,当然除
http://jsfiddle.net/GuXQZ/3/ header slideshow lates Content
我的图片出了点问题,我无法解决这个问题。这是我的代码.. HTML HIDE CSS #ads { -webkit-border-bottom-right-r
我有一个包含 3(css 网格)列的设计。第二列有嵌套的网格内容需要垂直滚动,而其他两列保持各自的高度。我给第二个嵌套列一个溢出,但我还需要给它一个顶部和底部填充或边距。我的解决方案没有顶部/底部填充
我在 View 中有两个 UIToolbar,分别在顶部和底部。我正在尝试在 iOS 版本中一致地应用外观。从 iOS5 开始有这个 setBackgroundImage: forToolbarPos
一个 div 我使用 top:-26px; 在 css 中设置高度。我有其他 div 其他地方我想与那个 div 对齐。我注意到在 jquery 中编写 .css('top') 得到了我的 css 而
我有这个无序列表 two three 有没有一种方法可以将无序列表添加到无序列表的前面,使其像这样结束? ONE two three 请注意“ONE”已添加到列表
我想检测鼠标何时离开顶部的视口(viewport)(可以说是向北)。我在网上搜了下How can I detect when the mouse leaves the window? .是一个好的开始
运行顶级命令top -c在 Ubuntu 服务器上显示当前正在运行的所有命令。关于 PostgreSQL 命令,括号中的值是什么意思?我说的是图片中红色框旁边的值。 最佳答案 我找不到任何文档来支持这
我想知道将顶部和底部边距添加到 GtkTextView 的正确且普遍接受的方法位于 GtkScrolledWindow 内.有设置左右边距的功能,我正在使用: gtk_text_view_set_le
作为很多“初学者”,我认为使用 TOP_OF_PIPELINE 作为 dst 和 BOTTOM_OF_PIPELINE 作为 src 意味着 ALL_COMMANDS 两者。 Here Nicol B
我正在尝试使用 jQuery/Javascript 解决这个问题: 当浏览器向下滚动且窗口底部到达页脚 DIV 顶部时,执行 CSS 代码更改。 问题示例: https://elodywedding.
我想使用范围 slider 来选择一个值并将该值呈现在 Angular 中的范围选择器顶部。我的html代码是: Raio: {{raio}} metros 在我的 co
我想将手的图片放在靠近脸部的黑色 Canvas 上。这可以吗?有没有办法确定图片的位置? 这是我的代码: var canvas; var canvasContext; window
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我是一名优秀的程序员,十分优秀!