-1

I have two form buttons that are stretched out to my container. and it is displayed line by line. Is there any way to make it side by side and centralised?

.submit1 {
  background-color: #008CBA;
  color: white;
  text-align: center;
  display: inline-block;
  font-size: 18px;
  border: none;
}

.submit2 {
  background-color: #BA002D;
  color: white;
  text-align: center;
  display: inline-block;
  font-size: 18px;
  border: none;
}
<html>

<body>
  <form action="listingsPage.php" method="post">
    <input type="submit" value="Express Interest" class="submit1">
  </form>

  <form action="listingsPage.php" method="post">
    <input type="submit" value="Back to Listings" class="submit2">
  </form>
</body>

</html>

Image of Output: https://ibb.co/rctwhTH

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Kinja
  • 449
  • 5
  • 22
  • Why do you have two separate forms? That's what's causing the issue... Also, the code you posted does not produce the output you show (please repost using the image icon in the editor toolbar). – Heretic Monkey Jan 22 '21 at 19:25

4 Answers4

3

Do you want like this:

.submit1 {
    background-color: #008CBA;
    color: white;
    text-align: center;
    display: inline-block;
    font-size: 18px;
    border: none;
}
.submit2 {
    background-color: #BA002D;
    color: white;
    text-align: center;
    display: inline-block;
    font-size: 18px;
    border: none;
}

.form1 {
  display:inline-block;
}
.center {
  text-align:center;
}
 <body>
   <div class="center">
     <form class="form1" action ="listingsPage.php" method="post">
        <input type="submit" value="Express Interest" class="submit1">
    </form>
    
    <form class="form1" action ="listingsPage.php" method="post">
        <input type="submit" value="Back to Listings" class="submit2">
    </form>
   </div>
  </body>
Sunil
  • 411
  • 5
  • 12
1

Add this to your buttons

#button1 , #button2 {
display:inline-block;
/**other codes**/
}
1

use flexbox, it will save you a lot of work

.submit1 {
  background-color: #008CBA;
  color: white;
  text-align: center;
  
  font-size: 18px;
  border: none;
}

.submit2 {
  background-color: #BA002D;
  color: white;
  text-align: center;
  
  font-size: 18px;
  border: none;
}

#container{
display:flex;
justify-content:center}
<html>

<body>
<div id='container'>
  <form action="listingsPage.php" method="post">
    <input type="submit" value="Express Interest" class="submit1">
  </form>

  <form action="listingsPage.php" method="post">
    <input type="submit" value="Back to Listings" class="submit2">
  </form>
</div>
</body>

</html>
DCR
  • 14,737
  • 12
  • 52
  • 115
0

Try to add style to the forms elements , like so:

html:

<body>
  <form action="listingsPage.php" method="post" class="form1">
    <input type="submit" value="Express Interest" class="submit1">
  </form>

  <form action="listingsPage.php" method="post" class="form1">
    <input type="submit" value="Back to Listings" class="submit2">
  </form>
</body>

</html>

css :

 submit1 {
  background-color: #008CBA;
  color: white;
  text-align: center;
  display: inline;
  font-size: 18px;
  border: none;
}

.submit2 {
  background-color: #BA002D;
  color: white;
  text-align: center;
  display: inline;
  font-size: 18px;
  border: none;
}

.form1{
  display:inline;
}

in other scenarios i recommend using flexbox , it's making positioning much more easy .

Arik Jordan Graham
  • 301
  • 1
  • 3
  • 9