Fork me on GitHub

26 Mar 2011

CSS box model hacking

Want to make an HTML element fill 100% of its parent’s width but also give it a border and/or some padding? Since the width of an element is exclusive of its border and padding this can be a pain. However there’s a fairly simple CSS solution that works cross-browser.

Here’s an example. Both input boxes are set to width: 100% and have padding: 5px. The first input shows the problem. Because the padding and border are added to the width of the element it overflows its container. The box model of the second input has been modified so that the padding and border are inside the declared width.

The trick to modifying the box model is to set box-sizing: border-box. Unfortunately that’s not a cross-browser property, only Opera supports it at the moment. To get the same effect in other browsers you will also need to set browser-specific versions as well:

   -moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
    -ms-box-sizing: border-box;
        box-sizing: border-box;
Note that Internet Explorer only supports the -ms-box-sizing property from version 8 upwards so you should probably be judicious with this technique or use an alternative method to get a similar effect in IE7 and below.

38 comments:

chicago stemcell therapy said...

Thank you for sharing. I found this post to be very informative and helpful.
Platelet Rich Plasma Therapy
Elbow Surgery
Hip Replacement Surgery
Shoulder Surgery
Knee Replacement Surgery
Stem Cell Therapy

Bella Tran said...

A good website is very important in promoting anything
juegos kizi | juegos kizi | jogos do friv | jogos de friv | clickjogos | juegos de pou | juegos de terror | jogos online gratis | unblocked games | baixar facebook | baixar mobogenie | descargar mobogenie | agario | five nights at freddy's 4 | h1z1 | Gmod

الصفوة جروب said...

شركة امست للتنظيف افضل شركة لتنظيف المنازل والشقق والفللوالبيوت والمجالس والكنب والمفروشات والخزانات بالقطيف والمنطقة الشرقية لديها عمالة مدربة وخصومات هائلة طما توفر خدمات مكافحة الحشرات ورش المبيدات بالقطيف باسعار رخيصة ومناسبة وخصومات هائلة

شركة امست للتنظيف
امست للنظافة القطيف
شركة امست لمكافحة الحشرات
شركة امست لرش المبيدات

abo-bder said...


نقل اثاث من الرياض الى الامارات
شركة شحن اثاث من السعودية الى الامارات

cynthiawilliams said...

Learned a lot from your blog. Good creation and hats off to the creativity of your mind. Share more like this.
ccna Training institute in Chennai
ccna institute in Chennai
DevOps Training in Chennai
AWS Training in Chennai
Angularjs Training in Chennai
RPA Training in Chennai

Sai Elakiyaa said...

Thank you for sharing such valuable information and tips. This can give insights and inspirations for us; very helpful and informative! Would love to see more updates from you in the future.


Selenium Training in Chennai
software testing selenium training
ios developer course in chennai
Digital Marketing Course in Chennai
PHP Course in Velahery
PHP Course in Adyar

Anbarasan14 said...

Thanks for your efforts in sharing this information in detail. This was very helpful to me. kindly keep continuing the great work.

Best IELTS Class in Chennai
Best IELTS Courses in Chennai
IELTS Course in Chennai
IELTS Class near Chennai
IELTS Center in Mumbai
IELTS Training in Mumbai
Best IELTS Coaching Classes in Mumbai

Aruna Ram said...

Great post, this is awesome and very creativity content. I really impressed. I want more updates.......
CCNA Training Center in Bangalore
Best CCNA Training Institute in Bangalore
CCNA Certification in Bangalore
CCNA Course in Vadapalani
CCNA Training in Nungambakkam
CCNA Course in Kodambakkam

Unknown said...

Nice post. By reading your blog, I get inspired .. Thank you for posting.

Informatica Training in Chennai
Informatica Training Center Chennai
Informatica Training Institute in Chennai
Best Informatica Training in Chennai
Informatica course in Chennai
Informatica Training center in Chennai
Informatica Training
Learn Informatica

Harish said...

It is an interesting topic you have discussed here. Keep updating more like this.

VMware course
Best VMware Training Institute in Chennai
Vm Training
Vmware Cloud Training
Vmware Training Courses
Best VMware Training Institute in Tambaram
Best VMware Training in Adyar
VMware course in Velachery


Gaming Lover said...

Merry Christmas & Happy New Year
Happy New Year Quotes 2019
Merry Christmas & Happy New Year 2019
Happy New Year Messages Poetry 2019
Happy New Year Resolution 2019
Happy New Year Resolutions 2019
Happy New Year Gift Ideas 2019
Happy New Year Wallpapers 2019

Check Also Today Live Match
Today Live Match Streaming
Today Live Match Prediction
World Cup Live Streaming

LindaJasmine said...

Amazing Blog. The liked your way of writing. It is easy to understand. Waiting for your next post.
Node JS Training in Chennai
Node JS Course in Chennai
Node JS Advanced Training
Node JS Training Institute in chennai
Node JS Training Institutes in chennai
Node JS Course
Informatica Training in Chennai
Informatica Training center Chennai
Informatica Training Institute in Chennai

priya rajesh said...

Thanks for sharing this information admin, it helps me to learn new things. Continue sharing more like this.
Spring Training in Chennai
Hibernate Training in Chennai
Struts Training in Chennai
Robotics Process Automation Training in Chennai
AngularJS Training in Chennai
AWS Training in Chennai
DevOps Training in Chennai

jefrin said...

