How to add padding or border to a DIV and keep width and height?

后端 未结 5 1338
半阙折子戏
半阙折子戏 2020-12-28 18:42

Is there some way to keep a set width/height for a DIV, and pad the content without the DIV growing? See example below. I want all the boxes to be exactly 140x140.

H

5条回答
  •  既然无缘
    2020-12-28 19:14

    The cleanest method would probably be to nest

    tags within your current
    tags, and apply the padding to them:

    Howdy.
    Howdy.
    Howdy.

    CSS:

    .div { /* ... */ }
    .div > div { padding: 1em; } /* Apply to all inner divs */
    #box2 > div { padding: 1em; } /* Only apply to the inner div in #box2 */
    

提交回复
热议问题