简体   繁体   English

在UL和左对齐文本中,将带更多li元素的li元素居中

[英]Center li elements with more li elements in it within an UL and allign text left and right

I have the following setup: JSFiddle example 我有以下设置: JSFiddle示例

I have a main ul that contains several li elements. 我的主要ul包含几个li元素。 I want to center these li elements within the ul. 我想将这些li元素放在ul中。 Unfortunatly I havent been able to do this have been struggeling with it. 不幸的是,我一直无法做到这一点。

This li element also contains an ul and again more li elements. 该li元素还包含ul和更多li元素。 I am also trying to allign these final li elements. 我也正在尝试消除这些最后的li元素。

The markup of this element is like this: 该元素的标记如下所示:

 <li><em>Order ID </em>1304129149</li> 

The em part should be aligned left and the rest should be right. em部分应左对齐,其余部分应右对齐。 I can only do one of the two. 我只能做两者之一。

Any ideas what I am missing? 有什么想法我想念的吗?

Kind regards 亲切的问候

Alignment is applied to old child elements. 对齐应用于旧的子元素。 To align different elements to left and right of parent you can use float: 要将不同的元素与父元素的左右对齐,可以使用float:

 ul { list-style: none; } li { width: 400px; text-align: right; } li em { float: left; } 
 <ul> <li><em>Order ID </em>1304129149</li> </ul> 

UPDATE: 更新:

Of course it can works in your code too. 当然,它也可以在您的代码中工作。 Just carefully check what you do: 只需仔细检查您的操作即可:

 #content { min-width: 100%; padding: 15px; margin: 0 auto; } .details-table > li { background-color: #FFFFFF; -webkit-backface-visibility: hidden; backface-visibility: hidden; box-shadow: 0 0 10px rgba(0,0,0,.15); outline: 1px solid transparent; float: left; margin: 0 20px 20px 0; list-style-type: none; } .details-table-header { height: auto; text-align: center; color: #fff; background-color: #ff1a00; } .details-table-data { list-style-type: none; padding-left: 0; } .details-table-data li { text-align: right; padding: 4px; } em { float: left; } 
 <div id="content"> <ul class="details-table"> <li> <header class="details-table-header"><h2>Algemeen</h2></header> <div class="details-table-body"> <ul class="details-table-data"> <li><em>Bestelling ID</em>8</li> <li><em>Winkel</em>eFor</li> <li><em>Order ID </em>1304129149</li> </ul> </div> </li> <li> <header class="details-table-header"><h2>Algemeen</h2></header> <div class="details-table-body"> <ul class="details-table-data"> <li><em>Bestelling ID</em>38</li> <li><em>Winkel</em>eFor</li> <li><em>Order ID </em>130413429149</li> </ul> </div> </li> </ul> </div> 

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

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