I have a cookie consent popup that I added a close X button to it.
I need to align the button in the middle of the popup but the button is off the center.
I know I could set a margin-top to fix the problem but I think that's not the correct way of fixing it.
<div class="alert cookiealert" >
By using our website you agree to our Cookie policy
<div class="acceptcookies">
<div class="x"></div>
</div>
</div>
.cookiealert {
position: fixed;
padding-left: 40px;
font-size: 14px;
bottom: 0;
left: 0;
width: 420px;
margin-bottom: 20px;
margin-left: 20px;
z-index: 900;
opacity: 0;
visibility: hidden;
border-radius: 50px;
transform: translateY(80%);
transition: all 500ms ease-out;
color: #000;
background-color: #ecf0f1;
}
.cookiealert.show {
opacity: 1;
visibility: visible;
transform: translateY(0%);
transition-delay: 1000ms;
}
.cookiealert a {
text-decoration: underline
}
.cookiealert .acceptcookies {
position: absolute;
display: inline-block;
margin-left: 25px;
}
.acceptcookies .x {
display: block;
position: fixed;
width: 12px;
height: 12px;
transition: transform .28s ease-in-out;
border-color: rgb(255, 255, 255);
}
.acceptcookies .x:hover {
transform: rotate(90deg);
}
.acceptcookies .x:before {
content: "";
position: absolute;
display: block;
margin: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 12px;
height: 0;
border-top: 1px solid rgba(0,0,0,0.5);
transform: rotate(45deg);
transform-origin: center;
}
.acceptcookies .x:after {
content: "";
position: absolute;
display: block;
margin: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 12px;
height: 0;
border-top: 1px solid rgba(0,0,0,0.5);
transform: rotate(-45deg);
transform-origin: center;
}
Here's the code: https://codepen.io/m4573r00/pen/RwWEVWp
Write it this way, even if you have multiple lines of text, it's centered.
.cookiealert.show {
opacity: 1;
visibility: visible;
transform: translateY(0%);
transition-delay: 1000ms;
}
.alert{
position: relative;
padding: .75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: .25rem;
}
.cookiealert {
font-size: 14px;
bottom: 0;
left: 0;
width: 420px;
margin-left: 20px;
z-index: 900;
transition: all 500ms ease-out;
color: #000;
background-color: #ecf0f1;
}
.cookiealert.show {
opacity: 1;
visibility: visible;
transform: translateY(0%);
transition-delay: 1000ms;
}
.cookiealert a {
text-decoration: underline
}
.cookiealert .acceptcookies {
position: absolute;
top: 0;
bottom: 0;
height: 12px;
margin-top: auto;
margin-bottom: auto;
right: 10px;
}
.acceptcookies .x {
display: block;
position: relative;
width: 12px;
height: 13px;
transition: transform .28s ease-in-out;
border-color: rgb(255, 255, 255);
}
.acceptcookies .x:hover {
transform: rotate(90deg);
}
.acceptcookies .x:before {
content: "";
position: absolute;
display: block;
left: 0;
right: 0;
top: 6px;
bottom: 0;
width: 12px;
height: 0;
border-top: 1px solid rgba(0,0,0,0.5);
transform: rotate(45deg);
transform-origin: center;
}
.acceptcookies .x:after {
content: "";
position: absolute;
display: block;
left: 0;
right: 0;
top: 6px;
bottom: 0;
width: 12px;
height: 0;
border-top: 1px solid rgba(0,0,0,0.5);
transform: rotate(-45deg);
transform-origin: center;
}
<div class="alert cookiealert show" >
By using our website you agree to our Cookie policy
By using our website you agree to our Cookie policy
By using our website you agree to our Cookie policy
<div class="acceptcookies">
<div class="x"></div>
</div>
</div>