HTML & CSS: Text on a button - html

I have a social media button at the home page of my personal website. Actually it is working pretty well but when I try to add a text on the button (eg. FOLLOW) the text layer makes it unclickable. My code has no JS function involved. How can I solve this problem?
Thanks in advance.
Edit: CSS code added.
Edit #2: Thank you for all the answers. However the <button> tag and JS codes didn't work for me in this situation. I finally managed to reduce the text layer area by removing height and width properties from the .social-text class and now the text doesn't affect the button functionality. It still overlaps the button but at a minimum area and doesn't cause an issue anymore. I'm adding a screenshot of fixed button. Happy coding!
HTML:
<div>
<ul id="menu">
<a class="menu-button icon-plus" href="#menu" title="Show navigation"></a>
<a class="menu-button icon-minus" href="#0" title="Hide navigation"></a>
<li class="menu-item">
<a href="https://www.instagram.com" target="_blank">
<span class="fa fa-instagram"></span>
</a>
</li>
<li class="menu-item">
<a href="https://www.facebook.com" target="_blank">
<span class="fa fa-facebook"></span>
</a>
</li>
<li class="menu-item">
<a href="https://twitter.com" target="_blank">
<span class="fa fa-twitter"></span>
</a>
</li>
<li class="menu-item">
<a href="https://linkedin.com/in" target="_blank">
<span class="fa fa-linkedin"></span>
</a>
</li>
</ul>
<span class="social-text">FOLLOW</span>
</div>
CSS:
#menu {
text-align: center;
width: 11vw;
height: 11vw;
position: absolute;
left: 50%;
top: 23vw;
margin-left: 23vw;
margin-top: 6vw;
list-style: none;
font-size: 2.5vw;
}
.menu-button {
opacity: 0;
z-index: -1;
}
.menu-button {
width: 11vw;
height: 11vw;
position: absolute;
left: 50%;
top: 50%;
margin: -5.8vw 0 0 -5.8vw;
border-radius: 50%;
background: #424242;
background-size: 100%;
overflow: hidden;
text-decoration: none;
}
#menu:not(:target)>a:first-of-type,
#menu:target>a:last-of-type {
opacity: 1;
z-index: 1;
}
#menu:not(:target)>.icon-plus:before,
#menu:target>.icon-minus:before {
opacity: 1;
}
.menu-item {
width: 5.5vw;
height: 5.5vw;
position: absolute;
left: 55%;
line-height: 1vw;
top: 70%;
margin: -3.9vw 0 0 -3.9vw;
border-radius: 50%;
background-color: #424242;
transform: translate(0vw, 0vw);
transition: transform 500ms;
z-index: -2;
transition: .5s;
}
.menu-item:hover{
opacity: 0.5;
box-shadow: 0 0.4vw 0.8vw black;
}
.menu-item a {
color: #fff;
position: relative;
top: 30%;
left: 0;
text-decoration: none;
}
#menu:target>.menu-item:nth-child(6) {
transform: rotate(60deg) translateY(-11.7vw) rotate(300deg);
transition-delay: 0s;
}
#menu:target>.menu-item:nth-child(5) {
transform: rotate(20deg) translateY(-12.1vw) rotate(-20deg);
transition-delay: 0.1s;
}
#menu:target>.menu-item:nth-child(3) {
transform: rotate(-20deg) translateY(-12.1vw) rotate(20deg);
transition-delay: 0.2s;
}
#menu:target>.menu-item:nth-child(4) {
transform: rotate(-60deg) translateY(-11.7vw) rotate(60deg);
transition-delay: 0.3s;
}
.social-text {
text-align: center;
width: 11vw;
height: 11vw;
position: absolute;
left: 50%;
top: 23vw;
margin-left: 23vw;
margin-top: 6vw;
z-index: 2;
}

Use a button tag in your span i.e,
<span><button class="social-text">Follow</button></span>
or either directly use <button> no need to add <span> . Here goes the JS:-
const btn=document.querySelector('.social-text');
btn.addEventListener("click",function(){
console.log("Followed");
})

