1

I did not find any answer for my question, even if it is really simple. I am using the CSS proprety box-sizing to do an "inside border" for a div (which is actually a <a>...</a>)

.myDiv{ 
       box-sizing: border-box; 
       -moz-box-sizing: border-box; 
       -webkit-box-sizing: border-box;
       border: 2px solid #3498db;
}

But it seams that it is not working at all as the border is the same without border-box properties. Anyone has an answer?

Just to be sure of what I am doing. What I want is to get a <a> an "inside border". I obviously know the border: ...; property but it is making the element bigger and I don't want that. I would like to have something like border: -2px solid #3498db.

[EDIT] I found a solution. Description on the comments.

jseiller
  • 222
  • 2
  • 16

2 Answers2

1

The easy way is to put a <span> inside the <a> and then put a border on the <span>. Then put the nessesary padding/margin on, either the <a> or the <span>.

Adrian Roworth
  • 813
  • 1
  • 7
  • 16
  • Thanks for your answer. It will not solve my problem but it will surely help me in the future. Thanks ! – jseiller Nov 06 '13 at 22:58
1

Using box-sizing: border-box on an inline element with no width will not make the border internal to the elements size.

Instead you can use the :after pseudo element to make the border over the top of the element.

HTML

This is some <span class="textBorder">text</span> and then some more.

CSS

.textBorder {
    background: #ffff99;
    position: relative;
}
.textBorder:after {
    content: " ";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 1px solid rgba(0,0,0,0.5);
}

Demo

3dgoo
  • 15,716
  • 6
  • 46
  • 58