简体   繁体   English

对齐标签,跨度和按钮

[英]Align label, span and button

I have the next elements defined like this: 我接下来定义了以下元素:

label(Name) span(Surname) span(button) 标签(名称)范围(姓氏)范围(按钮)

which gives me the result as shown below: 这给了我如下所示的结果:

Name: James Change Surname: Bond Change Age: 56 Change 姓名:James Change姓:Bond Change年龄:56 Change

Now I'd like to align my elements like this: 现在,我想像这样对齐我的元素:

Name: James Change Surname: Bond Change Age: 56 Change 姓名:James Change姓:Bond Change年龄:56 Change

I know, that one way is to use table. 我知道,一种方法是使用表格。 I don't want to use table. 我不想用桌子。 I have managed to align the button button to right with float:right but I haven't managed to separate surname from name. 我设法将按钮按钮的右边与float:right对齐,但是我没有设法将姓氏和名字分开。 I tried padding/margin left on both and they moved away but then they moved unequally. 我尝试在两者上都留有填充/边距,但它们移开了,但随后它们不均匀地移动了。 Also, this way resizing the window causes the text to overflow on each other. 同样,以这种方式调整窗口大小会导致文本彼此溢出。 Any ideas how to solve this? 任何想法如何解决这个问题?

Simple: 简单:

HTML 的HTML

 <div class="row">
   <label>Name</label> 
   <span>John Doe</span>
   <span>Change</span>
 </div>

CSS: CSS:

.row label, .row span {
  display: inline-block;
  vertical-align: top;
}

See it working: 看到它的工作:

 .row label, .row span { display: inline-block; vertical-align: top; border: 1px solid black; padding: 10px; margin: 0 2px; } 
 <div class="row"> <label>Name</label> <span>John Doe</span> <span>Change</span> </div> 

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

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