Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't position button element

enter image description here

I created a submit button using bootstrap but I want to place it where the arrow pointing but I no matter what I write the position doesn’t change it’s like the button stick to the position and I can’t reposition it
how can I place it to be there?

.container {
  position: absolute;
  top: 30%;
  left: 30%;
  transform: translate(-50%, -50%);
  text-align: center;
  /*give the text bolder font*/
  font-weight: bold;
}
/*set the input under the span element*/
input[type=text] {
  text-align: center;
  font-weight: bold;
  font-size: 20px;
  border: 2px solid #ccc;
  border-radius: 4px;
  padding: 12px 10px;
  width: 100%;
  box-sizing: border-box;
  margin-top: 6px;
  margin-bottom: 16px;
  /*set the space from left to 30%*/
  margin-left: 30%;
}
/* set the button under the input element*/
button {
  background-color: #4CAF50;
  color: white;
  padding: 12px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  /*set the space from left to 30%*/
  margin-left: 30%;
}
<!DOCTYPE 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>quiz</title>
    <link rel="stylesheet" href="quiz2.css">

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

</head>
<body>
  <div class="container">
    <span id="question">What type of file do you need to open javascript file ?</span>
    <div class="input-group flex-nowrap">
      <input type="text" id="answer" class="form-control" placeholder="Answer Here..." aria-label="Username" aria-describedby="addon-wrapping">
    </div>
    <button type="button" id="submit" class="btn btn-outline-success">Submit</button>
  </div>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you’re able to change the HTML, here’s a way:

Wrap your button inside another div:

<div class="button-wrapper">
   <button type="button" id="submit" class="btn btn-outline-success">Submit</button>
</div>

Then set the margin-left on that wrapper:

.button-wrapper {
  /*set the space from left to 30%*/
  margin-left: 30%;
}

Check this snippet for the result.

.container {
  position: absolute;
  top: 30%;
  left: 30%;
  transform: translate(-50%, -50%);
  /*give the text bolder font*/
  font-weight: bold;
}


/*set the input under the span element*/

input[type=text] {
  text-align: center;
  font-weight: bold;
  font-size: 20px;
  border: 2px solid #ccc;
  border-radius: 4px;
  padding: 12px 10px;
  width: 100%;
  box-sizing: border-box;
  margin-top: 6px;
  margin-bottom: 16px;
  /*set the space from left to 30%*/
  margin-left: 30%;
}


/* set the button under the input element*/

button {
  background-color: #4CAF50;
  color: white;
  padding: 12px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.button-wrapper {
  /*set the space from left to 30%*/
  margin-left: 30%;
}
<!DOCTYPE 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>quiz</title>
  <link rel="stylesheet" href="quiz2.css">

  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

</head>

<body>
  <div class="container">
    <span id="question"></span>
    <div class="input-group flex-nowrap">
      <input type="text" id="answer" class="form-control" placeholder="Answer Here..." aria-label="Username" aria-describedby="addon-wrapping">
    </div>
    <div class="button-wrapper">
      <button type="button" id="submit" class="btn btn-outline-success">Submit</button>
    </div>
  </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading