- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我可以简单地使用 float
实现文字环绕 <img>
元素,我明白 <img>
是一个行内元素并且 <p>
是一个 block 级元素,所以要使它们内联,我应该制作 <p>
内联元素或使用 <span>
相反。
问题是,如果我将它们全部视为内联元素,它会在图像旁边和文本顶部留下一个巨大的空白区域。
我想知道是什么导致了空白。
这是我的 JS Fiddle
最佳答案
这个问题似乎更关心为什么而不是如何,所以我将专注于内部工作:
Visual formatting model CSS 2.1 规范的部分描述了 inline formatting contexts :
In an inline formatting context, boxes are laid out horizontally, one after the other, beginning at the top of a containing block. Horizontal margins, borders, and padding are respected between these boxes. The boxes may be aligned vertically in different ways: their bottoms or tops may be aligned, or the baselines of text within them may be aligned. The rectangular area that contains the boxes that form a line is called a line box.
他们描述的属性是 vertical-align
它采用许多不同的值,baseline
作为默认值。这就是为什么你的两个 inline
通过位于基线,元素按原样显示。您可以更改 <p>
至 vertical-align: top
, 并且第一行文本的顶部将与图像的顶部对齐。但是,您仍然会在第一行文本和后续行之间看到一个空隙。
这是因为文本将一个 line-box 垂直渲染到下一个。不管第一行的 line-box 是否比其余的大,它仍然会一次流一个 line-box。这是这个概念的可视化:
理解这一点的另一个重要概念是 <img>
是一个replaced inline 元素,这意味着它的外观是由文档外部的外部资源构建的。 替换内联 元素可以采用 height
值,而所谓的非替换内联(如 <span>
)元素则不能。这就是为什么 <img> <span>foo</span>
可以与 <span>foo</span> <em>bar</em>
不同(因为图像具有固有高度),即使它们都是行内元素。想象一下,将图像的高度设置为文本的 x 高度——它会有效地呈现与您的图像相同的效果,但在这种情况下,它的行为完全符合您的预期:
img {
height: 10px;
}
p {
display: inline;
}
<div>
<img src="http://placehold.it/100x100/E8117F/000.png">
<p>hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello</p>
</div>
这可能是一些困惑发生的地方。如果您能想象这些行,那么您就会明白,我们并不期望内联元素表现得像 float 元素。
将该信息与规范中关于 floats 的内容进行比较:
A float is a box that is shifted to the left or right on the current line. The most interesting characteristic of a float (or "floated" or "floating" box) is that content may flow along its side (or be prohibited from doing so by the 'clear' property). Content flows down the right side of a left-floated box and down the left side of a right-floated box.
A floated box is shifted to the left or right until its outer edge touches the containing block edge or the outer edge of another float. If there is a line box, the outer top of the floated box is aligned with the top of the current line box.
虽然我无法向您描述电子发生了什么,但我希望这是一个很好的起点,可以帮助您理解为什么这些不同的场景会呈现出它们的行为方式。
关于CSS - 使段落文本环绕图像而不 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20085418/
我正在学习 ada 并且我正在尝试为枚举实现附加重载。 基本上我希望能够向 Day 类型添加一个 Integer 并获得生成的 Day 值。所以星期一 + 2 => 星期三。 这是我的简化代码: pr
Pycharm 具有“包围”代码片段的功能。有一些已经设置好的功能: 我想添加print()(使用python3),我该怎么做? 最佳答案 AFAIU,您可以为此定义自己的“实时”模板。 定义实时模板
例。我有一个包含15个对象的数组。我想从给定的索引开始枚举。假设从索引5开始,然后是上方的索引,下方,上方,下方等的索引...我确实希望它绕起来。 因此,在我的示例中,索引的顺序将是这样。 5、6、4
我需要帮助创建 UIPickerView 来环绕选项。因此,选择器不是这样的: 我希望它看起来像这样(没有“min”): 我到处找,但找不到用 Swift 2.0 实现的方法谢谢! 最佳答案 以下是有
如何让 UITextView 将其文本包裹在 UIImage 周围,如下图所示? 图像大小不一定是事先已知的。 最佳答案 IOS 7 及以上版本: UIBezierPath * imgRect = [
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: UIScrollView. Any thoughts on implementing “infinite” scro
我像这样创建纹理: this->width = width; this->height = height; glGenFramebuffers(1, &framebuffer); glBindFram
在编码和模板化中,我经常需要换行文本的特定部分。是否有任何快捷方式可以包装当前选择,例如: Hello World "Hello World" Hello World {{ trans 'Hello
我正在做一个项目,我们有一些从数据库中填充的 Highcharts 图表;其中之一是散点图,我们需要包围放置在图表外部区域的点。 我们需要像 this 这样的图表但是我们需要散点图外部点周围的区域;使
我有一个 500 像素高和 50 像素宽的 jpg。它由 10 个 50px x 50px 的正方形组成,每个正方形包含一个从 1 到 10 的数字(1 在图像顶部,10 在底部)。 (jpg 在这里
我正在尝试为那些了解它的人创建一个类似 Microsoft Project 的元素控件。 我有一个Container Div,然后有两个子容器如下: 每个子容器都有很多内部 div,例如,我的第一个子
我有 4 个 div,一个我想向左浮动,视频播放器(加载了 jquery),另一个包含一些将向右浮动的帮助/提示文本。这两个应该排在顶部。在视频播放器下方将是一个 div 内的表格。 当有人点击表格中
这个问题在这里已经有了答案: Proper use of flex properties when nesting flex containers (1 个回答) 关闭 4 年前。
我在使用自定义列表图像时遇到问题/其中图标隐藏在列表环绕的 float 元素后面。 http://jsfiddle.net/V8evM/ HTML This is list item n
是否可以将 textview 环绕在 textview 周围,第二个 textview 将环绕到第一个 textview 下的下一行? 例如: 我尝试过使用 android:layout_weig
图片最能说明问题: 它只是一个 float: left 图像 ( http://jsbin.com/itihes/1 )。有什么方法可以防止纯 CSS 中的动态文本出现这个问题吗?我确实希望文本换行,
我在 C 规范中读到一点,无符号变量(特别是 unsigned short int)在整数溢出时执行一些所谓的环绕 ,尽管我在带符号的变量上找不到任何东西,除了我留下了未定义的行为。 我的教授告诉我,
如果您想要容器底部的 div,如何让文本环绕 div? 我可以弄清楚如何让文本环绕在 div 上,只要它在顶部,但如果我尝试将它推到页面底部,文本要么不会'不要继续跨越 div 的顶部,否则 div
假设数组的长度为 1000。我正在尝试创建一种简单的方法来遍历存储在数组中的图像路径而不会越界。当涉及到单击“下一步”按钮以增加数组索引时,下面的方法使用模数很好地处理了环绕,但当我必须减少并从索引中
假设我的光标在单词 word 内.使用 vim-surround,输入序列 ysiw*将替换 word与 *word* . 问题:是否有我可以输入的单个序列来代替生成 **word** (即,单词加粗
我是一名优秀的程序员,十分优秀!