In particular, I mean a situation where you need to have a total width of, say, 100% on a DIV, but an indent of 10 pixels and 1 pixel border. (And do not rely on the browser to automatically set it to this width - let's say that it, for example, floats on the left).
Is there an easy way to accomplish this without using JavaScript?
No, there is no way to install this on a single element that works with current major browsers.
You can use 2 nested divs. Set the width 100%to outher divand set the registration and border to the inside div.
div
100%
box-sizing: border-box, width: 100%; border: 1px solid black; padding: 10px;, , , , .
box-sizing: border-box
width: 100%; border: 1px solid black; padding: 10px;
EDIT: , . FF 3.5 Safari 4 , IE8 Chrome.
This is only possible with CSS 3.
What about the next solution?
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Content with Menu</title> <style type="text/css"> .content .outer{ width:100%; border:1px solid black; background-color:green; } .content .inner{ margin-left:10px; margin-right:10px; background-color:red; } </style> </head> <body> <div class="content"> <div class="outer"> <div class="inner"> <p>Hi!</p> </div> </div> </div> </body> </html>
Updating OK does not do what you are talking about with only one element.
Source: https://habr.com/ru/post/1710929/More articles:Grails: файлы Javascript в папке views - javascriptWriting XML from Python: Python.NET equivalent of XmlTextWriter? - pythonWhy is an NSWindow or NSView instance handling its own key events and not its delegate? - objective-cIs there an effect on query speed when using SQL_CALC_FOUND_ROWS in MySQL? - mysqlJ2ME лишний раздражающий запрос на доступ к HTTP - httpIPhone Phonebook - Auto Select Phone Owner - iphoneHow to support messaging while waiting? - c ++Is it possible to use database link between oracle database and postgresql database on different physical servers - javaShould I study the framework for starting a project? - frameworksSort from current point to end of file in gvim? - vimAll Articles