问题
I am trying to add a button for numbers a round button. I am able to do it but the text(number is not centered). Ideally if i have 1 to 15 circular 15 buttons from 1 to 15
Code below
body {
padding: 1em;
}
<link
href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"
rel="stylesheet"
id="bootstrap-css"
>
<button type="button" class="btn btn-info btn-circle btn-lg">100</button>
The above code is used from this link
回答1:
You have to include the CSS for .btn-circle
to have the rounded corners. I copied the CSS from the link you provided and removed all padding so the text is centered. This will result in:
.btn-circle {
width: 30px;
height: 30px;
text-align: center;
padding: 0; // changed
font-size: 12px;
line-height: 1.428571429;
border-radius: 15px;
}
.btn-circle.btn-lg {
width: 50px;
height: 50px;
padding: 0; // changed
font-size: 18px;
line-height: 1.33;
border-radius: 25px;
}
.btn-circle.btn-xl {
width: 70px;
height: 70px;
padding: 0; // changed
font-size: 24px;
line-height: 1.33;
border-radius: 35px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<button type="button" class="btn btn-info btn-circle btn-lg">100</button>
回答2:
These changes will produce circular buttons with centered text:
include the
.btn-circle
css rules from the link you provided,wrap the button text in a
span
and give thespan
negative margins.
body {
padding: 1em;
}
.btn-circle {
width: 30px;
height: 30px;
text-align: center;
padding: 6px 0;
font-size: 12px;
line-height: 1.428571429;
border-radius: 15px;
}
.btn-circle.btn-lg {
width: 50px;
height: 50px;
padding: 10px 16px;
font-size: 18px;
line-height: 1.33;
border-radius: 25px;
}
.btn-circle.btn-xl {
width: 70px;
height: 70px;
padding: 10px 16px;
font-size: 24px;
line-height: 1.33;
border-radius: 35px;
}
/* use negative margins to accommodate wider button text */
.btn-circle span {
margin: 0 -2rem;
}
<link
href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"
rel="stylesheet"
id="bootstrap-css"
>
<button
type="button"
class="btn btn-info btn-circle btn-lg"
><span>100</span></button>
回答3:
A very simple class will solve your problem-
<button type="button" class="btn btn-info p-5 rounded-circle btn-lg">100</button>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<style>
body {
padding: 1em;
}
</style>
</head>
<body>
<button type="button" class="btn btn-info p-5 rounded-circle btn-lg">100</button>
</body>
</html>
来源:https://stackoverflow.com/questions/65440623/bootstrap-circled-button-for-numbers-at-center