Home > Web Front-end > HTML Tutorial > 如何让父元素自适应子元素的大小?_html/css_WEB-ITnose

如何让父元素自适应子元素的大小?_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:18:01
Original
1438 people have browsed it

有个图片  images/book1.jpg  维度是124*175



    如何让父元素自适应子元素的大小?_html/css_WEB-ITnose


效果如下,此时


下面增加img的padding:20px



    如何让父元素自适应子元素的大小?_html/css_WEB-ITnose


此时效果如图

如何写,可以使得div的大小可以自动变成:


测试过了,div不可以写成
div{
    overflow:auto;
    zoom:1;
    border:1px solid red;
}
宽度会撑满整个body.


回复讨论(解决方案)

div{display:inline-block;
    border:1px solid red;padding:20px;
}

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template