Center two spans horizontally within a flexbox container

I am trying to align two spans inside a flex div like shown in this.

Currently, it looks like this

Here is the code I have:

<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:

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

I want to achieve horizontally aligned spans with even spacing between them.

Answer №1

I believe there is a way to achieve this effect without using flex.

What I did was eliminate the flex, adjust the width of the span elements to be 50%, and then set the text-align property to right for the first span.

.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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

ReactJS allows functions to be executed repeatedly

I'm attempting to output "asdf" to the console every second in reactjs using setInterval. Below is my code snippet: <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react.js"></script> <scr ...

Leverage a JSON variable within jQuery to showcase additional JSON variables

This code snippet is a work in progress, and there is room for improvement. The goal here is to have the content of thumb2 displayed in the #imageLoad container when a user clicks on a thumbnail inside the #placeholder DIV. Keep in mind that both Thumb and ...

What is the best way to ensure that an anchor in a scrolling list adjusts its width based on its children's content?

Check out the setup I have here: http://jsfiddle.net/9F6CF/ In this scenario, there is a list containing anchors within each list item. The UL element has a specific width and an overflow set to auto, causing text in the anchors to scroll horizontally if ...

My Serverless function is excelling in the production environment, but encountering issues in the development stage

Website Name: Problem: I am currently facing an issue with my serverless functions. While they function perfectly in production, I recently discovered that by installing and using 'netlify-cli' to run 'netlify dev', I can develop the a ...

Scoped Styles rarely stand a chance against more dominant styles

I'm facing a scope issue while learning Vue. Question: I am trying to make sure that the styles in profile.vue do not override the ones in sidebar.vue. I want the sidebar to have a red background and the profile section to be blue. Shouldn't usi ...

Is there a way to hide the navbar items in Bootstrap 5 until the screen width reaches a specific size?

As I work on creating a navigation bar with Bootstrap 5, I am seeking a way to hide the navbar items until the screen width reaches a specific size. ...

Is there a way to eliminate the underscore that appears beside the image?

Here is a simple example of a webpage: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style type="text/css"> * { border:0; margin:0; padding:0; } body { background:# ...

A pop-up appears, prompting me to redirect to an external URL when clicking on a link that opens in a new tab on my WordPress website

Seeking assistance in dealing with a popup that appears when trying to open a link redirected to an external URL. The popup prompts for permission to open the link in a new tab. Upon inspecting the Element, the code snippet below is revealed: <div cla ...

Troubleshooting: Handling communication between forms and server in React-Native (Issue with undefined function)

Currently working on a registration app and encountering an error with event handling when submitting new field values. https://i.sstatic.net/xZl3P.png You can find the form code here and here. The event handling and sending of JSON object to the server ...

The transmission of specific properties to a customized component is not successful

I recently developed a custom component that is designed to receive a color name from the parent component and update that color in the state of the parent component. Despite completing all the necessary code, the new color is not being saved, resulting in ...

Using Angular directives to pre-select a default option

I am currently working on a select HTML tag with two options, and I want to set the first option as the default choice. My select element includes Angular directives like ng-change and ng-model. I have attempted to achieve this by adding selected = "select ...

Unable to modify variable values in AngularJS

I'm currently utilizing AngularJS along with the "Angular Material" implementation (found here: https://material.angularjs.org/latest/#/) One of the components I'm using is the SideNav component: https://material.angularjs.org/latest/#/demo/mate ...

Creating Radial Fades with CSS3

Seeking guidance on creating a background similar to the one shown here using just CSS. I believe it can be done, but I struggle with CSS3. The goal is for the background to be compatible with all modern browsers, not overly concerned about support for br ...

HTML and CSS site lacking responsiveness

I am new to HTML and I have created a page that looks good on desktop, but it is not responsive on mobile devices. Can someone please help me with my HTML and CSS code? .link-menu { color: black; } .topbar-p ...

Is the Navbar moving off-center and the Bootstrap sign-in demo looking funky on Flask? Need any solutions?

The positioning of the Navbar has been altered to the left, causing distortion in the login items, which is an example of Bootstrap implementation. In my login.html file, I have utilized the Bootstrap sign-in example. Strangely, only on this specific page ...

An angular component that is functioning properly when connected to a live server, however, it is experiencing issues when trying to run `

I tried integrating versitka into my Angular component by placing the version HTML file and all necessary assets in the appropriate directories. However, when I run ng serve, only the HTML file seems to be working, while the CSS and images fail to load. I ...

Steps for transferring an SQL table's data using PHP

I'm facing an issue while attempting to display a table containing users' SQL data onto an HTML page. Let's assume that the connection is established and there is indeed information in the table. <?php echo "<table> &l ...

"Converting an angular date-picker into a popup-date-picker: A step-by-step

I am currently working on a project in Plunker and I would like to implement an Angular date-picker-popup similar to the one in my design. Any suggestions or ideas on how to achieve this? Thank you in advance! ...

An object that appears to be empty at first glance, but contains values that are undefined

I am facing an issue with my object that I am populating with information. The logs show the object as empty, but when I inspect it in Chrome, it appears to have the correct details filled in. Here is a snapshot of what the logs display: closed: closed o ...

Dynamic Map Maker with JavaScript

Looking to create a tile map using just one picture for a 5x5 grid of small pictures. I've written some Javascript code with nested loops, but only one picture is showing up. If I remove the br tag in the second loop, I get 5 pictures displayed in a r ...