Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial Border in CSS

Tags:

html

css

I have two divs with borders as the picture below shows.

enter image description here

How do I remove only the border where the 2 divs touch like the picture below shows?

enter image description here

Here is the html and css used in the top picture (js fiddle: http://jsfiddle.net/paulyoder/whsC4/19/)

<html>
    <head>
        <style type="text/css">
            #sideBar {
                float: left;
                width: 75px;
                height: 50px;
                border-top: 1px solid black;
                border-left: 1px solid black;
                border-bottom: 1px solid black
            }

            #balanceSheetSummary {
                float: left;
                width: 150px;
                height: 150px;
                border: 1px solid black;
            }

            body { padding: 10px; }
            h2 { margin: 5px; }
        </style>
    </head>
    <body>
        <div id="sideBar">
            <h2>Side Bar</h2>
        </div>
        <div id="balanceSheetSummary">
            <h2>Content</h2>    
        </div>
    </body>
</html>
like image 944
Paul Avatar asked Dec 02 '11 14:12

Paul


People also ask

How do you color a half border in CSS?

Use two gradients: one rotated 90deg and the other rotated -90deg. Use two color stops: #880015 at 50% and #fff at 50% Use a background-size of 100% width and 3px in height, i.e. background-size: 100% 3px. Position the two backgrounds at the top left and bottom left of your element.

Can you have 2 borders CSS?

Introduction to CSS Multiple Borders. Multiple borders in CSS can be done by box-shadow property. Generally, we can get a single border with border property. Box-shadow property is not for multiple borders, but still, we are creating multiple borders with box-shadow property.

How do I remove part of a border in CSS?

We can specify the no border property using CSS border: none, border-width : 0, border : 0 properties. Approach 1: We will give border-color, border-style properties to both headings, for showing text with border and no-border. For no border heading, we will use the border-width : 0 which will result in no border.


1 Answers

You could do something like this: http://jsfiddle.net/sj2AD/1/

#sideBar {
   float: left;
   width: 75px;
   height: 50px;
   border-top: 1px solid black;
   border-left: 1px solid black;
   border-bottom: 1px solid black;
   background: red;
   position: relative;
   z-index: 2;
}

#balanceSheetSummary {
   float: left;
   width: 150px;
   height: 150px;
   border: 1px solid black;
   background: red;
   position: relative;
   z-index: 1;
   margin-left: -1px;
}

body { 
   padding: 10px; 
}
h2 { 
  margin: 5px; 
}

What I did was to add a negative margin to the right one so that the boxes overlap.

This does break, for example if the left div is higher than the right one.

like image 68
Filip Avatar answered Sep 24 '22 19:09

Filip