正当项目如何在显示器上工作:块元素 [英] How does justify-items work on display:block elements

查看:74
本文介绍了正当项目如何在显示器上工作:块元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

justify-items MDN文档指出:

在块级布局中,它将内联轴上的包含块内的项目对齐.

现在,我认为此属性仅应在display:flexdisplay:grid元素中使用,但规范指出可以在所有元素上使用.

所以我想尝试一下它如何与display:block一起工作,但是不幸的是,我无法使其以任何方式工作.它什么都不做.

所以我的问题是:有人可以提供一个示例如何在display:block元素上使用justify-items吗?

解决方案

但是规范指出它可以在所有元素上使用.

否,这不是规范.规格如下: https://drafts.c​​sswg.org/css-align-3/#propdef-justify-items ,您会注意到它仍然是草稿.所以是的,它意味着可以使用所有元素,但还不能.

这是编辑草稿的公开副本. 仅供讨论,可能随时更改.它在此处发布并不意味着W3C认可其内容.除了正在进行的工作外,请勿引用此文档.


CSS级别1和2允许通过text-align对齐文本和通过平衡自动页边距来对齐块.但是,除了表格单元格以外,无法进行垂直对齐.随着CSS添加更多功能,在各个维度上对齐框的能力变得越来越重要. 此模块尝试创建一个内聚的通用框对齐模型,以在所有CSS之间共享.

实际上,仅在您知道的Grid和Flex布局内才支持它.这是在它们各自的规范中描述的,而不是上面的描述:

https://www.w3.org/TR/css-flexbox- 1/

https://www.w3.org/TR/css-grid- 1/


您还可以在中查看MDN链接浏览器兼容性部分,您将发现仅支持Grid和Flex布局.


MDN是很好的参考,但是您需要能够遵循最后提供的规范链接以获取完整的信息.

The MDN documentation of justify-items states that:

In block-level layouts, it aligns the items inside their containing block on the inline axis.

Now, I thought that this property is intended to be used only in display:flex or display:grid elements, but the specification states that it can be used on all elements.

So I wanted to try out how does it work with a display:block, but unfortunately I can't make it work in any way. It just does nothing.

So my question is: can someone please provide an example how justify-items can be used on a display:block element?

解决方案

but the specification states that it can be used on all elements.

No, this is not the specification. Here is the specification: https://drafts.csswg.org/css-align-3/#propdef-justify-items and you will notice that it's still a draft. So yes it's meant to work with all elements but not yet.

This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.


CSS Levels 1 and 2 allowed for the alignment of text via text-align and the alignment of blocks by balancing auto margins. However, except in table cells, vertical alignment was not possible. As CSS adds further capabilities, the ability to align boxes in various dimensions becomes more critical. This module attempts to create a cohesive and common box alignment model to share among all of CSS.

Actually, it's only supported inside Grid and Flex layout like you know. This is described in their respective Specifications not the above one:

https://www.w3.org/TR/css-flexbox-1/

https://www.w3.org/TR/css-grid-1/


You can also check the MDN link in the browser compatibility section and you will find support for only Grid and Flex layout.


The MDN is a good reference but you need to be able to follow the specification links provided at the end to have a complete information.

这篇关于正当项目如何在显示器上工作:块元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