Languages

CSS - how to create bean button?

3 points
Asked by:
Vanessa-Drake
718

How can I create a bean button?

I was trying border-radius property with percentage value like 30% or 50% but it makes ellipse.

My code:

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    .bean-button {
        padding: 10px 20px;
        border: none;
        border-radius: 50%; /* doesn't work */
        background: #3085d6;
        font-weight: bold;
        color: white;
    }

  </style>
</head>
<body>
  <button class="bean-button">Click me!</button>
</body>
</html>

I need something like this:

CSS - how to create bean button?
CSS - bean button
1 answer
3 points
Answered by:
Vanessa-Drake
718

You shouldn't use percentage values with border-radius property.

Quick solutions:

Set border-radius property value to:

  1. 50% (or more) of button's height using some unit of: pxemrem, etc,
    e.g.
    for height: 50px border-radius: 25px
    for height: 10em border-radius: 5em
    for height: 10rem border-radius: 5rem
    etc.
  2. very big value using some unit of: pxemrem, etc,
    e.g. 1000px, 500rem or 500rem,

 

Practical example:

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    .bean-button {
        padding: 10px 20px;
        border: none;
        border-radius: 1000px;  /* <--- makes button in bean shape */
        background: #3085d6;
        font-weight: bold;
        color: white;
    }
    
    .bean-button:hover {
        background: #3b8cd8;
    }

  </style>
</head>
<body>
  <button class="bean-button">Click me!</button>
</body>
</html>

 

Reerences

  1. CSS values and units - Learn web development | MDN
0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join