国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

求大神來看為li元素設置相同的padding為何padding-bottom和padding-right為多出一部分_html/css

來源:懂視網 責編:小采 時間:2020-11-27 16:09:08
文檔

求大神來看為li元素設置相同的padding為何padding-bottom和padding-right為多出一部分_html/css

求大神來看為li元素設置相同的padding為何padding-bottom和padding-right為多出一部分_html/css_WEB-ITnose:代碼如下 無標題文檔 body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td,img {padding:0;margin:0;} #div1{ margin:10px; width:300px; height:2
推薦度:
導讀求大神來看為li元素設置相同的padding為何padding-bottom和padding-right為多出一部分_html/css_WEB-ITnose:代碼如下 無標題文檔 body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td,img {padding:0;margin:0;} #div1{ margin:10px; width:300px; height:2

代碼如下
無標題文檔


回復討論(解決方案)


哪里有問題

看了半天沒看懂你問的是什么


哪里有問題


ul上下的padding是一樣的,但是下面的空白明顯大于上面

看了半天沒看懂你問的是什么


ul上下的padding一樣,但是下面的空白明顯大于上面

這是 offsetHeight 的高度定義 和 li 的 box-sizing 是 content-box 相矛盾造成的

The offsetHeight property returns the viewable height of an element in pixels, including padding, border and scrollbar
就是說 offsetHeight 包含了 內容, padding-top, padding-bottom, border-top, border-bottom, 以及涉及 scroollbar 的高度
box-sizing: content-box 指定元素的高度只包含內容, 而不含其他.
你的代碼中, li 的高度之后被重設, 并且總是比期望的要多出 padding-top + padding-bottom 的和.
而之后, padding-top 和 padding-bottom 并沒有變化, 都是你指定的 10px, 這多出的部分被加到了 content 的高度上, 但content 的字體并沒有變大, 而且文字又沒有被處理成在 content 中垂直居中, 所以看起來上下空白就不一樣了

所以可以加入以下 CSS, 在 scroollbar 不存在的情況下, 就可以解決了

li{ box-sizing: border-box;}

W3C 上 box-sizing 的定義引用

3.1. box-sizing property

Name: box-sizing
Value: content-box | border-box
Initial: content-box

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.



這個定義表明 box-sizing 的默認值是 content-box; box-sizing 的值將影響 css 中 height 的定義-- 垂直方向上的 padding 和 border 究竟會不會包含在 height 中

W3C 上 box-sizing 的定義引用

3.1. box-sizing property

Name: box-sizing
Value: content-box | border-box
Initial: content-box

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.



這個定義表明 box-sizing 的默認值是 content-box; box-sizing 的值將影響 css 中 height 的定義-- 垂直方向上的 padding 和 border 究竟會不會包含在 height 中



W3C 上 box-sizing 的定義引用

3.1. box-sizing property

Name: box-sizing
Value: content-box | border-box
Initial: content-box

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.



這個定義表明 box-sizing 的默認值是 content-box; box-sizing 的值將影響 css 中 height 的定義-- 垂直方向上的 padding 和 border 究竟會不會包含在 height 中


但是如果 出現(xiàn)了滾動條,頁面就會變成這個樣子

看了半天沒看懂你問的是什么


ul上下的padding一樣,但是下面的空白明顯大于上面

你這里又給他加了高度
//運動 var iheight=oli.offsetHeight; alert(iheight); oli.style.height="0"; move(oli,{height:iheight});

但是如果 出現(xiàn)了滾動條,頁面就會變成這個樣子



我分別在 Chrome 42, IE8, Firefox 39.0 測試, 只發(fā)現(xiàn) Firefox 存在這個問題

下面多余的部分不全是padding,還有一部分是li的高。
oli.offsetHeight獲取的值是包括padding在內的,但是oli.style.height這樣賦值的高是不包括padding的。
最簡單的解決方法就是減掉padding,即var iheight=oli.offsetHeight-20;
但這樣解決效果不太好,因為oli.style.height=“0”;時其實padding部分還是看的見的。
要效果好,也要簡單就用jquery吧,修改如下

這兒是為了實現(xiàn)一個滑動效果,和padding沒關系吧,何況最終的高度并沒有改變


但是如果 出現(xiàn)了滾動條,頁面就會變成這個樣子



我分別在 Chrome 42, IE8, Firefox 39.0 測試, 只發(fā)現(xiàn) Firefox 存在這個問題


chrome43,IE11也存在問題

下面多余的部分不全是padding,還有一部分是li的高。
oli.offsetHeight獲取的值是包括padding在內的,但是oli.style.height這樣賦值的高是不包括padding的。
最簡單的解決方法就是減掉padding,即var iheight=oli.offsetHeight-20;
但這樣解決效果不太好,因為oli.style.height=“0”;時其實padding部分還是看的見的。
要效果好,也要簡單就用jquery吧,修改如下

這個函數(shù)來獲取li的高度就不會包括padding
謝謝,問題解決了!

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

求大神來看為li元素設置相同的padding為何padding-bottom和padding-right為多出一部分_html/css

求大神來看為li元素設置相同的padding為何padding-bottom和padding-right為多出一部分_html/css_WEB-ITnose:代碼如下 無標題文檔 body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td,img {padding:0;margin:0;} #div1{ margin:10px; width:300px; height:2
推薦度:
標簽: 為什么 多一 li
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 北条麻妃国产九九九精品视频 | 国产女人在线视频 | 国产高清在线播放免费观看 | 欧美在线一区二区三区精品 | 91热久久 | 国产成人久久一区二区三区 | 欧美一区二区三区精品 | 日韩电影免费在线观看视频 | 热re91久久精品国产91热 | 亚洲精品国产精品精 | 永久毛片 | 四虎影视最新地址 | 久久精品国产一区 | 亚洲视频二 | 欧美 日韩 国产 成人 在线观看 | 婷婷久久五月天 | 欧美日韩视频在线播放 | 日本精品久久久一区二区三区 | 成人a免费视频播放 | 精品久久久久久中文字幕 | 亚洲精品不卡久久久久久 | 热久久伊人 | 日本欧美韩国专区 | 久久久久无码国产精品一区 | 欧美色图日韩 | 亚洲最新偷拍 | 午夜视频网 | 欧美日韩专区 | 亚洲一区二区三区四区在线 | 国产在线看不卡一区二区 | 91免费高清无砖码区 | 极品国产高颜值露脸在线 | av毛片免费看 | 国产成人精品日本亚洲11 | 特一级大黄在线观看 | 欧美一级色图 | 国产成人高清亚洲一区久久 | 日韩欧美在线观看 | 欧美日韩精品在线 | 国产亚洲午夜精品a一区二区 | 欧美 日韩 国产 色 欧美 日韩 亚洲另类专区 |