You can try using a <button>
const btn = document.getElementById("btn-follow");
btn.addEventListener("click", () => {
console.log("followed");
});
<button id="btn-follow">FOLLOW</button>
Or you could add a role="button" to your span tag
const span = document.getElementById("span-follow");
span.addEventListener("click", () => {
console.log("followed");
});
<span id="span-follow" role="button">FOLLOW</span>
If you want to create a circle button, you can create a circle with a <div> and use it like a <button>
const btn = document.getElementById("btn-follow");
btn.addEventListener("click", () => {
console.log("followed");
});
.social-circle {
text-align: center;
width: 11vw;
height: 11vw;
line-height: 11vw;
border-radius: 50%;
background: #F77;
}
.social-text {
color: #fff;
}
.cursor-pointer {
cursor: pointer;
}
<div class="social-circle cursor-pointer" id="btn-follow" role="button">
<span class="social-text" role="button">FOLLOW</span>
</div>

You haven't used the button tag. So, only the 'Follow' text is showing. Try this.
<button class="social-text">Follow</button>

Related

How to apply rounded border radius in opposite direction on hover on menu item in menubar [duplicate]

This question already has an answer here:
CSS transparent curved shape with two rounded sides
(1 answer)
Closed 6 months ago.
How to apply rounded border radius in opposite direction on hover on menu item in menubar
I want this effect on menu item hover
Currently my menubar looks like this
This is my css code
sidebar-menu .dropdown-toggle:hover, .sidebar-menu .show>.dropdown-toggle {
background: #f8f9fa;
color: #2daab8;
border-top-left-radius: 50px;
border-bottom-left-radius: 50px;
border-bottom-right-radius: 70px;
border-top-right-radius: 70px;
width: 250px;
}
HTML Code:
<div class="left-side-bar lftsideBar">
<div class="brand-logo">
<a href="{% url 'home' %}">
<img src="{% static 'website/vendors/images/Rectangle_33.png' %}" alt="" />
</a>
</div>
<div class="close-sidebar" data-toggle="left-sidebar-close">
<i class="ion-close-round"></i>
</div>
<div class="menu-block customscroll">
<div class="sidebar-menu">
<ul id="accordion-menu menucls" style="margin-left: 25px !important;margin-bottom:250px;">
<li>
<a href="{% url 'home' %}" class="dropdown-toggle no-arrow">
<span class="micon dw dw-house-1"></span><span class="mtext">Home</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Client</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Medical</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Social</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Transportation</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Activity</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Food</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Reports</span>
</a>
</li>
</ul>
</div>
</div>
Can you please suggest me to what css make changes so I can make exactly same design as per screenshot-1 on each and every item of menubar?
You'll need imagination to be able to create the inverted radius. We could use a circle and use it to mask a square, but CSS mask is not very well supported still. But we can extend on this strategy and use borders to fill the part of a square not occupied by the circle.
In my example below, I've used a holder with overflow:hidden to hide any overflowing border. The size of the holder also determines the size of the final curve since the div inside spans to 100%. Instead of using a full circle, I've used just the 1/4 of it that was needed by rounding just the interesting corner to 100%. The color of the border determines the color of the curve.
.holder{
width:100px;
height:100px;
overflow:hidden;
}
.holder div{
width:100%;
height:100%;
border-bottom-right-radius:100%;
border:99999px solid black;
border-left:none;
border-top:none;
}
<div class="holder">
<div></div>
</div>
Now, armed with that knowledge, you can easily do the same for the bottom part by rounding a different corner. You'll need to add the markup to each menu element tough, and play with the display property. You could try to reduce as much as possible by using the ::before and/or ::after elements but I doupt you'd be able to save much (just maybe get to replace the inner div maybe?)
source code from there
const initNavBar = () => {
const menusEl = document.querySelectorAll('.side-bar ul li')
menusEl.forEach(menu => menu.addEventListener('click', ()=> {
const menuActiveEl = document.querySelector('.side-bar ul li.active')
menuActiveEl.classList.remove('active')
menu.classList.add('active')
}))
}
initNavBar()
:root {
--color-primary: #1380b8;
--color-secondary: #33ace3;
}
aside.side-bar-wrap {
--radius-size: 25px;
height: 98vh;
position: fixed;
top: 1vh;
left: 1vh;
overflow-y: scroll;
overflow-x: hidden;
border-radius: var(--radius-size);
padding-right: 2px;
}
aside.side-bar-wrap::-webkit-scrollbar {
width: 10px;
}
aside.side-bar-wrap::-webkit-scrollbar-track {
background-color: transparent;
}
aside.side-bar-wrap::-webkit-scrollbar-thumb {
border-radius: var(--radius-size);
background-color: var(--color-primary);
}
nav.side-bar {
min-height: 100%;
background-color: var(--color-primary);
display: inline-block;
border-left: var(--radius-size) solid var(--color-secondary);
border-right: var(--radius-size) solid var(--color-primary);
border-radius: var(--radius-size);
}
nav.side-bar .logo-area {
--curve-size: calc(2 * var(--radius-size));
position: relative;
display: flex;
justify-content: center;
align-items: center;
padding: 10px;
min-height: var(--curve-size);
background-color: var(--color-secondary);
border-radius: 0 var(--radius-size) var(--radius-size) 0;
box-shadow: var(--radius-size) 0 var(--color-secondary);
}
nav.side-bar .logo-area::after {
content: '';
width: var(--curve-size);
height: var(--curve-size);
background-color: var(--color-primary);
border-radius: 50%;
position: absolute;
bottom: calc(-1 * var(--curve-size));
left: 0;
box-shadow: calc(-1 * var(--curve-size) * 0.5) calc(-1 * var(--curve-size) * 0.5) var(--color-secondary);
}
nav.side-bar .logo-area img {
position: absolute;
max-height: 75%;
transition-duration: 1s;
}
aside.side-bar-wrap:hover nav.side-bar .logo-area img.min {
max-height: 0;
opacity: 0;
}
nav.side-bar .logo-area img.max {
max-width: 0;
opacity: 0;
transition-duration: 1s;
}
aside.side-bar-wrap:hover nav.side-bar .logo-area img.max {
max-width: 90%;
opacity: 1;
}
nav.side-bar ul {
padding: 0;
margin: calc(2 * var(--radius-size)) 0;
display: flex;
flex-direction: column;
}
nav.side-bar ul li {
height: 50px;
padding: 10px var(--radius-size);
list-style: none;
border-radius: var(--radius-size);
margin-bottom: var(--radius-size);
z-index: 1;
}
nav.side-bar ul li:not(.active) {
z-index: 2;
}
nav.side-bar ul li:not(.active):hover {
backdrop-filter: brightness(0.85);
}
nav.side-bar ul li.active {
position: relative;
background-color: var(--color-secondary);
border-radius: 0 var(--radius-size) var(--radius-size) 0;
}
nav.side-bar ul li.active::before,
nav.side-bar ul li.active::after {
--curve-size: calc(2 * var(--radius-size));
content: '';
width: var(--curve-size);
height: var(--curve-size);
background-color: var(--color-primary);
border-radius: 50%;
position: absolute;
}
nav.side-bar ul li.active::before {
top: calc(-1 * var(--curve-size));
left: 0;
box-shadow: calc(-1 * var(--curve-size) * 0.5) calc(var(--curve-size) * 0.5) var(--color-secondary);
}
nav.side-bar ul li.active::after {
bottom: calc(-1 * var(--curve-size));
left: 0;
box-shadow: calc(-1 * var(--curve-size) * 0.5) calc(-1 * var(--curve-size) * 0.5) var(--color-secondary);
}
nav.side-bar ul li a{
color: white;
font-size: 16pt;
width: 100%;
height: 100%;
display: flex;
gap: 0;
align-items: center;
text-decoration: none;
transition: 1s;
}
aside:hover nav.side-bar ul li a{
gap: 10px;
}
nav.side-bar ul li a span {
display: flex;
transition: 0.75s cubic-bezier(0.39, 0.58, 0.57, 1);
}
nav.side-bar ul li a span.icon {
font-size: 24pt;
}
nav.side-bar ul li a span.title {
max-width: 0;
opacity: 0;
}
aside:hover nav.side-bar ul li a span.title {
width: auto;
max-width: 10rem;
opacity: 1;
}
<aside class="side-bar-wrap">
<nav class="side-bar">
<div class="logo-area">
<img class="min" src="images/min-logo.png" alt="logo">
<img class="max" src="images/max-logo.png" alt="logo">
</div>
<ul>
<li class="active">
<a href="#">
<span class="title">Home</span>
</a>
</li>
<li>
<a href="#">
<span class="title">News</span>
</a>
</li>
<li>
<a href="#">
<span class="title">Jobs</span>
</a>
</li>
<li>
<a href="#">
<span class="title">Contact</span>
</a>
</li>
<li>
<a href="#">
<span class="title">About</span>
</a>
</li>
</ul>
</nav>
</aside>