Awesome post thanks for posting
Tableau training class in chennai

Softlogicseo said...

Very good to read

Tableau training course in chennai

nandhu said...


kingroot install
new kingroot
kingroot pc
kingroot android
They have grown quite refined over the years, progressing from brute force hacks to elaborate cloud-based applications that scan your device and automatically source the best root method for it from a database.

Sasi Surendher said...

This is really too useful and have more ideas and keep sharing many techniques. Eagerly waiting for your new blog keep doing more.
Regards,
Tableau training in Chennai | Tableau Courses Training in Chennai | Tableau training Institute in Chennai

Nisha San said...


Thanks for sharing the knowledgeable stuff to enlighten us no words for this amazing blog.. learnt so many things I recommend everyone to learn something from this blogger and blog.. I am sharing it with others also
IT Software Training in Chennai | Python Training in Chennai | Dot Net Training in Chennai

sangeetha sathyan said...

Fabulous post admin, it was too good and helpful. Waiting for more updates.
Tally course in Chennai
Tally Training in Chennai
Tally institute in Chennai
AngularJS course in Chennai
ccna course in Chennai
PHP course in Chennai
Salesforce course in Chennai
Tally Course in Velachery
Tally Course in Anna Nagar
Tally Course in T Nagar

cmtech said...

Has anyone said that your article is very good yet? I will give you a single ten for this achievement. Thanks
cửa gỗ công nghiệp chịu nước

Michael Dep said...

I really liked the way you create content. The work you have done seems like a professional, I make sure to keep a track on your blog once a week and subscribed to your RSS feed. In case if you liked stationery items you can also visit my website where you will find the best stationery products Diploma Covers, Diploma Holders, Wholesale Diploma Covers, Custom Diploma Cover, Graduation Tassels online.

Anand Shankar said...
This comment has been removed by the author.
Praisy Margret said...

good...nice...
assistant-director-resume-format
assistant-director-resume-sample
assistant-professor-resume-sample
back-office-executive-resume-samples
bank-branch-manager-resume-samples
basketball-coach-resume-sample-coach-resumes
bca-fresher-resume-sample
best-general-manager-resume-example
bpo-resume-freshers-sample
bpo-resume-samples-for-freshers

Indhu said...

SAP Training in Chennai
SAP ABAP Training in Chennai
SAP Basis Training in Chennai
SAP FICO Training in Chennai
SAP MM Training in Chennai
SAP PM Training in Chennai
SAP PP Training in Chennai
SAP SD Training in Chennai
SAP SRM Training in Chennai
SAP Success Factors Training in Chennai

Mithun said...

Informative Post very good blgo on SAP Technology. Thanks we do SAP training in Chennai and AWS Training in Chennai

Nisha said...

Informative and nice blog post. Thanks for this wonderful Post.
SAP Training in Chennai
AWS Training in Chennai
Hardware and Networking Training in Chennai
QTP Training in Chennai
CCNA Training in Chennai

subha said...

Wonderful blog with great piece of information. I've been following your blogs for a while and I'm really impressed by your works. Keep sharing more such blogs. keep it up guys
Ai & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai

augustwalker said...

The most effective method to HP Envy Printer Wireless Setup, introduce and design simple strides to interface printers, remote arrangement, driver introduce, gushing gadgets, information recuperation, email arrangement and pc rules.

Mithun said...

Thanks for this post.
Java Training in Chennai | Java Training Institute in Chennai | Java Training Center in Chennai | Best Java Training in Chennai | Java Training

Saqib Mirza said...

Are you Looking for a top Digital Marketing Services in North Carolina So hurry up we have best offers for you :)

Ishu Sathya said...



A Great read for me, Well written technically on recent technology

Are you looking for Ethical hacking related job with unexpected Pay, then visit below link


Ethical Hacking Course in Chennai
Ethical Hacking Online Course
Ethical Hacking Course
Hacking Course
Hacking Course in Chennai
Ethical Hacking Training in Chennai
hacking course online
learn ethical hacking online
hacking classes online
best ethical hacking course online
best hacking course online
ethical hacking online training
certified ethical hacker course online

Saqib Mirza said...

Hi!

Are you looking for an Video Agency in USA. We are offering services at low prices

Motion Design Agency
Video Motion Design
Video Motion Company

noman said...

Hi,
I things it's an amazing piece of content. I would like to appreciate your efforts.
We are providing wonderfull digital marketing agency. If you are looking for these services we are here for you. Feel free to visit our website.

Ramesh ji said...

We have seen many blog but this the great one, Thanks for provide great informatic and looking beautiful blog, really nice required information & the things i never imagined and i would like to request, wright more blog and blog post like that for us. Thanks you once agian

birth certificate in delhi
birth certificate in noida
birth certificate in ghaziabad
birth certificate in gurgaon
correction in birth certificate
marriage registration in delhi
marriage certificate delhi
how to change name in 10th marksheet
marriage registration in ghaziabad
marriage registration in gurgaon

Daily Word said...

Thanks for sharing such great information with us. Your Post is beneficial and the information is reliable for new readers. See this: Florida Pick 5

Essien said...

This a pretty wonderful share, thanks for the updates. This publish truly made my day. You can not imagine just how much time I had spent for this info! Thank you! Click Here post utme past questions for uam

Unknown said...


Very Nice Website, I really Appreciate your contents, this is very meaning for us.
Rajmandir Hyper Market

Jennifer James said...
This comment has been removed by the author.