简体   繁体   English

在flexbox的中间水平对齐两个范围

[英]Align horizontally two spans in the middle of a flexbox

I have a div (flex) containing 2 spans that I want to be aligned like this . 我有一个包含2个跨度,我要像对齐一个div(柔性)

What I have now is this 我现在已经是这个

Code: 码:

<div className="MemberLinks">
      <div>
        <span className="linkTitle">Schedule of Benefits</span>
        <span>
          <a href="./manifest.json">
            doc.pdf
          </a>
        </span>
      </div>
      <div>
        <span className="linkTitle">General Exclusions</span>
        <span>
          <a href="./manifest.json">
            doc.pdf
          </a>
        </span>
      </div>
    </div>

css: CSS:

.MemberLinks {
margin-top: 1em;
display: flex;
flex-direction: column;
}
.linkTitle {
display: inline-block;
margin: 0 .6em 0 0;
}

I want to accomplish horizontally alligned spans in the midle of them, so it stays formatted like there was a even space between elements 我想在它们中间完成水平指定的跨度,因此它保持格式,就像元素之间有均匀的空间一样

I don't think you need to use flex to achieve this effect. 我认为您无需使用flex即可达到此效果。

What I've done is removed the flex, set the span s to have 50% width, then set the text-align property to right for the first span . 我要做的是删除flex,将span设置为50%的宽度,然后将text-align属性设置为第一个span right

 .MemberLinks { margin-top: 1em; } .MemberLinks span { display: inline-block; width: 50%; padding: 0 0.1em; box-sizing: border-box; } .MemberLinks span:first-of-type { text-align: right; } 
 <div class="MemberLinks"> <div> <span class="linkTitle">Schedule of Benefits</span><span> <a href="./manifest.json"> manifestdoc.pdf </a> </span> </div> <div> <span class="linkTitle">General Exclusions</span><span> <a href="./manifest.json"> otherdoc.pdf </a> </span> </div> </div> 

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

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