Can't get animated link hover working with Tailwind CSS

Hi I'm trying to get an animation working when I hover over links with Nextjs and Tailwind. Anything would help thanks
Example of the working code in standard CSS/HTML
<div class="link-cont">
<div class="link-wrapper">
<a class="link hover-1" href="#">#1 - left to right</a>
</div>
</div>
CSS
.link-cont {
position: relative;
font-size: 24px;
}
.link {
display: inline-block;
position: relative;
text-decoration: none;
padding: 10px 0;
color: #fff;
}
.link-wrapper {
position: relative;
display: block;
padding: 20px 0;
}
.hover-1 {
&:after {
content:'';
position: absolute;
width: 100%;
height: 3px;
bottom: 0;
left: 0;
background-color: #red;
transform: scaleX(0);
transform-origin: bottom right;
transition: transform 0.3s;
}
&:hover {
&:after {
transform-origin: bottom left;
transform: scaleX(1);
}
}
}
My code in tailwind
<div className="">
<Link href="/models">
<a className="
ml-auto
font-serif
text-6xl
inline-block
relative
no-underline
px-[10px]
after:absolute
after:w-[100%]
after:h-[5px]
after:bg-black
after:bottom-0
after:left-0
after:scale-x-0
after:origin-bottom-right
after:transition-transform
hover:after:origin-bottom-left
hover:after:scale-x-1
">
models
</a>
</Link>
<Link href="/contact">
<a className="mx-10 font-serif text-6xl">contact</a>
</Link>
</div>
Not sure if this is bugging out from the after and hover states but you should be able to stack pseudo selectors and stuff as per the tailwind docs. Don't really know what's wrong with the code as the after portion of the css does not show up in the inspector.

