How to implement complex button style using CSS

I have a little problem. I am implementing a website design and need to implement a slightly sophisticated button style (attached here). I do not know how to do this using only CSS.

enter image description here

This will be several styles of buttons, and one of them should be with a transparent background and should get the background color from the element where this button is located. I have implemented a button with a custom background that can be set using CSS. But it is not flexible to use. If I want to use it on different backgrounds, you should add a new style, for example "btn-customColor", etc. Now I have styles for the transparent background, and it looks:

enter image description here

, . , . . btn-transparent btn-blue, btn-green, btn-white ..

, , "". , -. ? , , ..

, : HTML, CSS, JS (jQuery).

, , . .

.

.btn-base {
  padding: 0;
  margin: 0;
  height: 30px;
  outline: none;
  border-radius: 3px;
  background: transparent;
  border: 2px solid #fff;
  font-size: 12px;
  transition: 0.5s;
}

.btn-base>div {
  position: relative;
  width: 101%;
  left: 3px;
  bottom: 8px;
  padding: 5px 15px;
  outline: none;
  border-radius: 3px;
  background: #e4645d;
  /* hardcoded code, must be transparent */
  border: 2px solid #fff;
  font-size: 12px;
}
<button type="submit" class="btn-base btn-transparent">
  <div>Button example</div>
</button>
Hide result
+4
5

.

x3 .

:

.row {
  padding: 20px;
}

.row:nth-child(1) {
  background: #e4645d;
}

.row:nth-child(2) {
  background: #5dace4;
}

.row:nth-child(3) {
  background: #5fe45d;
}

.btn-base {
  padding: 0;
  margin: 0;
  height: 30px;
  outline: none;
  border-radius: 3px;
  background: transparent;
  border: 2px solid #fff;
  font-size: 12px;
  transition: 0.5s;
  /* added */
  position: relative; /* required for absolutely positioned pseudo-elements */
  padding: 0px 10px;
}

/* Additional */

.btn-base:before {
    content: "";
    position: absolute;
    width: 7px;
    height: 30px;
    border: 2px solid #fff;
    border-right: 0;
    right: 100%;
    bottom: -5px;
    top: 5px;
    border-top-left-radius: 3px;
    border-bottom-left-radius: 3px;
    box-sizing: border-box;
}

.btn-base:after {
    content: "";
    position: absolute;
    border: 2px solid #fff;
    height: 9px;
    border-top: 0;
    border-left: 0;
    right: 5px;
    left: 0;
    bottom: -9px;
    border-bottom-right-radius: 3px;
    box-sizing: border-box;
}
<div class="row">
  <button type="submit" class="btn-base btn-transparent">Button example</button>
</div>
<div class="row">
  <button type="submit" class="btn-base btn-transparent">Button example</button>
</div>
<div class="row">
  <button type="submit" class="btn-base btn-transparent">Button example</button>
</div>
Hide result
+8

body{
  background:#e4645d;
  text-align:center;
}
.btn-base {
   padding: 10px;
   margin: 0;
   outline: none;
   border-radius: 3px;
   background: transparent;
   border: 2px solid #fff;
   font-size: 12px;
   transition: 0.5s
   color:white;
        box-shadow: -10px 10px 0 -2px #e4645d, -10px 10px 0 0px white;
}
<button type="submit" class="btn-base btn-transparent">
   Button example
</button>
Hide result
+4

. , , . background-color: inerhit. :

.btn-base {
  padding: 0;
  margin: 0;
  height: 30px;
  outline: none;
  border-radius: 3px;
  background: transparent;
  border: 2px solid #fff;
  font-size: 12px;
  transition: 0.5s;
  color: white;
  position: absolute;
  width: 100%;
}

.button-holder>div {
  color: white;
  position: relative;
  width: calc(100% + 2px);
  left: 5px;
  bottom: 8px;
  padding: 5px 15px;
  outline: none;
  border-radius: 3px;
  background-color: inherit;
  border: 2px solid #fff;
  font-size: 12px;
  box-sizing: border-box;
}

body {
  background-color: teal;
}

.button-holder {
  background-color: inherit;
  display: inline-block;
  position: relative;
}
<div class="button-holder">
  <button type="submit" class="btn-base btn-transparent"></button>
  <div>Button example</div>
</div>
Hide result
+3

( IE/Edge) clip-path css , , , .

, , .

body{background:url('https://placeimg.com/640/480/animals') no-repeat;}
.btn-base {
  margin: 0;
  height: 30px;
  outline: none;
  border-radius: 3px;
  border: 2px solid currentColor;
  font-size: 12px;
  transition: 0.5s;
  padding: 5px 15px;
  font-size: 12px;
  position:relative;
  background:transparent;
  color:#fff;
  cursor:pointer;
}

.btn-base:before {
  content:'';
  position: absolute;
  width: 100%;
  height:100%;
  left: -7px;
  bottom: -10px;
  border-radius: 3px;
  /* hardcoded code, must be transparent */
  border: 2px solid currentColor;
  cursor:pointer;

-webkit-clip-path: polygon(0 0, 5% 0, 5% 88%, 100% 88%, 100% 100%, 0 100%);
clip-path: polygon(0 0, 5% 0, 5% 70%, 100% 70%, 100% 100%, 0 100%);
}
<button type="submit" class="btn-base">
  Button example
</button>
Hide result
+3

box-shadow, .

:

button {
  border: 0;
  background: #666;
  box-shadow: -8px 8px 0 -4px #FFF,
              -8px 8px 0 0px #666;
}
<button>Sample</button>
Hide result
0
source

Source: https://habr.com/ru/post/1689959/


All Articles