How to put link in css? - css

<style>
.button {
position: relative;
background-color: #41A0BF;
border: none;
font-size: 20px;
color: #FFFFFF;
padding: 15px;
width: 120px;
text-align: center;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
text-decoration: none;
overflow: hidden;
cursor: pointer;
}
.button:after {
content: "";
background: #69D2F5;
display: block;
position: absolute;
padding-top: 300%;
padding-left: 350%;
margin-left: -20px!important;
margin-top: -120%;
opacity: 0;
transition: all 0.8s
}
.button:active:after {
padding: 0;
margin: 0;
opacity: 1;
transition: 0s
}
</style>
<button class="button">Home</button>
How to put link in button?
i tried everything codes available in google but still error in my website
i dont know whats the best code for this
thanks for someone who wants to teach me.

No. Its not possible to add link through css. But you can use jquery
$('.case').each(function() {
var link = $(this).html();
$(this).contents().wrap('');
});

I'll suggest to add anchor tag if you want to add link.
Home
Add link in "#". It'll work.

Four different possibilities to a button become a link (CSS isn't an option):
.button {
position: relative;
background-color: #41A0BF;
border: none;
font-size: 20px;
color: #FFFFFF;
padding-top: 15px;
padding-bottom: 15px;
width: 120px;
text-align: center;
overflow: hidden;
cursor: pointer;
display: inline-block;
text-decoration: none;
}
a, a:active, a:visited, a:focus {
text-decoration: none;
color: white;
font-family: arial, sans-serif;
}
Javascript:<br>
<button class="button" onClick="window.location.href = 'http://example.com'">click</button><br><br>
Inner link:<br>
<button class="button">click</button><br><br>
Wrapper link:<br>
<button class="button">click</button><br><br>
Fake button:<br>
<a href="http://example.com" class=button>click</a>

Please try this:
<button class="button">Home</button>

I think its the easy way to do it.
.button {
position: relative;
background-color: #41A0BF;
border: none;
font-size: 20px;
color: #FFFFFF;
padding: 15px;
width: 120px;
text-align: center;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
text-decoration: none;
overflow: hidden;
cursor: pointer;
}
.button:after {
content: "";
background: #69D2F5;
display: block;
position: absolute;
padding-top: 300%;
padding-left: 350%;
margin-left: -20px!important;
margin-top: -120%;
opacity: 0;
transition: all 0.8s
}
.button:active:after {
padding: 0;
margin: 0;
opacity: 1;
transition: 0s
}
a{
text-decoration:none;
}
<button class="button">Home</button>

You can have the link as a button this way
home
Or if you using a css library like bootstrap
home

Related

CSS code for underline style for menu items

I would like to know the CSS code used to make the underline effect for the menu items of this website : https://www.kevin-missud-charpente.fr/
Thanks in advance.
this is better
body,html {
margin: 0;
font: bold 14px/1.4 'Open Sans', arial, sans-serif;
background: #fff;
}
ul {
margin: 150px auto 0;
padding: 0;
list-style: none;
display: table;
width: 600px;
text-align: center;
}
li {
display: table-cell;
position: relative;
padding: 15px 0;
}
a {
color: #000;
text-transform: uppercase;
text-decoration: none;
letter-spacing: 0.15em;
display: inline-block;
padding: 15px 20px;
position: relative;
}
a:after {
background: none repeat scroll 0 0 transparent;
bottom: 0;
content: "";
display: block;
height: 2px;
left: 50%;
position: absolute;
background: #000;
transition: width 0.3s ease 0s, left 0.3s ease 0s;
width: 0;
}
a:hover:after {
width: 100%;
left: 0;
}
#media screen and (max-height: 300px) {
ul {
margin-top: 40px;
}
}
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li>Support</li>
</ul>
this is on hover underline effect
Here a link to codepen with the same underline animation.
https://codepen.io/Nerd/details/zBmAWV
HTML
<nav>
Hover me!
</nav>
CSS
nav {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
a {
position: relative;
color: #000;
text-decoration: none;
font-size: 42px;
font-family: sans-serif;
&:hover {
color: #000;
&:before {
visibility: visible;
transform: scaleX(1);
}
}
&:before {
content: "";
position: absolute;
width: 100%;
height: 3px;
bottom: 0;
left: 0;
background-color: #000;
visibility: hidden;
transform: scaleX(0);
transition: all 0.3s ease-in-out 0s;
}
}

CSS transition a single character

I'm looking for help on how to transition a single character on a button when the button itself is hovered over as seen below:
All my attempts so far have just resulted in the whole button shifting to the right rather than the single chevron.
Thanks
Well, it's easy, You have to use pseudo-element for it eg:
Note: Don't decrease width or instead of button will move instead of the animated thing
.button {
border-radius: 4px;
background-color: red;
border: none;
text-align: center;
font-size: 28px;
padding: 20px;
width: 200px;
transition: all 0.5s;
cursor: pointer;
margin: 5px;
}
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.button:hover span {
padding-right: 25px;
}
.button:hover span:after {
opacity: 1;
right: 0;
<button class="button"><span>Hover </span></button>

CSS Content property does not work on safari

I have and element and on hover it has an arrow appearing.
The problem is that it works on chrome and firefox but does not work on safari 12. It works on safari 10 though.
So far I found out that the problem is content:url('../path/to/arrow.png')
If I replace path to the arrow with content: '1234' then it works for some reason.
here is a full code
<style>
.textwidget a {
border-radius: 0;
background-color: none;
color: #fff;
text-align: center;
font-size: 10px;
text-transform: uppercase;
width: 200px;
transition: all 0.5s;
cursor: pointer;
margin-top: 101px;
margin-bottom: 94px;
margin-left: -10px;
}
.textwidget a {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.textwidget a:after {
font-family: "Font Awesome 5 Free" !important;
content: url(../public/assets/images/icons/arrow-right-small-white.png) !important;
font-weight: 600 !important;
position: absolute;
opacity: 0;
top: 3px;
right: 23px;
transition: 0.5s;
}
.textwidget a:hover{
padding-right: 24px;
padding-left:3px;
}
.textwidget a:hover:after {
opacity: 1;
right: 10px;
}
</style>
<div class="textwidget">
<p>
Link
</p>
</div>
So my desired output is that content: url(../public/assets/images/icons/arrow-right-small-white.png)
works also on safari 12
Try mount the arrow on span element instead and do it like in docs, so without content property

display text on toggle button

I have a simple checkbox toggle that change the background color when clicked or checked, that indicates active or not. My problem is I don't know how to put label on that button.
something like this.
I'm not sure if that possible.
I hope you understand me.
Thanks
CODEPEN
body{
background-color: #ddd;
}
.toggle {
-webkit-appearance: none;
appearance: none;
width: 65.57px;
padding: 10px;
height: 26.32px;
display: inline-block;
position: relative;
border-radius: 13px;
overflow: hidden;
line-height: 16px;
text-align: center;
font-size: 12px;
outline: none;
border: none;
cursor: pointer;
background: #E1F6FF;
transition: background-color ease 0.3s;
}
.toggle:before {
content: "text text";
display: block;
position: absolute;
z-index: 2;
width: 24px;
height: 24px;
background: #fff;
left: 0;
top: 0;
border-radius: 50%;
padding-top: 5px;
text-indent: -30px;
word-spacing: 37px;
color: #4D5585;
text-shadow: -1px -1px rgba(0,0,0,0.15);
white-space: nowrap;
box-shadow: 0 1px 2px rgba(0,0,0,0.2);
transition: all cubic-bezier(0.3, 1.5, 0.7, 1) 0.3s;
}
.toggle:checked {
background: #dadce8;
}
.toggle:checked:before {
left: 40px;
}
.center{
text-align: center;
}
<div class="center">
<input class="toggle" type="checkbox" />
</center>
To achive desire result after edit, we are going to build something new.
HTML
<div class="switch">
<input type="checkbox" name="switch" class="switch-checkbox" id="myswitch" checked>
<label class="switch-labels" for="myswitch">
<span class="switch-text"></span>
<span class="switch-dot"></span>
</label>
</div>
We will use a main div with class switch to build our switch. This will hold 2 things
The input so we can target it state and use both for styles and what i suppose future js styles
A label that will hold 2 things
2.1 The on and off text as before and after of a span
2.2 The white dot that slides on each state
CSS is commented on the snippet
Hope this is what you were looking for. Happy to explain or help in a better solution if needed.
body {
background-color: #ddd;
}
/*Style main div and remove default checkbox*/
.switch {
position: relative;
width: 75px;
margin: 0 auto;
}
.switch-checkbox {
display: none;
}
/*Style words and oval switch */
.switch-labels {
display: block;
overflow: hidden;
cursor: pointer;
border-radius: 20px;
}
.switch-text {
display: block;
width: 200%;
margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.switch-text:before,
.switch-text:after {
float: left;
width: 50%;
line-height: 30px;
color: white;
box-sizing: border-box;
}
.switch-text:before {
content: "ON";
padding-left: 10px;
background-color: #E1F6FF;
color: #000000;
}
.switch-text:after {
content: "OFF";
padding-right: 10px;
background-color: #4D5585;
color: #FFFFFF;
text-align: right;
}
/*Style center dot*/
.switch-dot {
width: 30px;
height: 30px;
background: #FFFFFF;
position: absolute;
top: 0;
bottom: 0;
right: 41px;
margin-right: 5px;
border-radius: 20px;
transition: all 0.3s ease-in 0s;
}
.switch-dot:after{
content: "";
position: absolute;
width: 20px;
height: 20px;
background-size: cover;
background-image: url('http://www.free-icons-download.net/images/multiply-icon-27981.png');
margin: 5px 0 0 5px;
}
/*State changer*/
.switch-checkbox:checked+.switch-labels .switch-text {
margin-left: 0;
}
.switch-checkbox:checked+.switch-labels .switch-dot {
right: 0px;
margin-right: 0px;
}
<div class="switch">
<input type="checkbox" name="switch" class="switch-checkbox" id="myswitch" checked>
<label class="switch-labels" for="myswitch">
<span class="switch-text"></span>
<span class="switch-dot"></span>
</label>
</div>
Change the text in content for toggle.before to
content: "hide show";
Well, just want to add labels?
use below inside .toggle:before
content: "Hide Show";
instead
content: "text text";
Thanks. Ask for more queries.
If you want to put the text on the white circle means , you can add this one in css
.toggle:before{
text-overflow: ellipsis;
overflow: hidden;
}
I am not sure if I understand your question right way. Do you mean add a lebal to toggle this checkbox?
body{
background-color: #ddd;
}
.toggle {
-webkit-appearance: none;
appearance: none;
width: 65.57px;
padding: 10px;
height: 26.32px;
display: inline-block;
position: relative;
border-radius: 13px;
overflow: hidden;
line-height: 16px;
text-align: center;
font-size: 12px;
outline: none;
border: none;
cursor: pointer;
background: #E1F6FF;
transition: background-color ease 0.3s;
}
.toggle:before {
content: "text text";
display: block;
position: absolute;
z-index: 2;
width: 24px;
height: 24px;
background: #fff;
left: 0;
top: 0;
border-radius: 50%;
padding-top: 5px;
text-indent: -30px;
word-spacing: 37px;
color: #4D5585;
text-shadow: -1px -1px rgba(0,0,0,0.15);
white-space: nowrap;
box-shadow: 0 1px 2px rgba(0,0,0,0.2);
transition: all cubic-bezier(0.3, 1.5, 0.7, 1) 0.3s;
}
.toggle:checked {
background: #dadce8;
}
.toggle:checked:before {
left: 40px;
}
.center{
text-align: center;
}
<div class="center">
<input id="sample" class="toggle" type="checkbox" />
<label for="sample">This is a sample</label>
</center>

How to create a drop-down menu in div?

How to show the scrollable menu when passing the pointer over the div of the text 1x the scrollable menu is displayed.
What I want to do is something similar to the following image:
My code structure:
.spdText {
width: 3em;
height: 1.8em;
line-height: 1.8em;
position: relative;
font-size: 1em;
font-weight: 900;
text-shadow: none;
border-radius: 10%;
color: #29303b;
background-color: hsla(0,0%,100%,.9);
}
.speed {
display: none;
position: absolute;
max-height: 0;
transition: max-height 1s;
}
.speed:hover,
.btnSpd:hover .speed {
display: inline-table;
list-style: none;
max-height: 300px;
transition: max-height 1s;
top: -170px;
}
<div class="spdText">1x
<ul class="speed">
<li>x3</li>
<li>x1</li>
</ul>
</div>
Something like this?
Edit:
First you leave a space above 'spdText'. You position 'speed' over 'spdText' giving it a negative top value.
.spdText {
width: 3em;
height: 1.8em;
line-height: 1.8em;
position: relative;
font-size: 1em;
font-weight: 900;
text-shadow: none;
border-radius: 10%;
color: #29303b;
background-color: hsla(0,0%,100%,.9);
margin-top:5rem; /* You leave a space above */
}
.speed {
display: none;
position: absolute;
max-height: 0;
transition: max-height 1s;
}
.spdText:hover .speed {
display: block;
list-style: none;
max-height: 300px;
transition: max-height 1s;
left:-25px;
background-color: black;
opacity: 0.5;
color: white;
top: -4.4rem;
}
<div class="spdText">1x
<ul class="speed">
<li>x3</li>
<li>x1</li>
</ul>
</div>

Resources