gpt4 book ai didi

html - ":after"元素的高度和宽度是如何确定的?

转载 作者:行者123 更新时间:2023-11-28 05:23:41 25 4
gpt4 key购买 nike

<分区>

目前正在修复现有网站。用户报告了包含图像的链接实际上包含了整个父 div 的问题。

我在这里创建了一个示例:http://jsfiddle.net/WW3bh/25913/

.img-span {
display: block;
width: 100%;
/*position: relative;*/
}

.img-span:after {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1;
display: block;
background-color: transparent;
transition: all .3s ease
}

.img-span:hover:after {
background: rgba(0, 154, 228, 0.6)
}
<div class="wrap">
<h1>Test Page</h1>
<div class="rich-text-editor">
<div class="wrap">
<p>
and feel the charm of existence in this spot, which was created for the bliss of souls like mine. I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing
a single stroke at the present moment; and yet I feel that I never was a greater artist than now. When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees,
and but a few stray gleams steal into the inner s
</p>
<a href="http://google.com">
<div class="image-wrap">
<span class="img-span">
<img alt="" src="http://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png">
</span>
</div>
</a>
<p>
odo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla
vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.
Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutr
</p>
</div>
</div>
</div>

这个“:after”部分我不完全理解。我知道它会在容器内创建伪元素,但不了解顶部/左侧/右侧/底部。

将宽度和高度设置为 .image-wrap div 将解决此问题,但这需要始终在 img 标签周围有一个包装器。

我希望找到另一种方法来创建一个层,该层不响应其父级的宽度和高度,而是响应子级。

谁能解释一下如何根据上述 css 代码计算后区域的高度和宽度?

编辑

现在理解了top/left/right/bottom只是定义width和height为100%(他们为什么不直接使用width height 100%?)

了解到问题是 img-span 的位置是静态的,这就是为什么 img-span:after 不将其视为父级,而是向上寻找父级。如果 img-span 设置为相对位置,问题就会消失。不是 CSS 专家,这会导致任何副作用吗?

注意:在我的电脑上,jsfiddle 中的前几行 css 行没有应用到 html,这是我的错误还是每个人的错误? 默认情况下误导 CSS 中的 Jsfiddle 注释符号"//"...

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com