[英]div: collapse border + change the color of the border on hover + border radius?
this seam easy but i didn't find yet any way to do it. 这个接缝很容易,但是我还没有找到任何办法。 i have 3 divs (but the solution must work for n divs) like on the schema below : 我有3个div(但解决方案必须适用于n个div),如以下模式所示:
| | div 1 || div 1 || div 2 || div 2 || div 3 | div 3 |
ex: 例如:
i want normal div like this : 我想要这样的普通股利:
on hover of a particular div i want ALL border of this div to have another color like this : 在特定div的悬停上,我希望此div的所有边框具有另一种颜色,如下所示:
and finally, what i can't do, i want corner like it's show here: 最后,我不能做的是,我想要这里显示的角落:
i want first to collapse all the border. 我要首先破坏所有边界。 that easy with border-collapse:collapse. 与border-collapse:collapse一样容易。 but After i want also to change the border color of the full cell on hover (top + left + bottom + right border). 但是之后我还想更改悬停时整个单元格的边框颜色(顶部+左侧+底部+右侧边框)。 that also easy with border: 1px DOUBLE #000. 边框也很容易:1px DOUBLE#000。 But last (i block on this point) i want also a round corner on the top and bottom left of div 1 and on the top and bottom right of the div 3 但是最后(在这一点上我要阻止)我还希望在div 1的左上角和左下角以及在div 3的右上角和右下角有一个圆角
it's look like that with border-collapse:collapse their is no way to have round corner ... so need to find another solution 看起来像border-collapse:collapse他们是不可能有圆角的...所以需要找到另一个解决方案
EDIT: I try with the relative position and z-index and it's work a little better ! 编辑:我尝试使用相对位置和z-index,它的工作效果更好! however i need to know how to move the 2nd div by 1px on the left, the 3th div by 2 pixels on the left, ... and the n div by n-1 pixels on the left? 但是我需要知道如何将第二个div左移1px,将第三个div左移2像素,...和将n div左移n-1像素?
Actually this is a little more complicated than you think. 实际上,这比您想象的要复杂一些。
border-collapse is for tables not for all block elements. border-collapse适用于表,而不适用于所有块元素。 Of course you can still make it work with display:table/table-cell. 当然,您仍然可以使它与display:table / table-cell一起使用。 But the hover will still be flawed since the collapsed border will belong to the first element - if you hover the 2nd or 3rd element the left border won't change. 但是,由于折叠后的边框将属于第一个元素,因此悬停仍会存在缺陷-如果将鼠标悬停在第二个或第三个元素上,则左边框将保持不变。
And only then the lack of border-radius for collapsed border comes into play. 直到那时,缺乏边界半径才使边界崩溃。
I'd say you'll have to go for a different approach. 我想您将不得不采用其他方法。 I'd probably go for inline-block (or probably rather with "old-school" floats to avoid whitespace trouble) elements with the borders overlapping by 1px and a change of z-index in the :hover to bring the hovered element to the top and make sure its border is the one displayed. 我可能会选择内联块(或可能使用“老式”浮点数来避免空格问题)的元素,其边界重叠1px,并在:hover中更改z-index以将悬停的元素带到并确保其边框是显示的边框。
Not really clear what do you want, but just to try 不太清楚您想要什么,而只是尝试
.one { width: 80px; height: 40px; display: table-cell; border-collapse: collapse; border: double 1px black; } .one:first-child { border-top-left-radius: 15px; border-bottom-left-radius: 15px; } .one:last-child { border-top-right-radius: 15px; border-bottom-right-radius: 15px; }
<div> <div class="one"></div> <div class="one"></div> <div class="one"></div> </div>
Is it what you want? 是你想要的吗?
.container { display: table; } .container > div { display: table-cell; width: 80px; height: 40px; text-align: center; vertical-align: middle; border-top: solid 1px gray; border-bottom: solid 1px gray; border-left: solid 1px gray; } .container > div:first-child { border-top-left-radius: 8px; border-bottom-left-radius: 8px; } .container > div:last-child { border-right: solid 1px gray; border-top-right-radius: 8px; border-bottom-right-radius: 8px; } .container > div:hover { background-color: lightgray; border-color: red; border-right: solid 1px red; }
<div class='container'> <div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div> </div>
Here's a solution that solves the two problems: 这是解决两个问题的解决方案:
first-of-type
and last-of-type
and the border-radius
property. 这使用了first-of-type
和last-of-type
以及border-radius
属性。 For the latter, instead of playing with z-indices, what happens is the right border is created and has a color changed. 对于后者,不是玩z索引,而是创建右边框并更改了颜色。 Then, the left-hand border of the next li
is blanked out. 然后,下一个li
的左边框被清空。 Blanking the next li
is done by using the adjacent sibling selector ( +
). 通过使用相邻的兄弟选择器( +
)来清空下一个li
。
Here's a Codepen: http://codepen.io/anon/pen/JoyGxJ 这是一个Codepen: http ://codepen.io/anon/pen/JoyGxJ
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.