嵌套子元素何时扩展其父元素? [英] When do nested child elements expand their parent elment?

查看:109
本文介绍了嵌套子元素何时扩展其父元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多地方,我把elmeents嵌套在其他元素。我不能推断什么时候一个子元素导致父元素扩展。我没有任何代码发布,因为这是一个一般的概念问题,所以我可以根据需要设计。

In many places I have put elmeents nested in other elements. I can't deduce when a child element causes the parent element to expand. I don't have any code to post as this is a general conceptual question so that I can design as needed.

推荐答案

您应该了解的第一件事是 CSS盒模型。这将帮助您了解元素的属性如何导致其具有的大小和维度。另一个好的资源是这里

The first thing that you should understand is the CSS Box Model. That will help you understand how properties of an element cause it to have the size and dimensions that it has. Another good resource is here.

要以最简单的方式(非常一般)回答您的主要问题:

To answer your main question in the most simple manner (and being very general):


  • 块级元素占用尽可能宽的宽度服从它们的CSS宽度规则)。它们的高度取决于它们的内容和CSS高度属性。

    • 元素如 div p ul 都是块。

    • 这些通常会导致您的父元素展开。

    • Block level elements take up as much width as possible (obeying their CSS width rule). Their height is dependent on their content and the CSS height property.
      • Elements like div, p, and ul are all block.
      • These will generally cause your parent element to expand.

      • 元素如 span em strong 都是内联的。

      • 只有在同一行中有足够的元素可以保证另一行时,这些元素才会展开。

      • Elements like span, em, strong are all inline.
      • These will cause your parent element to expand only when there are enough of them on the same line to warrant another line.

      有很多方法可以使用CSS来调整元素的显示。

      There are many ways to tweak the display of elements with CSS.

      这篇关于嵌套子元素何时扩展其父元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