我记得我之前在网上有查到,如果在CSS属性里面声明一个值可以使得外边距,内边距和框的数值是计算在盒的高度和宽度里面的,但我忘记这个属性和这个值是什么了?求高手告知。
还有我想问为什么CSS默认外边距,内边距和框的值要独立出来,不算在盒的高度和宽度里面?这样有什么好处吗?
回复讨论(解决方案)
box-sizing 设为 content-box 时, height 和 width 只包含内容, 不含 padding 和 border
设为 border-box 时, height 和 width 包含 padding 和 border
你看看 W3C 官方的文档:
http://www.w3.org/TR/css3-ui/#box-sizing
content-box
This is the behavior of width and height as specified by CSS2.1. The specified width and height (and respective min/max properties) apply to the width and height respectively of the content box of the element. The padding and border of the element are laid out and drawn outside the specified width and height.
border-box
Length and percentages values for width and height (and respective min/max properties) on this element determine the border box of the element. That is, any padding or border specified on the element is laid out and drawn inside this specified width and height. The content width and height are calculated by subtracting the border and padding widths of the respective sides from the specified width and height properties. As the content width and height cannot be negative ([CSS21], section 10.2), this computation is floored at 0. Used values, as exposed for instance through getComputedStyle(), also refer to the border box.
还有我想问为什么CSS默认外边距,内边距和框的值要独立出来,不算在盒的高度和宽度里面?这样有什么好处吗?
如果我想要明确的设置内容的 height 和 width, 但 css 的 height 和 width 这两个属性却始终把 padding 和 border 的尺寸都包含在其中, 那我设置时不就是得先计算才能设置好吗
比如
$(element).css('width', 内容期望的宽度 + padding-left + padding-right + border-left + border-right);
这样岂不是相当麻烦吗, 而且如果 padding-left , padding-right , border-left, border-right 之中的任意一个发生改变时, 都将影响到 内容的宽度
还有我想问为什么CSS默认外边距,内边距和框的值要独立出来,不算在盒的高度和宽度里面?这样有什么好处吗?
如果我想要明确的设置内容的 height 和 width, 但 css 的 height 和 width 这两个属性却始终把 padding 和 border 的尺寸都包含在其中, 那我设置时不就是得先计算才能设置好吗
比如
$(element).css('width', 内容期望的宽度 + padding-left + padding-right + border-left + border-right);
这样岂不是相当麻烦吗, 而且如果 padding-left , padding-right , border-left, border-right 之中的任意一个发生改变时, 都将影响到 内容的宽度
非常感谢。

HTML是一種用於構建網頁的語言,通過標籤和屬性定義網頁結構和內容。 1)HTML通過標籤組織文檔結構,如、。 2)瀏覽器解析HTML構建DOM並渲染網頁。 3)HTML5的新特性如、、增強了多媒體功能。 4)常見錯誤包括標籤未閉合和屬性值未加引號。 5)優化建議包括使用語義化標籤和減少文件大小。

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

HTML的作用是通過標籤和屬性定義網頁的結構和內容。 1.HTML通過到、等標籤組織內容,使其易於閱讀和理解。 2.使用語義化標籤如、等增強可訪問性和SEO。 3.優化HTML代碼可以提高網頁加載速度和用戶體驗。

htmlisaspecifictypefodyfocusedonstructuringwebcontent,而“代碼” badlyLyCludEslanguagesLikeLikejavascriptandPytyPythonForFunctionality.1)htmldefineswebpagertuctureduseTags.2)“代碼”代碼“ code” code code code codeSpassSesseseseseseseseAwiderRangeLangeLangeforLageforLogageforLogicIctInterract

HTML、CSS和JavaScript是Web開發的三大支柱。 1.HTML定義網頁結構,使用標籤如、等。 2.CSS控製網頁樣式,使用選擇器和屬性如color、font-size等。 3.JavaScript實現動態效果和交互,通過事件監聽和DOM操作。

HTML定義網頁結構,CSS負責樣式和佈局,JavaScript賦予動態交互。三者在網頁開發中各司其職,共同構建豐富多彩的網站。

HTML適合初學者學習,因為它簡單易學且能快速看到成果。 1)HTML的學習曲線平緩,易於上手。 2)只需掌握基本標籤即可開始創建網頁。 3)靈活性高,可與CSS和JavaScript結合使用。 4)豐富的學習資源和現代工具支持學習過程。

AnexampleOfAstartingTaginHtmlis,beginSaparagraph.startingTagSareEssentialInhtmlastheyInitiateEllements,defiteTheeTheErtypes,andarecrucialforsstructuringwebpages wepages webpages andConstructingthedom。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

記事本++7.3.1
好用且免費的程式碼編輯器

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SublimeText3漢化版
中文版,非常好用