简体   繁体   English

将“浮动”内容放在文本段落的右下角

[英]Place 'floating' contents at the bottom right of a paragraph of text

Here is the code: http://jsfiddle.net/ym2GQ/ 这是代码: http//jsfiddle.net/ym2GQ/

 p { background: lightblue; } .end { background: orange; float: right; display: inline; } 
 <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam adipiscing orci at tortor bibendum suscipit et eu eros. Nunc congue, ante nec egestas fringilla, ipsum est porttitor leo, tempus lacinia augue erat posuere elit. </p> <div class="end">$$</div> 

I want the floating $$ to be within the paragraph before it. 我希望浮动$$在它之前的段落内。 It should align with the lasts line in the paragraph but it should be floated to right. 它应该与段落中的持续线对齐,但它应该向右浮动。

How can this be done? 如何才能做到这一点? Please note that I have to solve this problem under the constraint that I can not float the paragraph element that comes before the div element. 请注意,我必须在我不能浮动div元素之前的段落元素的约束下解决这个问题。 I can do whatever I want with the DIV element though. 我可以用DIV元素做任何我想做的事。 I can also move around the DIV element to some other part of the code if necessary. 如有必要,我还可以将DIV元素移动到代码的其他部分。

Replacing the DIV with a SPAN, and moving the inside the P seems to work. 用SPAN替换DIV,并在P内部移动似乎有效。 You can optionally set the SPAN to inline-block depending on the contents. 您可以根据内容选择将SPAN设置为内联块。

If you put the SPAN before the text, it will be near the top. 如果您在文本之前放置SPAN,它将接近顶部。 If you put it after, it will be at the bottom. 如果你把它放在后面,它将在底部。

demo 演示

Given your new information that you want it at the bottom right of the paragraph, see this live example: http://jsfiddle.net/AGEus/1/ 鉴于您在段落右下方需要的新信息,请参阅此实例: http//jsfiddle.net/AGEus/1/

截图

In short: 简而言之:

  1. Make the <div> a <span> and place it as a child of the paragraph. <div>设为<span>并将其作为段落的子项。
  2. Make the paragraph position:relative (so that it establishes its own coordinate system) 使段落position:relative (以便它建立自己的坐标系)
  3. Put some padding in the paragraph on the right side so that the contents of .end won't overlap the text. 在右侧的段落中放置一些填充,以便.end的内容不会与文本重叠。
  4. Absolutely position and size the .end to the bottom right of the paragraph. 绝对定位和缩小.end到段落的右下角。

HTML: HTML:

<p>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit...
  <span class="end">$$</span>
</p>

CSS: CSS:

p      { position:relative; padding-right:2em }
p .end { position:absolute; right:0; bottom:0; width:2em }
​

Ok, played with your code and found the solution. 好的,玩了你的代码,找到了解决方案。 You need to set the p tag to display: inline and float the div to the right. 您需要设置p标签以显示:内联并将div浮动到右侧。 I updated your fiddle for you. 我为你更新了你的小提琴。

If I understand you right, you want that the div is displayed over your paragraph. 如果我理解你,你希望div显示在你的段落上。 For that you could just set the div to position absolute and set the exact position with top, left, right, bottom. 为此,您可以将div设置为绝对位置,并设置顶部,左侧,右侧,底部的确切位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM