how to achieve hover effect on phone react - css

I have a code that changes another div's backgroundImage when it it is hovered over. To do this, I use onMouseOver={() => setCurrentIndex(i)} and it does the job fine for laptops. However, onMouseOver does not seem to be working on phones until I have already clicked on the image/link, making it redundant.
<Link key={post.node.title} href={`/posts/${post.node.slug}`}>
<a
onMouseOver={() => setCurrentIndex(i)}
className={`p-2 border-r-2 h-full md:p-6 lg:p-8 ${currentIndex !== i ? 'opacity-70' : 'opacity-100'}`}
>
<div className="flex flex-col items-start h-full justify-end hover:-translate-y-4 ease-in-out duration-100 ">
{post.node.categories.map((category) => (
<Link passHref key={category.name} href={`/categories/${category.name}`}>
<span className="hidden md:inline-block bg-gray-200 hover:bg-blue-100 ease-in duration-150 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2">
#{category.name}
</span>
</Link>
))}
<h1 className="text-xs text-gray-200 font-bold md:text-3xl">{post.node.title}</h1>
</div>
</a>
</Link>

You can't use hover effects on mobile since there's no cursor.
If you want visual feedback for pressing a button do a click event with a ripple effect.
Something like this Pure css ripple with minimal effort
/* Ripple effect */
.ripple {
background-position: center;
transition: background 0.8s;
}
.ripple:hover {
background: #47a7f5 radial-gradient(circle, transparent 1%, #47a7f5 1%) center/15000%;
}
.ripple:active {
background-color: #6eb9f7;
background-size: 100%;
transition: background 0s;
}
/* Button style */
button {
border: none;
border-radius: 2px;
padding: 12px 18px;
font-size: 16px;
text-transform: uppercase;
cursor: pointer;
color: white;
background-color: #2196f3;
box-shadow: 0 0 4px #999;
outline: none;
}

Related

How to rewrite CSS rules on tailwind?

