简体   繁体   English

CSS将文本分布在两行上并垂直对齐

[英]Css distribute text over 2 lines and vertically align

I am trying to achieve a layout like the image in the link below. 我正在尝试实现以下链接中的图像所示的布局。 It's basically a set of list items that contain some text and then a large number to the right. 它基本上是一组列表项目,其中包含一些文本,然后在右侧包含大量文本。 I am wondering if it would be possible to distribute the text where it's outputted over 2 lines even though there is no fixed width on the list item elements 我想知道,即使列表项元素上没有固定的宽度,是否也可以在两行上分配输出文本的位置

Additionally, i am looking for a cross browser solution to vertically align the text and the numbers inside the LI. 另外,我正在寻找一种跨浏览器解决方案,以使LI内的文本和数字垂直对齐。 It needs to work in IE7+ without any javascript 它需要在没有任何JavaScript的IE7 +中工作

在此处输入图片说明

Try this 尝试这个

<ul>
<li>
    <div class="top">To</div>
    <div>For Submit<span class="number">50</span></div>
    </li>
<li>
    <div class="top">To</div>
    <div>For Submit<span class="number">50</span></div>
    </li>
<li>
    <div class="top">To</div>
    <div>For Submit<span class="number">50</span></div>
    </li>    
<ul>

CSS 的CSS

ul {
list-style:none;
font-size:14px;
margin:0;
padding:0;
}

ul li {
background-color:gray;
display:inline-block;
padding:5px 10px;
}

.number {
margin-left:10px;
font-size:20px;
}

JS Fiddle Demo JS小提琴演示

First solution: navigation bar 第一种解决方案:导航栏

I think that you need basically a navbar. 我认为您基本上需要一个导航栏。

Twitter Bootstrap navbar is the best thing you can chose I say. 我说,Twitter Bootstrap导航栏是最好的选择。 See the documentation . 请参阅文档

<div class="navbar">
  <div class="navbar-inner">
    <a class="brand" href="#">Title</a>
    <ul class="nav">
      <li class="active"><a href="#">Home</a></li>
      <li><a href="#">Link</a></li>
      <li><a href="#">Link</a></li>
    </ul>
  </div>
</div>

在此处输入图片说明

See live example: JSFIDDLE . 请参见实时示例: JSFIDDLE

Second solution 第二解决方案

Also, you can use row s and span s. 另外,您可以使用rowspan

Documentation is here . 文档在这里

Example: 例:

<div class="row">
    <div class="span1">Text 1</div>
    <div class="span1">Text 2</div>
    <div class="span1">Text 3</div>
    <div class="span1">Text 4</div>
    <div class="span1">Text 5</div>
    <div class="span1">Text 6</div>
</div>

JSFIDDLE JSFIDDLE

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

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