简体   繁体   English

如何在HTML的一行中放置两个元素

[英]How to position two elements on the one line in HTML

Here is my problem: 这是我的问题: 在此处输入图片说明

I need to put this number over"...". 我需要把这个数字放在“ ...”上。

Here is the HTML code: 这是HTML代码:

<div class=" unread-object">

            <div style="overflow: hidden; text-overflow: ellipsis;">

                <a class="k-link nowrappable outdate-object" href="#/view/19260">
                    л ьотрипмасвчувсапмдгбыцячшльогтрнамам ам маугшпгнплрплроsdsds 
                </a>


                 <span class="unread-count" style="font-weight:normal; font-size:9px; color:rgb(161,187,206);float:right;">[3]</span>


            </div>
        </div>

float:right and left doesnt work. float:左右不起作用。 But, when I stretch fully slider: 但是,当我完全拉伸滑块时:

在此处输入图片说明

use display:inline-block 使用display:inline-block

<a class="k-link nowrappable outdate-object" href="#/view/19260" style="display:inline-block;">л ьотрипмасвчувсапмдгбыцячшльогтрнамам ам маугшпгнплрплроsdsds</a>

<span class="unread-count" style="font-weight:normal; font-size:9px; color:rgb(161,187,206); display:inline-block;">[3]</span>

I think this will solve your issue. 我认为这可以解决您的问题。

jsFiddle Link jsFiddle链接

When the width of the block does not align the two elements, the right will float line. 当块的宽度未使两个元素对齐时,右侧将浮动线。

Simple solution is to use position:absolute; 简单的解决方法是使用position:absolute;

In my example 在我的例子中

I placed position:relative for the second div 我将position:relative对于第二个div

<div style="overflow: hidden;position:relative; text-overflow: ellipsis;">

where you have content and the span with unread-count it's placed with position absolute; 您有内容且未读计数的跨度以position absolute;放置position absolute;

.unread-object .unread-count{
   position:absolute;
    right:0px;
    top:0px
}

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

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