Div width 100% minus fixed amount of pixels

后端 未结 10 2065
猫巷女王i
猫巷女王i 2020-11-28 17:57

How can I achieve the following structure without using tables or JavaScript? The white borders represent edges of divs and aren\'t relevant to the question.

10条回答
  •  粉色の甜心
    2020-11-28 18:14

    You can use nested elements and padding to get a left and right edge on the toolbar. The default width of a div element is auto, which means that it uses the available width. You can then add padding to the element and it still keeps within the available width.

    Here is an example that you can use for putting images as left and right rounded corners, and a center image that repeats between them.

    The HTML:

    This is the dynamic center area

    The CSS:

    .Header {
       background: url(left.gif) no-repeat;
       padding-left: 30px;
    }
    .Header div {
       background: url(right.gif) top right no-repeat;
       padding-right: 30px;
    }
    .Header div div {
       background: url(center.gif) repeat-x;
       padding: 0;
       height: 30px;
    }
    

提交回复
热议问题