0

How would I align a button to the right?

I've tried text-align: right; and align-content: right;

I would also like the button have display: flex;

#hideShow {
  display: flex;
  text-align: right;
  align-content: right;
}
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<button class="flex" id="hideShow" onclick="hideBtTS()">Hide</button>
Ghost Ops
  • 1,710
  • 2
  • 13
  • 23
Atramentis
  • 81
  • 10

6 Answers6

2

You should have flex on your parent div. Also, you can try using { display: flex; justify-content: flex-end; }

justify-content will align your button with the end of your parent div (right side of the window).

0

You can use margin-left: auto, but you have to display it as a block as follows -

#hideShow {
display: block;
margin-left: auto;
}

If you want it at centre then also add margin-right: auto as follows -

#hideShow {
display: block;
margin-left: auto;
margin-right: auto;
}
Akshay
  • 126
  • 6
0

Here I am assuming that your button container is 100% width.

CSS:

.btn-container {
    display:flex;
    justify-content:flex-end
}
//#hideShow {
//    display: flex;
//    text-align: right;
//    align-content: right;
//}

HTML:

<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="flex">
    <form action="../index.html" id="BtTS">
        <input type="submit" value="<--- Back to Title Screen" />
    </form>
    <div class="btn-container" align="right">
        <button class="flex" id="hideShow" onclick="hideBtTS()">Hide</button>
    </div>
    </div>
<div id="dividers">
    <hr><br><br>
</div>
</body>
</html>

check the result here

0

You are doing changes on the text inside the button. You have to put "text-align: right" to the container not the button

#right {
  text-align: right;
}
djadweb
  • 29
  • 2
0

Use:

.btn-container {
   justify-content: flex-end;
   position: relative;
   bottom: 38px;
}

Adjust bottom: ; to whatever you need.

This worked for me.

Atramentis
  • 81
  • 10
0

try this

.flex{
 display: flex;
 justify-content: space-between!important;
}
Osman Rafi
  • 938
  • 1
  • 16
  • 37