Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulating border-collapse in lists (no tables)

I have always the same problem, when I have 2 adjacent elements with borders, the borders are merged. With tables we have the border-collapse property for solving this.

I've tried omiting the border from one of the sides, but that works only for elements in the middle, the first and final element will miss a border.

Does somebody know a solution for list elements for example?

like image 246
Enrique Avatar asked Apr 20 '11 23:04

Enrique


People also ask

Does border-collapse only work on tables?

border-collapse: collapse | separate; Initial value: separate. Applies to: table and inline-table elements. Inherited: yes.

What is the difference between using border spacing 0 and Border-collapse collapse?

In the separated model, adjacent cells each have their own distinct borders. In the collapsed model, adjacent table cells share borders. The border-spacing CSS property specifies the distance between the borders of adjacent table cells (only for the separated borders model).

Which property is used to specify whether the table borders should be collapsed or not?

The border-collapse property sets whether table borders should collapse into a single border or be separated as in standard HTML.

How do I make a table border none?

Set the CSS border Property to none to Remove Border From a Table in HTML. We can set the border property to none to remove the border from an HTML table. The property is short-hand of different border properties. Those different properties are border-width , border-style and border-color .


2 Answers

Here's how I solved it: add a margin-left/-top of -1px to each li element. Then the borders really collapse without any tricks.

like image 195
Frederick Avatar answered Sep 22 '22 15:09

Frederick


You can add a left and bottom border to the ul and drop it from the li.

fiddle: http://jsfiddle.net/TELK7/

html:

<ul>     <li>one</li>     <li>two</li> </ul> 

css:

ul{     border: 0 solid silver;     border-width: 0 0 1px 1px; } li{     border: 0 solid silver;     border-width: 1px 1px 0 0;     padding:.5em; } 
like image 31
Billy Moon Avatar answered Sep 21 '22 15:09

Billy Moon