Link Bootstrap with my caroussel's image disappears

I have this carousel which works fine, i need to add the bootstrap 4 style to my page, whenever i add the link, my carousel's pictures disappear.
I tried to figure out if there is anything confusing between the classes but still can't find anything, i also tried to add '!important' to the img tag in css but still can't solve it, what seems to be the problem ? Thanks.
var carousel = document.querySelector('.acc-carousel');
var container = carousel.querySelector('.carousel-container');
var prevBtn = carousel.querySelector('.carousel-prev');
var nextBtn = carousel.querySelector('.carousel-next');
var pagination = carousel.querySelector('.carousel-pagination');
var bullets = [].slice.call(carousel.querySelectorAll('.carousel-bullet'));
var totalItems = container.querySelectorAll('.carousel-item').length;
var percent = (100 / totalItems);
var currentIndex = 0;
function next() {
slideTo(currentIndex + 1);
}
function prev() {
slideTo(currentIndex - 1);
}
function slideTo(index) {
index = index < 0 ? totalItems - 1 : index >= totalItems ? 0 : index;
container.style.WebkitTransform = container.style.transform = 'translate(-' + (index * percent) + '%, 0)';
bullets[currentIndex].classList.remove('active-bullet');
bullets[index].classList.add('active-bullet');
currentIndex = index;
}
bullets[currentIndex].classList.add('active-bullet');
prevBtn.addEventListener('click', prev, false);
nextBtn.addEventListener('click', next, false);
pagination.addEventListener('click', function(e) {
var index = bullets.indexOf(e.target);
if (index !== -1 && index !== currentIndex) {
slideTo(index);
}
}, false);
.text{
position: absolute;
/* width: 100px; */
/* height: 50px; */
background-color: red;
top: 52%;
left: 44%;
text-align: center;
transform: translate(0%, 50%);
}
.container {
width: 80%;
margin: 0 auto;
}
.carousel-item > div {
height: 400px;
line-height: 500px;
font-size: 1.5em;
text-align: center;
color: #fff;
}
img {
width: 100%;
height: 100%;
}
/* Carousel */
.acc-carousel {
position: relative;
overflow: hidden;
height: 300px;
width: 100%;
}
.carousel-container {
list-style: none;
overflow: hidden;
padding: 0;
margin: 0;
width: 500%;
transition: transform 0.3s cubic-bezier(.694, .0482, .335, 1);
}
.carousel-item {
position: relative;
float: left;
width: 20%;
}
/* Next / Prev Buttons */
.carousel-prev,
.carousel-next {
position: absolute;
top: 50%;
background-color: #222;
opacity: 0.7;
border-radius: 50%;
color: #fff;
font-size: 1em;
cursor: pointer;
width: 40px;
height: 40px;
line-height: 40px;
-webkit-transform: translate(0, -50%);
transform: translate(0, -50%);
text-align: center;
z-index: 10;
transition: opacity 0.3s ease;
}
.carousel-prev {
left: 2%;
padding-right: 3px;
}
.carousel-prev::before {
content: '\f053';
font-family: "FontAwesome";
}
.carousel-next {
right: 2%;
padding-left: 3px;
}
.carousel-next::before {
content: '\f054';
font-family: "FontAwesome";
}
.carousel-prev:hover,
.carousel-next:hover {
opacity: 1;
}
/* Pagination */
.carousel-pagination {
list-style: none;
position: absolute;
bottom: 3%;
left: 0;
right: 0;
width: 50%;
padding: 0;
margin: 0 auto;
text-align: center;
z-index: 10;
}
.carousel-bullet {
display: inline-block;
width: 12px;
height: 12px;
background-color: #000;
cursor: pointer;
margin: 0 7px;
border-radius: 50%;
opacity: 0.5;
transition-property: transform, opacity, background-color;
transition-duration: 0.3s;
}
.carousel-bullet:hover {
-webkit-transform: scale(1.3);
transform: scale(1.3);
}
.carousel-bullet.active-bullet,
.carousel-bullet.active-bullet:hover {
opacity: 1;
-webkit-transform: scale(1.3);
transform: scale(1.3);
background-color: #fff;
cursor: default;
}
<!--If i link Bootstrap 4 css, pictres will disappear -->
<!-- Bootstrap 4 css :
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.css'>
<div class="container">
<div class="acc-carousel">
<div class="carousel-prev"></div>
<div class="carousel-next"></div>
<ul class="carousel-pagination">
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
</ul>
<ul class="carousel-container">
<li class="carousel-item">
<div class="item-1 img-fluid">
<img src="https://image.shutterstock.com/image-photo/mountains-during-sunset-beautiful-natural-260nw-407021107.jpg" />
</div>
<p class="text">First image</p>
</li>
<li class="carousel-item">
<div class="item-2 img-fluid">
<img src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510__340.jpg" />
</div>
<p class="text">Second image</p>
</li>
<li class="carousel-item">
<div class="item-3"></div>
</li>
<li class="carousel-item">
<div class="item-4"></div>
</li>
<li class="carousel-item">
<div class="item-5"></div>
</li>
</ul>
</div>
</div>

