I have 2 elements that represent +/- signs, When the two elements are visible they represent +
, On clicking the vertical element disappears and it becomes -
.
Both + and - signs are inside a circle, I want to center both vertical and horizontal elements inside that circle.
Here is a fiddle: http://jsfiddle.net/9ek3gt7o/10
The HTML:
<span class="plusminussign closed">
<div class="circle">
<div class="horizontal"></div>
<div class="vertical"></div>
</div> <!-- .circle -->
</span> <!-- .plusminussign -->
The CSS:
.plusminussign{
position: relative;
display:inline-block;
height: 24px;
width: 24px;
vertical-align: bottom;
opacity: .7;
background: green;
border-radius: 50%;
color: #fff;
margin: 10px auto;
cursor: pointer;
}
.circle .horizontal {
position: absolute;
background-color: #fff;
width: 15px;
height: 2.5px;
left: 50%;
top: 50%;
}
.circle .vertical {
position: absolute;
background-color: #fff;
width: 2.5px;
height: 15px;
left: 50%;
top: 50%;
}
.closed .horizontal {
transition: all 0.5s ease-in-out;
transform: rotate(-90deg);
opacity: 1;
}
.closed .vertical {
transition: all 0.5s ease-in-out;
transform: rotate(-90deg);
}
.opened {
opacity: 1;
}
.opened .horizontal {
transition: all 0.5s ease-in-out;
transform: rotate(90deg);
opacity: 0;
}
.opened .vertical {
transition: all 0.5s ease-in-out;
transform: rotate(90deg);
}
On clicking, The class opened
will be added to the container .plusminussign
.
jQuery:
$('.plusminussign').on('click', function(){
$(this).toggleClass('opened');
});
I want a x-browser compatible responsive solution, So that I won't lose the positioning if the screen gets smaller.
How to center both horizontal and vertical elements inside the circle?