2015-10-23 2 views
0

Я искал в Интернете какое-то время и ничего не нашел, поэтому я обращаюсь к вам, ребята.Как сделать эту кнопку в CSS?

мне было интересно, как вы можете сделать кнопку, как это с помощью CSS (On/Off, например кнопки):

Button On/Off

Я уже пытался что-то вроде этого:

HTML:

   <a class="button_tooltip" href="#">On</a> 
       <a class="button_tooltip" href="#">Off</a> 

CSS:

a { 
    color: #76daff; 
    display: inline-block; 
    padding: 8px 16px; 
    position: relative; 
    text-decoration: none; 
} 
a { 
    color: #76daff; 
} 
a.button_tooltip { 
    background: #ccc none repeat scroll 0 0; 
    color: black; 
} 
a.button_tooltip::after { 
    border-top-color: #cccccc; 
} 
a.button_tooltip::after { 
    border-left: 8px solid transparent; 
    border-right: 8px solid transparent; 
    border-top: 8px solid #ccc; 
    content: ""; 
    margin-left: -8px; 
} 
a.button_tooltip { 
    background: #cccccc none repeat scroll 0 0; 
    color: #000000; 
} 
a.button_tooltip::after { 
    border-left: 8px solid transparent; 
    border-right: 8px solid transparent; 
    border-top: 8px solid #ccc; 
    content: ""; 
} 
a.button_tooltip::after { 
    border-top-color: #cccccc; 
} 

Но только дал мне квадрат без маленького треугольника внизу.

+1

Вы также должны предоставить разметку: те ссылки/элементы списка/кнопки? – fcalderan

ответ

2

Это легко можно с 2-мя элементами и с помощью псевдо элемента, чтобы получить немного со стрелкой внизу, чтобы показать.

Это не займет много HTML/CSS для полного и может быть легко изменено для работы в качестве ввода или как тег <a>. Независимо от ваших требований.

$(document).ready(function() { 
 
    $('.btn').click(function() { 
 
    $('.btn').toggleClass('active'); 
 
    }); 
 
});
.container { 
 
    width: 200px; 
 
    height: 100px; 
 
} 
 
.btn { 
 
    width: 100px; 
 
    height: 100px; 
 
    box-sizing: border-box; 
 
    border: 1px solid blue; 
 
    float: left; 
 
    cursor: pointer; 
 
} 
 
.active { 
 
    background: blue; 
 
    position: relative; 
 
} 
 
