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

My button won't go to the top right corner of my screen

I’m new to CSS, JavaScript, and HTML so be patient with me. I created a button that duplicates my div but the button won’t go to the top right of my page. It just stays attached for the div for some reason – image attached for clarification.

Button and were I'm trying to get it to go

body {
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.nameone {
  box-shadow: 0px 0px 6px -1px rgba(0, 0, 0, 0.4);
  position: relative;
  padding: 20px;
  padding-left: 25px;
  padding-right: 25px;
  border-radius: 5%;
}

.buttonformatting {
  background-color: red;
  height: 25px;
  width: 25px;
}

.text {
  border: none;
  text-align: center;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewpoint" content="width=device-width,initial-scale=1">
  <title>TrialV3</title>
  <link href="Style.css" rel="stylesheet" type="text/css">
</head>

<body>

  <div class="nameone">
    <input class="text" type="text" onkeypress="this.style.width = ((this.value.length + 1)*8 ) + 'px';">
  </div>

  <script>
    var i = 0;
    var original = document.querySelector('.nameone');

    function duplicate() {
      var clone = original.cloneNode(true);
      clone.class = ".nameone" + ++i;
      original.parentNode.appendChild(clone);
    }
  </script>

  <button id="buttonone" onclick=duplicate() class="buttonformatting">
    </button>

</body>

<button id="buttonone" onclick=duplicate() class="buttonformatting">
    </button>

</html>

I have tried placing outside of my so it doesn’t get affected by that centering. I also tried putting inside of the body. However I arrange it, it seems like the button doesn’t want to leave the div’s side.

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 :

Why would it go to the top right unless you specify it?
position: absolute; top: 20px; right: 20px also consider position: fixed

body {
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.nameone {
  box-shadow: 0px 0px 6px -1px rgba(0, 0, 0, 0.4);
  position: relative;
  padding: 20px;
  padding-left: 25px;
  padding-right: 25px;
  border-radius: 5%;
}

.buttonformatting {
  background-color: red;
  height: 25px;
  width: 25px;
  position: absolute;
  top: 20px;
  right: 20px;
}

.text {
  border: none;
  text-align: center;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewpoint" content="width=device-width,initial-scale=1">
  <title>TrialV3</title>
  <link href="Style.css" rel="stylesheet" type="text/css">
</head>

<body>

  <div class="nameone">
    <input class="text" type="text" onkeypress="this.style.width = ((this.value.length + 1)*8 ) + 'px';">
  </div>

  <script>
    var i = 0;
    var original = document.querySelector('.nameone');

    function duplicate() {
      var clone = original.cloneNode(true);
      clone.class = ".nameone" + ++i;
      original.parentNode.appendChild(clone);
    }
  </script>

  <button id="buttonone" onclick=duplicate() class="buttonformatting">
    </button>

</body>

</html>
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