I am making todo list with JS and jQuery. And I have come across a problem where, I am appending the button into the HTML with JS (code below). And the problem is that the button is appended with class to it. The class is set to just give the button width, height ,bacground-color, color, border, and border-radius.
The problem apears when I add the border-radius property to the button. The border becomes round and thas okay, but on the places where border shinked it is now white (image below).
Does anyone knows why is this happening, and how can I fix this.
**//Everything is happening on a button click**
**//Here is the css class**
.btn{
width: 30px;
height: 30px;
background-color: var(--boja1);
color: var(--boja4);
border: 2px solid var(--boja4);
border-radius: 20px;
}
**//Here I am appending a div element to html**
var boxx=document.createElement("div");
boxx.innerHTML=`<div class="box" id="box"></div>`;
txt1.before(boxx);
**//Here I am apending not important P thag to the div eleement**
var element=document.createElement("p");
element.innerHTML=`<p class="newItem" id="new`+ne+`" >`+text+`</p>`;
$("#box").append(element);
**//And here I am appending the button that is causing me the problem to the P thag above**
var bt=document.createElement("button");
bt.innerHTML=`<button class="btn" id=""> ✕</button>`
$(`#new`+ne+``).append(bt);
This is how the button looks before adding the border-radius property in css
2
Answers
This is because the parent element background is visible after the button’s border gets the radius. You are appending the button to the $(
#new
+ne+“) element, You have to add a radius to that parent element too.OR deal it in
.class
OR Make the
background: transparent
To fix this issue you need to ensure that the
border-radius
is applied correctly without any white gaps, you can use theborder-collapse
property and set it to separate on the button’s parent element. Here’s how you can modify your code:Make sure that you apply the border-collapse property to the correct parent element to target the specific area where you want the button’s border-radius to work as expected.