html link buttons centered on page

Currently I am trying to create some links that look like buttons. It's working fairly well, except I want to be able to align them horizontally. This what I have so far:
.border {
display: table;
width: 220px;
height: 120px;
border: 2px solid #1E5034;
transition: all 250ms ease-out;
box-sizing: border-box;
border-spacing: 10px;
float:left;
}
.border:hover {
border-spacing: 2px;
}
a.btn {
display: table-cell;
vertical-align: middle;
text-align: center;
color: #ffffff;
font: 17.5px sans-serif;
text-decoration: none;
background-color: #1E5034;
line-height: 20px;
margin-bottom: 0;
}
a.btn:hover,
a.btn:focus,
a.btn:active,
a.btn:visited,
a.btn:link {
color: #ffffff;
background-color: #1E5034;
text-decoration: none;
cursor: pointer;
}
<div class="btn-grp">
<div class="border">
<a class="btn" href="#">Some really long text link #1</a>
</div>
<div class="border">
<a class="btn" href="#">Some other really long text link #2</a>
</div>
<div class="border">
<a class="btn" href="#">Some more really really long text link #3</a>
</div>
<div class="border">
<a class="btn" href="#">The last really long text link #4</a>
</div>
</div>
Edit:
If it has display:inline-block; it will mess up with formatting with heights and not center the text.
I'm trying to create something as shown here, but then be able to center this on the page as well.
Thanks!
Support in all browsers including IE.
.btn-grp {
position: absolute;
top: 0%;
left: 50%;
transform: translate(-50%, 0%);
width: 80vw;
}
.border {
display: table;
width: 25%;
height: 120px;
border: 2px solid #1E5034;
transition: all 250ms ease-out;
box-sizing: border-box;
border-spacing: 10px;
float: left;
}
.border:hover {
border-spacing: 2px;
}
a.btn {
display: table-cell;
vertical-align: middle;
text-align: center;
color: #ffffff;
font: 17.5px sans-serif;
text-decoration: none;
background-color: #1E5034;
line-height: 20px;
margin-bottom: 0;
}
a.btn:hover,
a.btn:focus,
a.btn:active,
a.btn:visited,
a.btn:link {
color: #ffffff;
background-color: #1E5034;
text-decoration: none;
cursor: pointer;
}
<div class="btn-grp">
<div class="border">
<a class="btn" href="#">Some really long text link #1</a>
</div>
<div class="border">
<a class="btn" href="#">Some other really long text link #2</a>
</div>
<div class="border">
<a class="btn" href="#">Some more really really long text link #3</a>
</div>
<div class="border">
<a class="btn" href="#">The last really long text link #4</a>
</div>
</div>
If you need the 4 div at vertically centered then use:
.btn-grp {
position: absolute;
top: 50%;
left:50%;
transform: translate(-50%, -50%);
}
Because you are using width in px thats why then don't come in a single row...So try to use % width i.e. 25%...
.border {
display: table;
width: 25%;
height: 120px;
border: 2px solid #1E5034;
transition: all 250ms ease-out;
box-sizing: border-box;
border-spacing: 10px;
float: left;
}
.border:hover {
border-spacing: 2px;
}
a.btn {
display: table-cell;
vertical-align: middle;
text-align: center;
color: #ffffff;
font: 17.5px sans-serif;
text-decoration: none;
background-color: #1E5034;
line-height: 20px;
margin-bottom: 0;
}
a.btn:hover,
a.btn:focus,
a.btn:active,
a.btn:visited,
a.btn:link {
color: #ffffff;
background-color: #1E5034;
text-decoration: none;
cursor: pointer;
}
<div class="btn-grp">
<div class="border">
<a class="btn" href="#">Some really long text link #1</a>
</div>
<div class="border">
<a class="btn" href="#">Some other really long text link #2</a>
</div>
<div class="border">
<a class="btn" href="#">Some more really really long text link #3</a>
</div>
<div class="border">
<a class="btn" href="#">The last really long text link #4</a>
</div>
</div>
Well I recommend you to use Flexbox here...It will give you the full control to align the item vertically and horizontally...Also you will need to use :after for the background, as flexbox does not allow border-spacing
.btn-grp {
display: flex;
justify-content: center;
}
.border {
width: 20%;
height: 120px;
border: 2px solid #1E5034;
transition: all 250ms ease-out;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
position: relative;
padding: 10px;
}
a.btn {
text-align: center;
color: #ffffff;
font: 16px sans-serif;
text-decoration: none;
line-height: 20px;
margin-bottom: 0;
flex: 1;
}
a.btn:hover,
a.btn:focus,
a.btn:active,
a.btn:visited {
color: #ffffff;
background-color: #1E5034;
text-decoration: none;
cursor: pointer;
}
.border:before {
content: "";
top: 0;
right: 0;
bottom: 0;
left: 0;
background: #1f5034;
position: absolute;
z-index: -1;
transition: all .3s ease;
transform: scale(0.85);
}
.border:hover:before {
transform: scale(0.95);
}
<div class="btn-grp">
<div class="border">
<a class="btn" href="#">Some really long text link #1</a>
</div>
<div class="border">
<a class="btn" href="#">Some other really long text link #2</a>
</div>
<div class="border">
<a class="btn" href="#">Some more really really long text link #3</a>
</div>
<div class="border">
<a class="btn" href="#">The last really long text link #4</a>
</div>
</div>
Well for IE 8 support use display:inline-block and transform to place the content in center...
.btn-grp {
text-align: center;
font-size: 0;
}
.border {
width: 20%;
height: 120px;
border: 2px solid #1E5034;
transition: all 250ms ease-out;
box-sizing: border-box;
display: inline-block;
vertical-align: top;
position: relative;
padding: 10px;
}
a.btn {
text-align: center;
color: #ffffff;
font: 16px sans-serif;
text-decoration: none;
line-height: 20px;
margin-bottom: 0;
position: relative;
top: 50%;
transform: translateY(-50%);
display: block;
}
.border:before {
content: "";
top: 0;
right: 0;
bottom: 0;
left: 0;
background: #1f5034;
position: absolute;
z-index: -1;
transition: all .3s ease;
transform: scale(0.85);
}
.border:hover:before {
transform: scale(0.95);
}
<div class="btn-grp">
<div class="border">
<a class="btn" href="#">Some really long text link #1</a>
</div>
<div class="border">
<a class="btn" href="#">Some other really long text link #2</a>
</div>
<div class="border">
<a class="btn" href="#">Some more really really long text link #3</a>
</div>
<div class="border">
<a class="btn" href="#">The last really long text link #4</a>
</div>
</div>

