[英]CSS: How the backgrounds can extend the border and overlap?
I'm designing a navigation bar as shown in image below (a) with the following code:我正在设计一个导航栏,如下图(a)所示,代码如下:
<ul>
<li class="unselected">Step 1</li>
<li class="selected">Step 2</li>
<li class="unselected">Step 3</li>
<li class="unselected">Step 4</li>
<li class="unselected">Step 5</li>
</ul>
I want to have one background image for unselected steps (d) and one for the selected step (c).我想为未选择的步骤 (d) 设置一个背景图像,为选定的步骤 (c) 设置一个背景图像。 For simplicity let's assume Step 1 and Step 5 use the same background as well.为简单起见,我们假设步骤 1 和步骤 5 也使用相同的背景。 I want to adjust the button background in HTML only with a class name.我想仅使用 class 名称调整 HTML 中的按钮背景。
The question is how can I achieve the result with CSS?问题是如何使用 CSS 实现结果? I just want to know how background of two neighbor elements can overlap each other ?我只想知道两个相邻元素的背景如何相互重叠?
Edit: the steps are links.编辑:步骤是链接。 the background is a transparent PNG file preferably only containing the blue or gray shape and its border.背景是透明的 PNG 文件,最好只包含蓝色或灰色的形状及其边框。
Answer: http://jsfiddle.net/morrison/99LhB/答案: http://jsfiddle.net/morrison/99LhB/
Notes:笔记:
You can do this.你可以这样做。 what you want to do is use a negative margin.你想要做的是使用负边距。
.someclass {
margin-left: -5px;
}
That should overlap the each of the elements (if applied to all li objects).这应该与每个元素重叠(如果应用于所有 li 对象)。
They can't overlap only the background, but html element might be stacked.它们不能只与背景重叠,但 html 元素可能会堆叠。 However I'd recommend such a solution only if you have no other.但是,仅当您没有其他解决方案时,我才会推荐这样的解决方案。
In your visual example, I guess that must be something like that:在您的视觉示例中,我想一定是这样的:
Html: Html:
<ul>
<li class="before_selected">Step 1</li>
<li class="selected">Step 2</li>
<li class="after_selected">Step 3</li>
<li class="unselected">Step 4</li>
<li class="unselected">Step 5</li>
</ul>
CSS: CSS:
.unselected {
background-image: url('all_grey.jpg');
}
.before_selected {
background-image: url('left_grey_right_blue.jpg');
}
.after_selected {
background-image: url('left_blue_right_grey.jpg');
}
.selected {
background-image: url('all_blue.jpg');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.