Css 这些复选标记是如何绘制的?
我在阅读有关CSS的MDN参考站点中的伪元素,在中,他们使用了一个简单的待办事项列表作为示例。其代码如下: HTML JavascriptCss 这些复选标记是如何绘制的?,css,Css,我在阅读有关CSS的MDN参考站点中的伪元素,在中,他们使用了一个简单的待办事项列表作为示例。其代码如下: HTML Javascript var list = document.querySelector('ul'); list.addEventListener('click', function(ev) { if( ev.target.tagName === 'LI') { ev.target.classList.toggle('done'); } }, false);
var list = document.querySelector('ul');
list.addEventListener('click', function(ev) {
if( ev.target.tagName === 'LI') {
ev.target.classList.toggle('done');
}
}, false);
我了解Javascript代码的功能,我希望复选标记是图像,但它们是由CSS代码绘制的。我能看到关于画什么和如何画的说明在哪里,但我不能理解这些说明
我也不知道如何用谷歌搜索它(因为我不知道CSS中这项技术的名称),所以我真的被困在这里了。它是如何工作的?li.done::before规则基本上是创建一个空白框(
内容:”;
),然后设置右边距和底部边距的样式(0.3em 0.25em 0;
),然后将其旋转45度(变换:旋转(45度);
)做一个复选标记。li.done::before规则基本上是创建一个空白框(内容:”;
),然后设置右边距和底部边距的样式(0.3em 0.25em 0;
),然后将其旋转45度(变换:旋转(45度);
)做一个复选标记。li.done::before规则基本上是创建一个空白框(内容:”;
),然后设置右边距和底部边距的样式(0.3em 0.25em 0;
),然后将其旋转45度(变换:旋转(45度);
)做一个复选标记。li.done::before规则基本上是创建一个空白框(内容:”;
),然后设置右边距和底部边距的样式(0.3em 0.25em 0;
),然后将其旋转45度(变换:旋转(45度);
)做一个复选标记。我怀疑旋转角度应该是45度
,而不是135度
。它是在右侧和底部提供一个边框,并旋转它,其尺寸使高度高于宽度。旋转将向后的L变为复选标记。谢谢@KingKing,它最初是45,我正在更改值以查看是否能找到答案。我怀疑旋转角度是否应该是45度
,而不是135度
。它是在右侧和底部添加边框并旋转,以及使高度高于宽度的尺寸。旋转将向后的L变为复选标记。谢谢@KingKing,它最初是45,我正在更改值以查看是否能找到答案。我怀疑旋转角度是否应该是45度
,而不是135度
。它是在右侧和底部添加边框并旋转,以及使高度高于宽度的尺寸。旋转将向后的L变为复选标记。谢谢@KingKing,它最初是45,我正在更改值以查看是否能找到答案。我怀疑旋转角度是否应该是45度
,而不是135度
。它是在右侧和底部添加边框并旋转,以及使高度高于宽度的尺寸。旋转将一个向后的L变成一个复选标记。谢谢@KingKing,它原来是45,我正在更改这些值,看看我是否能找到答案。你能更具体地描述一下相对位置吗?你所说的“真正的元素”是什么意思?真正的元素是
。它有位置:relative
,这使得绝对定位(伪或非伪)元素的顶部和左侧属性相对于应用,而不是相对于整个文档。好的,我理解了。非常感谢。你能更具体地描述一下相对位置吗?你所说的“真正的元素”是什么意思?真正的元素是
。它有位置:relative
,这使得绝对定位(伪或非伪)元素的顶部和左侧属性相对于应用,而不是相对于整个文档。好的,我理解了。非常感谢。你能更具体地描述一下相对位置吗?你所说的“真正的元素”是什么意思?真正的元素是
。它有位置:relative
,这使得绝对定位(伪或非伪)元素的顶部和左侧属性相对于应用,而不是相对于整个文档。好的,我理解了。非常感谢。你能更具体地描述一下相对位置吗?你所说的“真正的元素”是什么意思?真正的元素是
。它有位置:relative
,这使得绝对定位(伪或非伪)元素的顶部和左侧属性相对于应用,而不是相对于整个文档。好的,我理解了。非常感谢。
li.done::before { /* This creates a (pseudo) element that is (by default) placed before the content, but is hidden (by default). */
content: ''; /* This makes this (pseudo) element actually appear. */
position: absolute; /* This makes it not push the content or affect it in anyway and also makes it act as if it has some sort of display: inline-block; */
/* These create a right and bottom border and give a width and a height (width * 2) to this (pseudo) element, so you get a reversed L shape. */
border-color: #009933; /*
border-style: solid;
border-width: 0 0.3em 0.25em 0;
height: 1em;
width: 0.5em;
/* These position this (pseudo) element relatively to its real/owner element, the LI, since it has position: relative. */
top: 1.3em;
left: 0.6em;
margin-top: -1em;
/* This rotates this (pseudo) element. When you rotate a reversed L, it looks like a check mark. */
transform: rotate(45deg);
}
var list = document.querySelector('ul');
list.addEventListener('click', function(ev) {
if( ev.target.tagName === 'LI') {
ev.target.classList.toggle('done');
}
}, false);
li.done::before { /* This creates a (pseudo) element that is (by default) placed before the content, but is hidden (by default). */
content: ''; /* This makes this (pseudo) element actually appear. */
position: absolute; /* This makes it not push the content or affect it in anyway and also makes it act as if it has some sort of display: inline-block; */
/* These create a right and bottom border and give a width and a height (width * 2) to this (pseudo) element, so you get a reversed L shape. */
border-color: #009933; /*
border-style: solid;
border-width: 0 0.3em 0.25em 0;
height: 1em;
width: 0.5em;
/* These position this (pseudo) element relatively to its real/owner element, the LI, since it has position: relative. */
top: 1.3em;
left: 0.6em;
margin-top: -1em;
/* This rotates this (pseudo) element. When you rotate a reversed L, it looks like a check mark. */
transform: rotate(45deg);
}