I am trying to create a button with an arrow same as the below image:
But when I do that using the below code it looks like this:
My Code:
.ms-btn,
.ms-btn:hover {
border: 2px solid #3E5B73;
color: #3E5B73;
font-size: 12px;
font-family: 'Ubuntu';
border-radius: 40px;
padding: 16px 28px;
position: relative;
background: transparent;
transition: 0.3s all linear;
}
.ms-btn:before {
content: url(../img/image-left.svg);
position: absolute;
left: -15px;
top: 23%;
/*background: #fff;*/
padding: 5px;
height: 24px;
display: flex;
transform: translateX(0px);
transition: 0.3s all linear;
}
<a class="ms-btn" href="">LEARN MORE</a>
Hope to see any solution for it using css. so button borders can cut or something..
Add to you code the background-color for the 'svg' and adjust the position top. that was it.
div {
padding: 20px;
}
.ms-btn,
.ms-btn:hover {
border: 2px solid #3E5B73;
color: #3E5B73;
font-size: 12px;
font-family: 'Ubuntu';
border-radius: 40px;
padding: 16px 28px;
position: relative;
background: transparent;
transition: 0.3s all linear;
}
.ms-btn:before {
content: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yMS44ODMgMTJsLTcuNTI3IDYuMjM1LjY0NC43NjUgOS03LjUyMS05LTcuNDc5LS42NDUuNzY0IDcuNTI5IDYuMjM2aC0yMS44ODR2MWgyMS44ODN6Ii8+PC9zdmc+');
position: absolute;
left: -15px;
top: 15%;
background: #fff;
padding: 5px;
height: 24px;
display: flex;
transform: translateX(0px);
transition: 0.3s all linear;
}
<div>
<a class="ms-btn" href="">LEARN MORE</a>
</div>
Use clip-path to cut the border. I have added 2 CSS variables to control the cut area:
.ms-btn {
--s: 15px;
--b: 10px;
display: inline-block;
margin: 50px;
color: #3E5B73;
font-size: 12px;
padding: 16px 28px;
position: relative;
transition: 0.3s all linear;
}
/* the border */
.ms-btn:before {
content: "";
position: absolute;
inset: 0;
border: 2px solid #3E5B73;
border-radius: 40px;
clip-path:polygon(0 0,100% 0,100% 100%,0 100%,0 calc(50% + var(--s)),var(--b) calc(50% + var(--s)),var(--b) calc(50% - var(--s)),0 calc(50% - var(--s)));
}
/* the arrow */
.ms-btn:after {
content: "";
position: absolute;
left: -10px;
top: calc(50% - 10px);
background: red;
height: 20px;
width: 20px;
}
<a class="ms-btn" href="">LEARN MORE</a>
The closest style to what you want is that I noted below. I remove left border and reduce top and bottom left border radius. You can increase or decrease them as you want. This arrow doesn't have and doesn't need background color and I think it will solve you problem and meet your need.
div {
padding: 20px;
}
.ms-btn,
.ms-btn:hover {
border-width: 2px 2px 2px 0px;
border-color: #3E5B73;
border-style: solid;
color: #3E5B73;
font-size: 12px;
font-family: 'Ubuntu';
border-radius: 20px 40px 40px 20px;
padding: 16px 28px;
position: relative;
background: transparent;
transition: 0.3s all linear;
}
.ms-btn:before {
content: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yMS44ODMgMTJsLTcuNTI3IDYuMjM1LjY0NC43NjUgOS03LjUyMS05LTcuNDc5LS42NDUuNzY0IDcuNTI5IDYuMjM2aC0yMS44ODR2MWgyMS44ODN6Ii8+PC9zdmc+');
position: absolute;
left: -25px;
top: 15%;
padding: 5px;
height: 24px;
display: flex;
transform: translateX(0px);
transition: 0.3s all linear;
}
<div>
<a class="ms-btn" href="">LEARN MORE</a>
</div>
Related
I have implemented a :hover animation for a link that takes you to another part of the website. When hovered in Firefox or Google Chrome, the width of the border of the :before and :after pseudo-elements are 2px like specified but when checking Safari, I found the width to be thicker than what is expected.
The HTML, CSS and screenshots of the occurrence are below.
Firefox and Chrome:
Safari:
Code:
a {
text-decoration: none;
color: inherit;
}
#title {
color: black;
margin: 0 auto;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#gallery-link {
padding: 15px 0;
text-align: center;
}
#gallery-link-padding {
padding: 15px 60px;
}
.frame-effect-click {
position: relative;
font-weight: 500;
font-size: 16px;
cursor: pointer;
border-radius: 10px;
transition: 0.4s;
}
.frame-effect-click:after, .frame-effect-click:before {
content: '';
position: absolute;
width: 0;
height: 0;
transition: all 0.4s linear, opacity 0.1s 0.4s;
opacity: 0;
}
.frame-effect-click:after {
bottom: 0;
right: 0;
border-bottom: 2px solid black;
border-right: 2px solid black;
}
.frame-effect-click:before {
top: 0;
left: 0;
border-top: 2px solid black;
border-left: 2px solid black;
}
.frame-effect-click:hover:after, .frame-effect-click:hover:before {
width: calc(100% + 10px);
height: calc(100% + 10px);
transition: 0.4s, opacity 0.1s;
opacity: 1;
}
<div id="title">
<div id="gallery-link">
<a id="gallery-link-padding" class="frame-effect-click" href="#">View gallery</a>
</div>
</div>
Does anyone know why that is and how to fix this issue?
I have made a button which has a small tab that upon hovering over it expands to the side. It is there because I want the button to be draggable. So once the tab expands, you can grab it and drag the button around. Don't mind the broken icons, they are supposed to be there from font awesome pack.
However I wanted to inform user, that the small tab can be grabbed, so I made a little jiggle effect on idle that plays two times indicating, that the tab can expand. And once user hovers over it, it fully expands. However when user unhovers the tab, the animation starts again. I need the animation to start only when the page loads and occur exactly 2 times and never again. Why does the aniamtion start after the transition that is there on hover and what can I do to disallow it animating again? Is it possible without JS?
Here is my code
.insite-draggable {
z-index: 10;
position: fixed;
left: 45px;
bottom: 12px;
}
.insite-handle {
position: absolute;
left: -14px;
bottom: 13px;
transition: left 0.3s cubic-bezier(0.32, 1.85, 0.43, 0.43);
animation: bounce 2s;
animation-iteration-count: 2;
animation-delay: 2s;
}
.insite-handle:before {
content: "\f100";
font-family: "Font Awesome 5 Free";
font-style: normal;
font-size: 16px;
line-height: 16px;
display: inline-block;
background-color: #1ea2b1;
cursor: move;
color: #ffffff;
height: 16px;
width: 26px;
padding: 3px 3px 3px 4px;
border-radius: 7px 0px 0px 7px;
border: 1px solid #1a8e9b;
transition: padding-left 0.3s cubic-bezier(0.32, 1.85, 0.43, 0.43);
}
.insite-handle:hover {
left: -27px;
animation: step-end;
&:before {
content: "\f0b2";
padding-left: 5px;
}
}
#keyframes bounce {
0% { left: -14px; }
10% { left: -20px; }
20% { left: -14px; }
30% { left: -20px; }
40% { left: -14px; }
100% {left: -14px; }
}
.insite-btn {
display: block;
position: relative;
top: auto;
left: auto;
bottom: auto;
right: auto;
font-family: 'BrixSansBold';
font-style: italic;
font-size: 0.875rem;
line-height: 1rem;
-ms-border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
color: #b00402;
border: none;
margin: 10px 10px 10px auto;
padding: 7px 10px 7px 34px;
text-decoration: none;
text-transform: none;
box-shadow: #333333 1px 1px 10px;
background-color: #e3e000;
}
<span class="insite-draggable">
<i class="insite-handle"></i>
<a class="insite-btn" href="#">Turn on</a>
</span>
I used CSS Variables with fallback.
var(--use-this-variable-if-exist, use this fallback if no variable);
Initially there is no --left value, so it uses fallbacks. When hover, set --left value as -27px. Thus, the keyframes are also updated.
.insite-draggable {
z-index: 10;
position: fixed;
left: 45px;
bottom: 12px;
}
.insite-handle {
position: absolute;
left: -14px;
bottom: 13px;
transition: left 0.3s cubic-bezier(0.32, 1.85, 0.43, 0.43);
animation: bounce 2s;
animation-iteration-count: 2;
animation-delay: 2s;
}
.insite-handle:before {
content: "\f100";
font-family: "Font Awesome 5 Free";
font-style: normal;
font-size: 16px;
line-height: 16px;
display: inline-block;
background-color: #1ea2b1;
cursor: move;
color: #ffffff;
height: 16px;
width: 26px;
padding: 3px 3px 3px 4px;
border-radius: 7px 0px 0px 7px;
border: 1px solid #1a8e9b;
transition: padding-left 0.3s cubic-bezier(0.32, 1.85, 0.43, 0.43);
}
.insite-handle:hover {
left: -27px;
--left: -27px;
&:before {
content: "\f0b2";
padding-left: 5px;
}
}
#keyframes bounce {
0% {
left: var(--left, -14px);
}
10% {
left: var(--left, -20px);
}
20% {
left: var(--left, -14px);
}
30% {
left: var(--left, -20px);
}
40% {
left: var(--left, -14px);
}
100% {
left: var(--left, -14px);
}
}
.insite-btn {
display: block;
position: relative;
top: auto;
left: auto;
bottom: auto;
right: auto;
font-family: 'BrixSansBold';
font-style: italic;
font-size: 0.875rem;
line-height: 1rem;
-ms-border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
color: #b00402;
border: none;
margin: 10px 10px 10px auto;
padding: 7px 10px 7px 34px;
text-decoration: none;
text-transform: none;
box-shadow: #333333 1px 1px 10px;
background-color: #e3e000;
}
<span class="insite-draggable">
<i class="insite-handle"></i>
<a class="insite-btn" href="#">Turn on</a>
</span>
I got this problem with safari browser when I used to transform with perspective to parent "parent". these blocks work well with chrome and Mozilla!
any help?
my code and a screenshot from safari below
enter image description here
.service-element {
text-align: center;
padding: 28px;
perspective: 298px;
position: absolute;
padding-left: 56px;
transition: all .5s ease-in-out;
padding-bottom: 60px;
padding-top: 60px;
}
.service-element:before {
content: '';
position: absolute;
right: 0;
bottom: 0;
left: 0;
top: 0;
z-index: -1;
background-color: #ffffff;
border: solid 0.5px #e3e0e0;
border-radius: 24px;
transition: all .5s ease-in-out;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.225);
-webkit-transform: rotateY(-10deg);
transform: rotateY(-10deg);
}
.service-element img {
height: 89px;
margin-bottom: 31px;
}
.service-element h2 {
font-size: 22px;
font-family: "indielabs-Frutiger-bold";
color: #4c4c4c;
}
.service-element .paragraph {
font-size: 14px;
color: #959595;
font-family: "indielabs-Frutiger-light";
}
<div class="service-element tr">
<img src="http://yehia.alyomhost.net/alyom-new/images/apps-icon#3x.jpg" class="img-fluid">
<h2>تصميم تطبيقات الجوال</h2>
<div class="paragraph">
لوريم ابيسوم نص عشواىي هنا يوضح الشكل وليس الهدف منه المحتوي
</div>
How do I achieve this kind of checkbox (Image Shown Below) ? I tried some code, but it won't work as I expected. I am not familiar with css before, after pseudo elements.
JSFiddle
.chkbox {
height: 15px;
width: 15px;
background-color: #fff;
border: 1px solid #ddd;
position: relative;
transition: border-color ease 0.125s;
-ms-transition: border-color ease 0.125s;
-moz-transition: border-color ease 0.125s;
-webkit-transition: border-color ease 0.125s;
cursor: pointer;
border-radius: 2px;
}
.chkbox:before {
right: -1px;
width: 1px;
top: -1px;
height: 8px
}
.chkbox:after {
top: -1px;
right: 0;
width: 2px;
height: 2px
}
Why not use clip-path? Remove pseudo-elements and just add something like clip-path: polygon(0 0, 65% 0%, 65% 25%, 100% 25%, 100% 100%, 0 100%);
.chkbox {
height: 15px;
width: 15px;
background-color: #fff;
border: 1px solid #ddd;
position: relative;
transition: border-color ease 0.125s;
-ms-transition: border-color ease 0.125s;
-moz-transition: border-color ease 0.125s;
-webkit-transition: border-color ease 0.125s;
cursor: pointer;
border-radius: 2px;
clip-path: polygon(0 0, 65% 0%, 65% 25%, 100% 25%, 100% 100%, 0 100%);
}
<div class="chkbox"></div>
That's very handy, by the way http://bennettfeely.com/clippy/
Here is an example.
.chkbox {
display: none;
}
.chkbox+label {
display: inline-block;
color: #666666;
position: relative;
padding-left: 30px;
margin: 7px 10px;
font-size: 16px;
line-height: 20px;
}
.chkbox+label:before {
content: "";
line-height: 20px;
display: inline-block;
width: 18px;
height: 18px;
margin-right: 10px;
position: absolute;
left: 0;
top: -1px;
border-radius: 3px;
border: 1px solid #aaaaaa;
}
.chkbox+label:after {
height: 7px;
width: 7px;
content: "";
background-color: #ffffff;
position: absolute;
left: 13px;
top: -1px;
}
<input type="checkbox" class="chkbox">
<label for="check1">Morning</label>
Try to override borders like this
.chkbox:before {
content: "";
width: 7px;
height: 7px;
background:white;
position:absolute;
right:-1px;
top:-1px;
}
here is fiddle example for you
https://jsfiddle.net/th9qpdvh/2/
You can also use image for this purpose
Try this
.chkbox {
height: 15px;
width: 15px;
background-color: #fff;
border: 1px solid #ddd;
position: relative;
transition: border-color ease 0.125s;
-ms-transition: border-color ease 0.125s;
-moz-transition: border-color ease 0.125s;
-webkit-transition: border-color ease 0.125s;
cursor: pointer;
border-radius: 2px;
box-shadow: 1px -1px 2px #ccc;
}
.chkbox:after {
content: '';
display: block;
right: -3px;
width: 9px;
top: -3px;
height: 9px;
background: #fff;
position: absolute;
}
<div class="chkbox"></div>
You cannot modify the input type="checkbox" element into the desired shape directly, because:
Input elements don't have pseudo elements.
You cannot use clip-path as mentioned in one of the answers because of very low browser support (if that is a concern for you.) CanIUse Reference
So I would suggest you to go with #Pugazh's answer
input[type="checkbox"] {
display: none;
}
input[type="checkbox"] + label {
display: inline-block;
position: relative;
color: #404040;
padding-left: 30px;
margin: 7px 10px;
font-size: 16px;
line-height: 20px;
}
input[type="checkbox"] + label:before, input[type="checkbox"] + label:after {
content: "";
position: absolute;
display: block;
}
input[type="checkbox"] + label:before {
width: 18px;
height: 18px;
left: 0;
top: -1px;
border-radius: 3px;
border: 1px solid #aaaaaa;
}
input[type="checkbox"] + label:after {
height: 7px;
width: 7px;
background-color: #ffffff;
left: 13px;
top: -1px;
}
Hidden those corner borders using this below class.
Few other answers are good. But, it doesn't work on some browsers. Another answer affect my TICK css class. Finally I found this below solution to solve this issue without compatibility problems.
JsFiddle
.hideWhite{
width:10px;
height:10px;
background:#fff;
border-radius:50%;
position:absolute;
top:-2px;
right:-4px;
display:inline-block
}
http://jsfiddle.net/93bphr4f/
html:
<button type="button" onClick="location.href='#'" class="buttonpink2">Claim 10 Free Student Accounts for Your School</button>
css:
/* PINK BUTTON 2 */
.buttonpink2 {
font-weight: bold;
font-size: 30px;
color: white;
cursor: pointer;
cursor: hand;
border-radius: 5px !important;
box-shadow: 4px 4px 4px #b5bcc2;
border: 0;
background-repeat: no-repeat;
background: #e57780;
height: 75px;
width: 100%;
position: relative;
}
.buttonpink2:after {
border-radius: 5px !important;
content: "Claim 10 Free Student Accounts for Your School";
display: block;
height: 100%;
width: 100%;
opacity: 0;
background: #c24e57;
-moz-transition: all 1s;
-webkit-transition: all 1s;
transition: all 1s;
top: 0;
left: 0;
position: absolute;
}
.buttonpink2:hover:after {
opacity: 1;
}
.buttonpink2 p {
color: #fff;
z-index: 1;
position: relative;
}
look at it,
I dont know why when I hover mouse on button, text move to top..
I want to text be still on center of button.
What i doing wrong?
Anyone can help?
Don't know why you complicated it too much but you simple use line-height equal of element height:
/* PINK BUTTON 2 */
.buttonpink2 {
font-weight: bold;
font-size: 30px;
color: white;
cursor: pointer;
cursor: hand;
border-radius: 5px !important;
box-shadow: 4px 4px 4px #b5bcc2;
border: 0;
background-repeat: no-repeat;
background: #e57780;
height: 75px;
width: 100%;
position: relative;
}
.buttonpink2:after {
border-radius: 5px !important;
content: "Claim 10 Free Student Accounts for Your School";
display: block;
height: 100%;
width: 100%;
opacity: 0;
background: #c24e57;
-moz-transition: all 1s;
-webkit-transition: all 1s;
transition: all 1s;
top: 0;
left: 0;
position: absolute;
line-height: 75px;/*add line height equal of element height*/
}
.buttonpink2:hover:after {
opacity: 1;
}
.buttonpink2 p {
color: #fff;
z-index: 1;
position: relative;
}
<button type="button" onClick="location.href='./freeaccess'" class="buttonpink2">Claim 10 Free Student Accounts for Your School</button>
You shouldn't use the :after tag at all in this situation.
// All the positioning made the button go crazy.
You should do it this way:
Use .buttonClass { } to set the basic button styling, and use .buttonClass:hover { } to only change the background of the button. You don't have to duplicate every item in the :hover part.
/* PINK BUTTON 2 */
.buttonpink2 {
font-weight: bold;
font-size: 30px;
color: white;
cursor: pointer;
border-radius: 5px;
box-shadow: 4px 4px 4px #b5bcc2;
border: 0;
height: 75px;
width: 100%;
background: #e57780;
-moz-transition: all 1s;
-webkit-transition: all 1s;
transition: all 1s;
}
.buttonpink2:hover {
background: #c24e57;
}
.buttonpink2 p {
color: #fff;
z-index: 1;
}
Strange way to do, why are you using pseudo-elements just in order to change background-color ?
.buttonpink2:after {
height: 75px;
line-height:75px;
...
}
will solve your problem, but I suggest you to remove the .buttonpink2:after element and just change the background-color of the button
If you would rather using padding instead of line-height, you can do this:
.buttonpink2:after {
height: 50%;
padding: 20px 0;
}
You can add some letter-spacing on :after to solve it, I just added 0.3px, you can try other values to make it better.
/* PINK BUTTON 2 */
.buttonpink2 {
font-weight: bold;
font-size: 30px;
color: white;
cursor: pointer;
cursor: hand;
border-radius: 5px !important;
box-shadow: 4px 4px 4px #b5bcc2;
border: 0;
background-repeat: no-repeat;
background: #e57780;
height: 75px;
width: 100%;
position: relative;
}
.buttonpink2:after {
border-radius: 5px !important;
content: "Claim 10 Free Student Accounts for Your School";
display: block;
height: 100%;
width: 100%;
opacity: 0;
background: #c24e57;
-moz-transition: all 1s;
-webkit-transition: all 1s;
transition: all 1s;
top: 0;
left: 0;
position: absolute;
letter-spacing: 0.3px
}
.buttonpink2:hover:after {
opacity: 1;
}
.buttonpink2 p {
color: #fff;
z-index: 1;
position: relative;
}
<button type="button" onClick="location.href='#'" class="buttonpink2">Claim 10 Free Student Accounts for Your School</button>