Home > front end >  Why can't this button have border-radius?
Why can't this button have border-radius?

Time:11-10

The red border is only for reference. I have tried overflow: hidden but it didn't work. I am trying to have the same border radius as the red border. Is there anything that I am doing wrong? Thank you.

*,*::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    --violet: #8F00FF;
}

.rating {
    border: 1px solid red;
    border-radius: 8px;
    width: 30px;
    margin-left: 100px;
    margin-top: 100px;
    background-color: #f0f0f0;
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0px 8px rgba(172, 169, 169, 0.1);
}

button {
    border: none;
    border-radius: 8px;
    align-items: center;
    color: var(--violet);
    font-weight: bold;
    cursor: pointer;
    -webkit-border-radius:10px;
    overflow: hidden;
}

.rating span {
    display: flex;
    justify-content: center;
    color: var(--violet);
    font-weight: bold;
}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Interface</title>

    <!-- CSS Link -->
    <link rel="stylesheet" href="style.css">

    <!-- Boxicons -->
    <script src="https://unpkg.com/[email protected]/dist/boxicons.js"></script>

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- JS Link -->
    <script src="script.js" defer></script>
</head>
<body>
        
        <!-- <div >
           

            
        </div> -->
    
        <div >
            <button> </button>
            <span>12</span>
            <button>-</button>
        </div>
</body>
</html>

CodePudding user response:

You can add overflow: hidden; for .rating class.

.rating {
    ...
    overflow: hidden;
}

OR you just need to add !important rule for border-radius of button. With this way, you don't have to add overflow for .rating.

button {
 ...
 border-radius: 8px !important;
}

*,*::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    --violet: #8F00FF;
}

.rating {
    border: 1px solid red;
    border-radius: 8px;
    width: 30px;
    margin-left: 100px;
    margin-top: 100px;
    background-color: #f0f0f0;
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0px 8px rgba(172, 169, 169, 0.1);
    overflow: hidden;
}

button {
    border: none;
    border-radius: 8px !important;
    align-items: center;
    color: var(--violet);
    font-weight: bold;
    cursor: pointer;
}

.rating span {
    display: flex;
    justify-content: center;
    color: var(--violet);
    font-weight: bold;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Interface</title>

    <!-- CSS Link -->
    <link rel="stylesheet" href="style.css">

    <!-- Boxicons -->
    <script src="https://unpkg.com/[email protected]/dist/boxicons.js"></script>

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- JS Link -->
    <script src="script.js" defer></script>
</head>
<body>
        
        <!-- <div >
           

            
        </div> -->
    
        <div >
            <button> </button>
            <span>12</span>
            <button>-</button>
        </div>
</body>
</html>

CodePudding user response:

You should add overflow: hidden to .rating which would help to fully cover the inner element with the border radius

*,*::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    --violet: #8F00FF;
}

.rating {
    border: 1px solid red;
    border-radius: 8px;
    width: 30px;
    margin-left: 100px;
    margin-top: 100px;
    background-color: #f0f0f0;
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0px 8px rgba(172, 169, 169, 0.1);
    overflow: hidden; /*The change is here*/
}

button {
    border: none;
    border-radius: 8px;
    align-items: center;
    color: var(--violet);
    font-weight: bold;
    cursor: pointer;
    -webkit-border-radius:10px;
    overflow: hidden;
}

.rating span {
    display: flex;
    justify-content: center;
    color: var(--violet);
    font-weight: bold;
}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Interface</title>

    <!-- CSS Link -->
    <link rel="stylesheet" href="style.css">

    <!-- Boxicons -->
    <script src="https://unpkg.com/[email protected]/dist/boxicons.js"></script>

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- JS Link -->
    <script src="script.js" defer></script>
</head>
<body>
        
        <!-- <div >
           

            
        </div> -->
    
        <div >
            <button> </button>
            <span>12</span>
            <button>-</button>
        </div>
</body>
</html>

CodePudding user response:

This behavior is due to bootstrap because in bootstrap <button> tag is already given border-radius:0 so you can't change it on direct tags instead you can make your button a class and give it to <button> tag.

*,*::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    --violet: #8F00FF;
}

.rating {
    border: 1px solid red;
    border-radius: 8px;
    width: 30px;
    margin-left: 100px;
    margin-top: 100px;
    background-color: #f0f0f0;
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0px 8px rgba(172, 169, 169, 0.1);
}

.button {
border: none;
-webkit-border-radius: 8px;
border-radius: 8px;
align-items: center;
color: var(--violet);
font-weight: bold;
cursor: pointer;
overflow: hidden;    
  }

.rating span {
    display: flex;
    justify-content: center;
    color: var(--violet);
    font-weight: bold;
}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Interface</title>

    <!-- CSS Link -->
    <link rel="stylesheet" href="style.css">

    <!-- Boxicons -->
    <script src="https://unpkg.com/[email protected]/dist/boxicons.js"></script>

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- JS Link -->
    <script src="script.js" defer></script>
</head>
<body>
        
        <!-- <div >
           

            
        </div> -->
    
        <div >
            <button > </button>
            <span>12</span>
            <button >-</button>
        </div>
</body>
</html>

  • Related