[css] Circle button css

I'm a beginner and very confused, as a div tag when I give the same width and height with border-radius: 50% it always becomes circle. but with the tag a in case I want to make a circle button, It doesnt work that way. This is when I try to make a circle border button clickable.

_x000D_
_x000D_
 
.btn {
  height: 300px;
  width: 300px;
  border-radius: 50%;
  border: 1px solid red;
}
_x000D_
<a class="btn" href="#"><i class="ion-ios-arrow-down"></i></a>
 
_x000D_
_x000D_
_x000D_

This question is related to css button geometry

The answer is


_x000D_
_x000D_
.round-button {_x000D_
  width:25%;_x000D_
}_x000D_
.round-button-circle {_x000D_
  width: 100%;_x000D_
  height:0;_x000D_
  padding-bottom: 100%;_x000D_
  border-radius: 50%;_x000D_
  border:10px solid #cfdcec;_x000D_
  overflow:hidden;_x000D_
        _x000D_
  background: #4679BD; _x000D_
  box-shadow: 0 0 3px gray;_x000D_
}_x000D_
.round-button-circle:hover {_x000D_
  background:#30588e;_x000D_
}_x000D_
.round-button a {_x000D_
  display:block;_x000D_
  float:left;_x000D_
  width:100%;_x000D_
  padding-top:50%;_x000D_
  padding-bottom:50%;_x000D_
  line-height:1em;_x000D_
  margin-top:-0.5em;_x000D_
        _x000D_
  text-align:center;_x000D_
  color:#e2eaf3;_x000D_
  font-family:Verdana;_x000D_
  font-size:1.2em;_x000D_
  font-weight:bold;_x000D_
  text-decoration:none;_x000D_
}
_x000D_
<div class="round-button"><div class="round-button-circle"><a href="http://example.com" class="round-button">Button!!</a></div></div>
_x000D_
_x000D_
_x000D_

or very simple for <a/>

_x000D_
_x000D_
.round-button {_x000D_
    display:block;_x000D_
    width:80px;_x000D_
    height:80px;_x000D_
    line-height:80px;_x000D_
    border: 2px solid #f5f5f5;_x000D_
    border-radius: 50%;_x000D_
    color:#f5f5f5;_x000D_
    text-align:center;_x000D_
    text-decoration:none;_x000D_
    background: #555777;_x000D_
    box-shadow: 0 0 3px gray;_x000D_
    font-size:20px;_x000D_
    font-weight:bold;_x000D_
}_x000D_
.round-button:hover {_x000D_
    background: #777555;_x000D_
}
_x000D_
<a href="http://example.com" class="round-button">Button</a>
_x000D_
_x000D_
_x000D_

for jsfiddle reference click here


HTML:

<div class="bool-answer">
  <div class="answer">Nej</div>
</div>

CSS:

.bool-answer {
    border-radius: 50%;
    width: 100px;
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}

you could always do

html: <div class = "btn"> <a> <button> idk whatever you want to put in the button </button> </a> </div>

and then do

css: .btn a button { border-radius: 50% }

works perfect in my opinion


Add display: block;. That's the difference between a <div> tag and an <a> tag

.btn {
      display: block;
      height: 300px;
      width: 300px;
      border-radius: 50%;
      border: 1px solid red;
    }

The problem is that the actual width of an a tag depends on its contents. Your code has no text in the a tag, so it appears like a hunger-sunken circle. If you use the div tag along the a, you get the desired results.

Check this code out:

_x000D_
_x000D_
.btn {
  background-color: green;
  border-radius: 50%;
  /*this will rounden-up the button*/
  width: 80px;
  height: 80px;
  /*keep the height and width equal*/
}
_x000D_
<a href="#">
 <!--use the URL you want to use-->
 <button class="btn">press me</button>
 </a>
_x000D_
_x000D_
_x000D_


For create circle button you are this codes:

_x000D_
_x000D_
.circle-right-btn {
    display: block;
    height: 50px;
    width: 50px;
    border-radius: 50%;
    border: 1px solid #fefefe;
    margin-top: 24px;
    font-size:22px;
}
_x000D_
<input  class="circle-right-btn" type="submit" value="<">
_x000D_
_x000D_
_x000D_


Here is a flat design circle button:

enter image description here

_x000D_
_x000D_
.btn {_x000D_
  height: 80px;_x000D_
  line-height: 80px;  _x000D_
  width: 80px;  _x000D_
  font-size: 2em;_x000D_
  font-weight: bold;_x000D_
  border-radius: 50%;_x000D_
  background-color: #4CAF50;_x000D_
  color: white;_x000D_
  text-align: center;_x000D_
  cursor: pointer;_x000D_
}
_x000D_
<div class="btn">+</div>
_x000D_
_x000D_
_x000D_

but the problem is that the + might not be perfectly centered vertically in all browsers / platforms, because of font differences... see also this question (and its answer): Vertical alignement of span inside a div when the font-size is big


An round button with box-shadow https://v2.vuetifyjs.com/en/components/floating-action-buttons/

_x000D_
_x000D_
.btn {
  height: 50px;
  width: 50px;
  line-height: 50px;
  font-size: 2em;
  border-radius: 50%;
  background-color: red;
  color: white;
  text-align: center;
  border: none;
  cursor: pointer;
  position: fixed;
  z-index: 1;
  bottom: 10%;
  right: 4%;
  box-shadow: 0 3px 5px -1px rgba(0, 0, 0, 0.2), 0 6px 10px 0 rgba(0, 0, 0, 0.14), 0 1px 18px 0 rgba(0, 0, 0, 0.12);
}
_x000D_
<div class="btn">+</div>
_x000D_
_x000D_
_x000D_


Though I can see an accepted answer and other great answers too but thought of sharing what I did to solve this issue (in just one line).

CSS ( Created a Class ) :

.circle {
    border-radius: 50%;
}

HTML (Added that css class to my button) :

<a class="button circle button-energized ion-paper-airplane"></a>

So Easy Right ?

Note : What I actually did was proper use of ionic classes with just one line of css.

See Result your self on this JSFiddle :

https://jsfiddle.net/nikdtu/cnx48u43/


use this css.

_x000D_
_x000D_
.roundbutton{_x000D_
          display:block;_x000D_
          height: 300px;_x000D_
          width: 300px;_x000D_
          border-radius: 50%;_x000D_
          border: 1px solid red;_x000D_
          _x000D_
        }
_x000D_
<a class="roundbutton" href="#"><i class="ion-ios-arrow-down"></i></a>
_x000D_
_x000D_
_x000D_