简体   繁体   English

列表项水平间距

[英]List Item horizontal spacing

I have the following list and want to add another element to list element with Name .我有以下列表,并希望将另一个元素添加到具有Name的列表元素中。 So I am adding Primary User but want the new element Primary User styled to the right of the line.因此,我添加了Primary User ,但希望将新元素Primary User设置在该行的右侧。 What's the best way to do this?最好的方法是什么? Is it awkward doing this to a list item?对列表项这样做很尴尬吗? Thanks.谢谢。

      <div class="panel-heading">Company Details</div>
        <ul class="list-group">
          <li class="list-group-item"><b>Name:</b> <%= @company.name %><b>Primary User:</b><%= @company.primary %></li>```

One possibility would be to use float right.一种可能性是使用 float right。 Don't know if it is the best one and there are probably plenty others, but it will work.不知道它是否是最好的,可能还有很多其他的,但它会起作用。

HTML HTML

<div class="panel-heading">Company Details</div>
<ul class="list-group">
  <li class="list-group-item">Name: Test1 <span class="user">User: Test</span>
  </li>
  <li class="list-group-item">Name: Test1 <span class="user">User: Test</span>
  </li>
  <li class="list-group-item">Name: Test1 <span class="user">User: Test</span>
  </li>
</ul>

CSS CSS

.user {
  float: right;
}

.list-group {
  width: 250px;
}

https://jsfiddle.net/zy7d48ub/ https://jsfiddle.net/zy7d48ub/

Wrap your code inside this div wrapper and it should work.将您的代码包装在这个 div 包装器中,它应该可以工作。

<div class = "panel-heading-wrapper" style = "display: flex;">

I find myself using (maybe overusing?) css grid a lot for layouts such as this.我发现自己经常使用(可能过度使用?)css 网格用于这样的布局。 It has so much flexibility for fine-tuning the layout.它在微调布局方面具有很大的灵活性。 My approach would be:我的方法是:

<div class="panel">
  <div class="panel-heading">
    Company
  </div>
  <div class="name">
    Name
  </div>
  <div class="user">
    User
  </div>
</div>
.panel {
  display: grid;
  grid-template-columns: 100px 100px;
  grid-template-rows: 20px 20px;
  grid-template-areas: 'heading heading''name user'
}

.panel-heading {
  grid-area: heading;
}

.name {
  grid-area: name;
}

.user {
  grid-area: user;
}

here's what it looks like on jsfiddle这是jsfiddle上的样子

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

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