0

I am just learning Angular.Actually I am trying to centralized text using Flex.I tried and the text also centralized but the problem was it is not look like professional.Can you please help me with this.I want like:

                                 Account Name  Dev
                                       Region  North Virginia
                                    User Name  Ramya

I tried and it looks like:

                                 Account Name  Dev
                                Region  North Virginia
                                  User Name  Ramya

CSS I tried:

<div style="flex: 1">
<div  style="display: flex;flex-direction:row;justify-content:center;">
    <span>Account</span>
    <span>{{' ' + recoveryaccount}}</span>
</div>  
<div  style="display: flex;flex-direction:row;justify-content:center;">
    <span>Region</span>
    <span>{{' '}}{{selectedrestorepoint?.instances?.length  ? (selectedrestorepoint.instances[0].aws_region | region) : ' '}}</span>
</div>
</div>

I want the above format.Can you please help with this.Seriouly I am struggling. Thanks in advance :)

Chellappan வ
  • 23,645
  • 3
  • 29
  • 60
codebuff
  • 93
  • 3
  • 15

3 Answers3

0

if you want to use flex box to put the element at the center of you div, the best and reliable way is, using the flex class in the bootstrap. the link below help you surely about using the flex box to center the element. i wish it helps you.

https://www.w3schools.com/bootstrap4/bootstrap_flex.asp

Seyed-Amir-Mehrizi
  • 720
  • 1
  • 5
  • 19
0

As you said you are currently learning. Below link is a great source as per me for understanding flex and its functionality. Hope this helps.

https://tburleson-layouts-demos.firebaseapp.com/#/docs

AshishKh
  • 46
  • 5
0

What you are trying to acheive is displaying data in tabular form, for which you should be using CSS grids or CSS tables as they are designed for these usecases.

Though the below snippet acheives what you want using CSS flexbox solution, I won't recommend using this approach.

<html>
<head>
<title>Sample</title>
<style>
 .flex-container {
  display: flex;
  justify-content: center;
 }
 .flex-item {
  width: 50%;
  padding: 0 5px;
 }
 .flex-item:first-of-type {
  text-align: right;
 }
</style>
</head>
<body>
<div class="flex-container">
 <span class="flex-item">Account</span>
 <span class="flex-item">Dev</span>
</div>  
<div class="flex-container">
 <span class="flex-item">Region</span>
 <span class="flex-item">North Virginia</span>
</div>
<div class="flex-container">
 <span class="flex-item">User Name</span>
 <span class="flex-item">Ramya</span>
</div>
</body>
</html>

PS: Use CSS paddings or margins to add space between elements instead of adding space character in HTML template.

Hope this helps you. Happy coding!

Edit: Refer the below links for more information on CSS tables and grids.

Shravan
  • 1,182
  • 8
  • 21