How to animate menu slide up using css animations?

I am working on a pure css based menu. I tried to create a slide up animation of the menu but couldn't get it to work. I looked at a lot of solutions online but none of them worked for my case.
Here's the laydown of my case.
The menu has a title and subitems (submenu). This menu will only be one level.
I need the height of the submenu to zap behind the menu title.
Since the number of sub items are dynamic I want to achieve this without using specific height.
transform: translateY seemed like a better option but the menu items are visible above the title.
I do not want the menu items to appear above the menu title and use translate or something similar.
I'm not sure if I'm on the right track or if I'm missing something elementary.
$(function() {
$('.accordion-tabs__header').click(function() {
$('.accordion-tabs__body').toggleClass('collapsed');
$('.accordion-tabs__body').toggleClass('expanded');
});
});
.accordion-tabs {
position: relative;
top: 2rem;
width: 60%;
}
.accordion-tabs__header {
transition-delay: 1s;
display: flex;
align-items: center;
padding: 1rem 0.5rem;
z-index: 10;
position: relative;
background-color: azure;
}
.accordion-tabs__header__title {
margin: 0;
padding: 0;
}
.accordion-tabs__body {
position: absolute;
width: 100%;
transition: 200ms transform ease-in-out;
}
.accordion-tabs__body.expanded {
z-index: 1;
transform: translateY(0%);
}
.accordion-tabs__body.collapsed {
z-index: 1;
transform: translateY(-100%);
}
.accordion-tabs__body .accordion-tabs__body__link {
display: flex;
align-items: center;
padding: 0.875rem;
background-color: antiquewhite;
}
.accordion-tabs__body .accordion-tabs__body__link a{
text-decoration: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='wrapper'>
<div class="accordion-tabs">
<div class="accordion-tabs__header">
<div class="accordion-tabs__header__title">Menu Title Looong</div>
</div>
<div class="accordion-tabs__body collapsed">
<div class="accordion-tabs__body__link"><a class="link" href="#">Item One</a></div>
<div class="accordion-tabs__body__link"><a class="link" href="#">Item One</a></div>
<div class="accordion-tabs__body__link"><a class="link" href="#">Item Three</a></div>
</div>
</div>
</div>
Here's the codepen to my code - https://codepen.io/flexdinesh/pen/VybwwE
I managed to achieve this with max-height.
Slide-up animation was a bit slow to trigger when I used this code in react. However I made it look okay with ease-out transition.
$(function() {
$('.accordion-tabs__header').click(function() {
$('.accordion-tabs__body').toggleClass('collapsed');
$('.accordion-tabs__body').toggleClass('expanded');
});
});
.accordion-tabs {
position: relative;
top: 2rem;
width: 60%;
}
.accordion-tabs__header {
transition-delay: 1s;
display: flex;
align-items: center;
padding: 1rem 0.5rem;
position: relative;
background-color: azure;
}
.accordion-tabs__header__title {
margin: 0;
padding: 0;
}
.accordion-tabs__header.expanded {
border-bottom: none;
}
.accordion-tabs__body {
overflow: hidden;
position: absolute;
width: 100%;
border-bottom-width: 2px;
border-bottom-style: solid;
}
.accordion-tabs__body.expanded {
max-height: 100vh;
transition: max-height 500ms ease-in;
}
.accordion-tabs__body.collapsed {
max-height: 0;
transition: max-height 200ms ease-out;
}
.accordion-tabs__body__link {
display: flex;
align-items: center;
padding: 0.875rem;
border-top-width: 1px;
border-top-style: solid;
background-color: antiquewhite;
}
.accordion-tabs__body__link a {
text-decoration: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='wrapper'>
<div class="accordion-tabs">
<div class="accordion-tabs__header">
<div class="accordion-tabs__header__title">Menu Title Looong</div>
</div>
<div class="accordion-tabs__body collapsed">
<div class="accordion-tabs__body__link"><a class="link" href="#">Item One</a></div>
<div class="accordion-tabs__body__link"><a class="link" href="#">Item One</a></div>
<div class="accordion-tabs__body__link"><a class="link" href="#">Item Three</a></div>
</div>
</div>
</div>
Here's the updated codepen that works -
https://codepen.io/flexdinesh/pen/VyWzKo