.active:before { 
 
    content: ''; 
 
    position: absolute; 
 
    width: 50px; 
 
    height: 50px; 
 
    transform: rotate(45deg); 
 
    bottom: -10px; 
 
    left: 25px; 
 
    background: blue; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="container"> 
 
    <div class="btn"></div> 
 
    <div class="btn active"></div> 
 
</div>

+0

THX это именно то, что я искал. – Furnez

0

Здесь вы идете: http://jsfiddle.net/es_kaija/negzqemp/

<div class="switch off"> 
    <div class="toggle"></div> 
<span class="on">ON</span> 
<span class="off">OFF</span> 
</div> 


<style> 
.switch { 
position: relative; 
display: inline-block; 
font-size: 1em; 
font-weight: bold; 
color: #ccc; 
text-shadow: 0px 1px 1px rgba(255,255,255,0.8); 
height: 18px; 
padding: 6px 6px 5px 6px; 
border: 1px solid #ccc; 
border: 1px solid rgba(0,0,0,0.2); 
border-radius: 4px; 
background: #ececec; 
box-shadow: 0px 0px 4px rgba(0,0,0,0.1), inset 0px 1px 3px 0px rgba(0,0,0,0.1); 
cursor: pointer; 
} 

.switch span { display: inline-block; width: 35px; } 
.switch span.On { color: #33d2da; } 

.switch .toggle { 
position: absolute; 
top: 1px; 
width: 37px; 
height: 25px; 
border: 1px solid #ccc; 
border: 1px solid rgba(0,0,0,0.3); 
border-radius: 4px; 
background: #fff; 
background: -moz-linear-gradient(top, #ececec 0%, #ffffff 100%); 
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ececec), color-stop(100%,#ffffff)); 
background: -webkit-linear-gradient(top, #ececec 0%,#ffffff 100%); 
background: -o-linear-gradient(top, #ececec 0%,#ffffff 100%); 
background: -ms-linear-gradient(top, #ececec 0%,#ffffff 100%); 
background: linear-gradient(top, #ececec 0%,#ffffff 100%); 

box-shadow: inset 0px 1px 0px 0px rgba(255,255,255,0.5); 
z-index: 999; 

-webkit-transition: all 0.15s ease-in-out; 
-moz-transition: all 0.15s ease-in-out; 
-o-transition: all 0.15s ease-in-out; 
-ms-transition: all 0.15s ease-in-out; 
} 

.switch.on .toggle { left: 2%; } 
.switch.off .toggle { left: 54%; } 


</style> 

<script> 
$(document).ready(function() { 

    // Switch toggle 
    $('.switch').click(function() { 
     $(this).toggleClass('on').toggleClass('off'); 
    }); 

}); 
</script> 
0

Вы можете сделать это с помощью самого CSS. Вот пример - https://jsfiddle.net/p653bpbe/

HTML

<div class="onoffswitch"> 
    <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked> 
    <label class="onoffswitch-label" for="myonoffswitch"> 
     <span class="onoffswitch-inner"></span> 
     <span class="onoffswitch-switch"></span> 
    </label> 
</div> 

CSS

.onoffswitch { 
    position: relative; width: 90px; 
    -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none; 
} 
.onoffswitch-checkbox { 
    display: none; 
} 
.onoffswitch-label { 
    display: block; overflow: hidden; cursor: pointer; 
    border: 1px solid #2E8DEF; border-radius: 0px; 
} 
.onoffswitch-inner { 
    display: block; width: 200%; margin-left: -100%; 
    transition: margin 0.3s ease-in 0s; 
} 
.onoffswitch-inner:before, .onoffswitch-inner:after { 
    display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 26px; 
    font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold; 
    box-sizing: border-box; 
    border: 2px solid transparent; 
    background-clip: padding-box; 
} 
.onoffswitch-inner:before { 
    content: ""; 
    padding-left: 10px; 
    background-color: #FFFFFF; color: #FFFFFF; 
} 
.onoffswitch-inner:after { 
    content: ""; 
    padding-right: 10px; 
    background-color: #FFFFFF; color: #333333; 
    text-align: right; 
} 
.onoffswitch-switch { 
    display: block; width: 45px; margin: 0px; 
    background: #2E8DEF; 
    position: absolute; top: 0; bottom: 0; 

    transition: all 0.3s ease-in 0s; 
} 
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner { 
    margin-left: 0; 
} 
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch { 
    right: 0px; 
} 
0
<a href="#">Button</a> 

    a { font-size: 0; line-height: 0; text-indent: -4000px; background: #fff; border: 1px solid #007bff; width: 30px; height: 30px; display: block; position: relative; } 
    a:after { position: absolute; top: -1px; left: 30px; width: 30px; height: 30px; content: ''; display: block; background: #007bff; border: 1px solid #007bff; } 
    a:before { content: ''; display: block; width: 0; height: 0; border-style: solid; border-width: 10px 10px 0 10px; border-color: #007bff transparent transparent transparent; position: absolute; bottom: -10px; right: -25px; } 
1

$(document).ready(function() { 
 
    $('.toggle-btn button').click(function() { 
 
    $(this).parent('.toggle-btn').children('button').removeClass('active'); 
 
    $(this).addClass('active'); 
 
    }); 
 
});
.toggle-btn { 
 
    border: 1px solid #4c8cca; 
 
    display: inline-block; 
 
    line-height: 1; 
 
    width: 100px; 
 
} 
 

 
button { 
 
    line-height: 1; 
 
    float: left; 
 
    height: 30px; 
 
    background: none; 
 
    background-color: transparent; 
 
    border: none; 
 
    padding: 0; 
 
    position: relative; 
 
    outline: 0; 
 
    width: 50%; 
 
    cursor: pointer; 
 
} 
 

 
button:hover { 
 
    background-color: #EEE; 
 
} 
 

 
button.active { 
 
    background: #4c8cca; 
 
    background-color: #4c8cca; 
 
    color: #FFF; 
 
} 
 

 
button.active:after { 
 
    content: ''; 
 
    position: absolute; 
 
    width: 10px; 
 
    height: 10px; 
 
    top: 25px; 
 
    transform: rotate(45deg); 
 
    background-color: #4c8cca; 
 
    left: 50%; 
 
    margin-left: -4px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="toggle-btn"> 
 
    <button>Yes</button> 
 
    <button class="active">No</button> 
 
</div>

Смежные вопросы