Click here to Skip to main content
13,195,564 members (66,036 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

57.4K views
1 bookmarked
Posted 22 Aug 2013

HTML element inner border

, 22 Aug 2013
Rate this:
Please Sign up or sign in to vote.
How to make HTML element border that takes inner space of element rectangle.

Problem  

By default HTML element border is placed outside of element content. This is described in CSS box model: 

But I've stumbled with case where new additional space outside element was undesirable. So border must be placed inside element's content. 

Solution 

CSS3 box-shadow property can set shadow inside of element. So you can simulate border using shadow:

div
{
   width: 300px;
   height: 100px;
   background-color: gray;
   border: 5px solid red;
   box-shadow: 0 0 0 5px blue inset;
}

Result is:

Gray - element content, red - standard border, blue - inner border (shadow). So element space is taken by  gray area plus blue shadow border. And red border takes additional (undesirable) space outside. 

Conclusion

You can use CSS3 box-shadow to get effect of inner border. But I believe that another techniques exist to get the same result.

Resources 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

savbace
Software Developer
Ukraine Ukraine
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 4 Pin
DrABELL22-Aug-13 6:47
professionalDrABELL22-Aug-13 6:47 
GeneralRe: My vote of 4 Pin
savbace22-Aug-13 10:03
membersavbace22-Aug-13 10:03 
GeneralUseful... Pin
roberto galbiati22-Aug-13 6:20
memberroberto galbiati22-Aug-13 6:20 
GeneralI know i'll need it ... Pin
Adam R Harris22-Aug-13 5:38
memberAdam R Harris22-Aug-13 5:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171019.1 | Last Updated 22 Aug 2013
Article Copyright 2013 by savbace
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid