CSS 技巧用空白覆盖其他 div 边框?
我将如何去做像这张照片这样的事情?
我尝试为 li
提供背景,将其 1px
放置在右侧,并增大 z-index
>,但没有有用。
我还想到了为 li
提供边框并隐藏活动边框的想法,但我需要边框与右侧的内容一样长。
How would I go about doing something like on this picture?
I have tried giving the li
a background, positioning it 1px
to the right and greater z-index
, but to no avail.
I also got the idea to give border to the li
's and hide the border of the active one, but I need the border to be as long as the content on right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
以下内容基于约翰的解决方案,并且还扩展了边框的高度以匹配内容的高度。
HTML:
CSS:
示例此处。
The following builds on John's solution and also expands the height of the border to match the height of the content.
HTML:
CSS:
Example here.
您可以这样做...
只要包含的
ul
具有overflow: hide
。You can do this...
So long as the containing
ul
hasoverflow: hidden
.尝试其中之一:
try one of these:
我实现了这种效果,我给每个列表项一个右边框,但对于选定的列表项,我将
border-color
更改为白色。但是,如果您希望右边框扩展到列表项之外,则需要在
ul
上设置边框的高度,并为列表项添加 1px 负边距。例如这个标记
和这个CSS
将实现这个结果 - http://jsfiddle.net/ajcw/3VMyY/
I achieve this effect I give each of my list items a right border, but for the selected list item I change the
border-color
to white.However if you want the right border to expand beyond the list items you need to set the border on the
ul
with a set height, and add a 1px negative margin to the list items.For example this mark-up
And this CSS
Will achieve this result - http://jsfiddle.net/ajcw/3VMyY/
我认为重叠可以用 li 内的另一个 div 来完成,位置相对,向右移动。但随后您必须根据所选项目显示/隐藏它。
I think the overlapping could be done with another div inside li, with position relative, shifted to the right. But then you have to show/hide it based on selected item.