I have the following styles in figma:
display: flex;
flex-direction: row;
align-items: center;
padding: 10px 16px;
position: absolute;
width: 227px;
height: 40px;
/* Button/Red */
background: #E30513;
/* RedBtn */
box-shadow: 0px 4px 12px rgba(157, 84, 81, 0.44);
border-radius: 10px;
I tried to rewrite these styles on tailwind for the buttion:
<button type="submit" class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-xl shadow-sm text-white bg-red-600 hover:bg-red-600 focus:outline-none focus:ring-2 focus:ring-offset-2">Make request</button>
But I have faced with problems:
There is no tailwind border-radius: 10px only rounded-lg or rounded-xl.
There is no padding: 10px 16px; only this
No the same shadow
No color #E30513
Could you explain me, how to use tailwind in my case?
Here is how you can do it directly from tailwind classes using Arbitrary values
<script src="https://cdn.tailwindcss.com"></script>
<button
type="submit"
class="flex flex-row items-center py-[10px] px-[16px]
absolute w-[227px] h-[40px] bg-[#E30513]
shadow-[0px_4px_12px_rgba(157,84,81,0.44)]
rounded-[10px]
">
Make request
</button>
There are basically two ways to solve this problem.
Tailwind CSS v3 actually supports setting arbitrary values.
border-radius: 10px can be represented as rounded-[10px]
padding: 10px 16px can be represented as py-[10px] px-[16px]
box-shadow: 0px 4px 12px rgba(157, 84, 81, 0.44) can be represented as shadow-[0px_4px_12px_rgba(157,84,81,0.44)]
background: #E30513 can be represented as bg-[#E30513]
Here's an example of your button: https://play.tailwindcss.com/9K23furBKo
Alternatively, if you plan to use these values more than once, you could also easily extend your Tailwind CSS configuration.
Here are the links to the relevant documentation pages:
https://tailwindcss.com/docs/border-radius#using-custom-values
https://tailwindcss.com/docs/padding#using-custom-values
https://tailwindcss.com/docs/box-shadow#using-custom-values
https://tailwindcss.com/docs/background-color#using-custom-values

How do i fix this floating label in plain css?

project is here -> https://play.tailwindcss.com/udQSLuVwHa
When i click inside the InputField (do not click directly on the Username label), the Label correctly shrinks.
And if i click out of the inputField (make it lose focus), the Label gets big again.
Now, if i type some text into the InputField, and the make it lose focus, the Username label should not shrink, but stay on top.
I have commented out the CSS that should work. Its something wrong with my CSS right? and not tailwinds?
Try to select label when it's sibling input is not showing placeholder by input:not(:placeholder-shown) + label, here is your styles with new selector:
.outline:focus-within label,
input:not(:placeholder-shown) + label {
background-color: white;
transform: scale(0.75) translateY(-1rem);
z-index: 0;
margin-left: 0.75rem;
padding-left: 0.25rem;
padding-right: 0.25rem;
padding-top: 0px;
padding-bottom: 0px;
}
Saeed's answer is a great CSS solution.
If you want to solve this in JavaScript you could do the following:
(note styling will look different when you run code snippet as tailwind isn't present)
inputUsername = document.getElementById('inputUsername');
labelUsername = document.getElementById('labelUsername');
inputUsername.onfocus = () => {
labelUsername.classList.add('outline');
}
inputUsername.onblur = () => {
if (inputUsername.value.length == 0){
labelUsername.classList.remove('outline');
}
}
.outline {
background-color: white;
transform: scale(0.75) translateY(-1rem);
z-index: 0;
margin-left: 0.75rem;
padding-left: 0.25rem;
padding-right: 0.25rem;
padding-top: 0px;
padding-bottom: 0px;
}
<div class="outline relative border-2 focus-within:border-blue-500">
<input id="inputUsername" class="bg-red-700 block p-4 w-full text-lg appearance-none bg-transparent" placeholder=" " type="text" />
<label id="labelUsername" for="username" class="absolute top-0 text-lg bg-white p-4 -z-1 duration-300 origin-0">Username</label>
</div>

Transitioning element in Vue

I'm somewhat new to Vue, and I'm working on trying to make a transition work. The outcome would look similar to the gif below. The element moving from right to left is one component in Vue, but the issue is I'm transitioning it from one Bootstrap column to another. From what I've seen online, there isn't an easy way to CSS transition while also changing the parent element, so what I've done is basically rendered the component twice, and delayed the second one. In the gif, you can see the point where it transitions and its a bit clunky.
I'm wondering if this is best practice, or if there's another, easier way to do this. Should I rework my whole structure to make them live under the same parent, and just change the position via CSS, or should I continue with what I've done and just work to smooth out the transition between the two elements?
<div class="d-flex align-items-center min-vh-100 hero">
<div class="container-fluid">
<div class="row hero-row d-flex">
<div class="col hero-left d-flex align-items-center">
<div class="w-100">
<transition appear name="fade-left" mode="out-in" >
<HeroNav v-if="$route.name!='Home'"/>
<h1 v-else>Hey, I'm George.</h1>
</transition>
</div>
</div>
<div class="col d-flex hero-right align-items-center">
<transition name="slide" mode="out-in">
<HeroNav v-if="$route.name=='Home'"/>
<div v-else>
</div>
</transition>
</div>
</div>
</div>
</div>
</template>
<script>
import HeroNav from '#/components/HeroNav.vue'
export default {
name: 'Hero',
components: { HeroNav }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.hero {
background: #24292E;
height: 100%;
}
.hero-row {
height: 30em;
}
.hero-left {
border-right: 1px solid #AEC6CF;
}
.hero-left .nav-text{
float: right;
margin-right: 3em;
z-index: 1;
}
.hero-right .nav-text{
margin-left: 3em;
}
h1 {
color: #CFAEB5;
font-family: 'Lato', sans-serif;
font-size: 4rem !important;
font-weight: 100 !important;
text-align: right;
}
h3 {
color: #ffffff;
}
.fade-enter-active,
.fade-leave-active {
transition: all .5s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
.fade-left-enter-active,
.fade-left-leave-active {
transition: all 1s ease;
transition-delay: .15s;
}
.fade-left-enter-from,
.fade-left-leave-to {
opacity: 0;
}
.slide-enter-active,
.slide-leave-active {
transition: all 1.7s cubic-bezier(.17,.67,0,1);
}
.slide-leave-to {
transform: translateX(-29.4em);
opacity: 1;
}
</style>```

Prevent parent CSS while focus on child button

I've a <div> wrapped within <a>. a:active has css to transform the element but I don't want that behaviour (transform) to be there while I focus on bx--overflow-menu child. I am using NextJS with styled-jsx and SaSS. Below is my code :
<a class="singleTile" data-cta-type="unimplemented" href="test">
<div class="bx--row">
<div class="bx--overflow-menu" role="button" aria-haspopup="true" aria-expanded="false" aria-label="Menu" tabindex="0">
<svg focusable="false" aria-label="open and close list of options" role="img" class="bx--overflow-menu__icon">
<circle cx="8" cy="3" r="1"></circle>
<circle cx="8" cy="8" r="1"></circle>
<circle cx="8" cy="13" r="1"></circle>
<title>open and close list of options</title>
</svg>
</div>
<div class="bx--col">
<p class="name-212">cougar</p>
<p class="name-213">Version:<span class="" style="display: inline;">test.1</span></p>
</div>
</div>
</a>
The styles:
<style>
.singleTile {
flex: none;
width: 100%;
border: 1px solid #e0e0e0;
display: block;
padding: 1rem;
transition: all 150ms cubic-bezier(0.2, 0, 0.38, 0.9);
background-color: #ffffff;
}
a.singleTile:hover {
border-color: red;
}
a.singleTile:active {
transform: scale(.994);
}
.bx--overflow-menu{
top: 0;
right: .25rem;
position: absolute;
}
</style>
I have some idea that it can't be done with CSS only and I am also not allowed to use jQuery.
Any other suggestions will be helpful.
There are no parent selectors in css right now. It could be possible to implement this on next css4.
.singleTile:has(> bx--overflow-menu:active) { /* styles to apply to the singleTile tag */ }

Range input refuses to change background color and height

So I'm working on a website for a radio station and have encountered an issue. The range input we use for volume literally refuses to change its background color and height. I'm using SASS (which makes it a scss file type) for the purposes of this project.
I've done some research and have tried a few things the Internet recommended, but unfortunately, none have worked. I have tried using background, background-color and even color fields to try and fix my issue. I have made sure to overwrite everything that might be stopping me from doing so by setting the -webkit-appearance to none.
This is the content of the slider and its parent elements in my hbs file:
<div class="rootplayer">
<div>
<img class="picture" alt='Artist art' src="{{songart}}" width="170px">
<div class="playerinfo">
<p>On air: {{dj}}</p>
<hr>
<p>Up next: AJS Show</p>
<hr>
<p>Currently playing: {{songTitle}}</p>
<hr>
<p>Current Listeners: {{currentListeners}}</p>
</div>
<audio controls="" id="player">
<source src="http://radio.nowhits.uk:8000/radio.mp3" type="audio/mpeg">
<p>Your browser does not support the audio element.</p>
</audio>
</div>
<div class="playercontrols">
<i class="fas fa-play" onclick="play()" id="play"></i>
<i class="fas fa-pause" onclick="pause()" id="pause"></i>
<input type="range" min="0" max="1" value="0.5" step="0.01" class="slider" id="volume">
<script src="scripts/volume.js"></script>
<script src="scripts/playpause.js"></script>
</div>
</div>
And this is the content of the slider object in my scss file:
.slider {
-webkit-appearance: none;
height: 1px;
width: 65%;
background-color: red;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
cursor: pointer;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 12px;
height: 12px;
background: #000;
border-radius: 50%;
}
.slider::-moz-range-thumb {
width: 12px;
height: 12px;
background: #000;
cursor: pointer;
border-radius: 50%;
}
Obviously, the expected output should be a red background and a height of 1px (should be a pretty thin line), but instead, I get this.
Try to add this :
.slider::-webkit-slider-runnable-track {
background: red;
}
.slider::-moz-range-track {
background: red;
}
.slider::-ms-track {
background: red;
}
Look at this site for more customizations : http://danielstern.ca/range.css

Resources