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.
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.
2
Answers
Why would it go to the top right unless you specify it?
position: absolute; top: 20px; right: 20px
also considerposition: fixed
CSS Code: