How to control css transition? - css

I am creating a search bar that accepts search terms from user.I have inserted a CSS transition (it's width increases on click).The problem I am facing is that when i click the submit button the width of the search bar decreases.I don't want that to happen and the search bar should retain its changed width.
Here is the HTML:
<input type="text" placeholder=" search" id="search">
<button type="submit" id="submit" >submit </button>
</form>
Here is the CSS:
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid black;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url("http://icons.iconarchive.com/icons/ampeross/qetto-2/256/search-icon.png");
background-size:40px;
/*background-position: 10px 10px;*/
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
margin-left:7%;
}
input[type=text]:focus {
width: 75%;
}
Here is the link to my code if it helps:
https://codepen.io/ryoko1/pen/eRMYrg?editors=1111

The problem I am facing is that when i click the submit button the width of the search bar decreases.
That's because as soon as input losses it's focus it decrease it's input width back to originally assigned or default width. This even happens when you click anywhere else in the page not only submit button and reason is it lost focus from input. So do using jQuery click() method.
$("input[type='text']").on("click",function(){
$(this).css("width","75%");
}); //Add this to your jQuery
$(document).ready(function() {
var url = "https://cors-anywhere.herokuapp.com/https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=bill gates";
$.getJSON(url, function(data) {
// console.log(data[1]);
});
$("#submit").click(function() {
// document.getElementById("demo").innerHTML("hello");
// console.log("hello");
});
$("input[type='text']").on("click", function() {
$(this).css("width", "75%");
});
});
body {
background-color: black;
background-repeat: no-repeat;
background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Wikipedia-logo-en-big.png/800px-Wikipedia-logo-en-big.png");
}
h1 {
color: white;
text-align: center;
}
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid black;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url("http://icons.iconarchive.com/icons/ampeross/qetto-2/256/search-icon.png");
background-size: 40px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out .1s;
margin-left: 7%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1> Wikipedia Viewer</h1>
<form>
<input type="text" placeholder=" search" id="search">
<button type="submit" id="submit">submit </button>
</form>
<p id="demo"></p>

You can use transition delay (set to 100ms):
transition: width 0.4s ease-in-out .1s;
Additional reset delay on focused element:
input[type=text]:focus {
transition-delay: 0s;
}

Related

Link/Chain CSS Transitions

I know this should be a no-brainer, but for some reason I really just cannot figure out how to link my CSS transitions... I am attaching a website with widgets that act how I want mine to act: https://kion.io/resources
I love that when you hover on the widget, all CSS transitions happen at the same time over that one div/a href
I am attempting to do the same, and I have written all of my code but I have to hover individually over my elements... this is for a site that is not yet done, but I will post a link to the page that I am referring to. Specifically focusing on the widgets in the middle of the page. They scale up, BUT I want the arrows to move to the right when you hover over the entire div like in Kion's site. I can only figure out how to make them move when you hover over them specifically.
My site: https://cloudshape.net/cloudshape/
My code:
/*WIDGETS*/
.card a {
text-decoration: none;
color: black;
}
.card a:hover {
color: black;
}
.card {
font-family: 'helvetica', sans-serif;
margin: 25px;
display: flex;
justify-content: center;
align-items: center;
align-content: center;
background-image: url('https://cloudshape.net/wp-
content/uploads/2022/02/clear-bg.png');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
transition: background-image 2s ease-in-out;
}
.white-square {
width: 310px;
height: 330px;
background-color: white;
border: 2px solid black;
border-radius: 6px;
box-shadow: 0 0 10px 2px #202020;
padding: 15px;
text-align: center;
transition: transform .4s ease-in-out, border .4s ease-in-out;
}
/*WIDGET ARROW BUTTONS*/
.btn img {
width: 80px;
margin-top: -20px;
margin-left: 120px;
}
.btn img:hover {
margin-left: 130px;
}
.btn img {
transition: margin-left .7s ease;
}
<div class="card">
<a href="">
<div class="white-square">
<span class="icon"><img alt="security" src="https://cloudshape.net/wp-content/uploads/2022/02/shielddot-color.png"/></span>
<h5>Dev(Sec)Ops/SRE<br>Architecture & Modernization</h5>
<p>Short for development, security and operations — automates the integration of security at every phase of the software development lifecycle.</p>
<span class="btn"><img alt="button" src="https://cloudshape.net/wp-content/uploads/2022/02/arrow.png"/></span>
</div>
</a>
</div>
You could use this CSS rule to target your arrow when your white square is hovered :
.white-square:hover .btn img {
margin-left: 130px;
}

Trying to style input type range but thumb doesnt get styled

im trying to style an input type='range' i am able to style the runnable track but for some reason the thumb isnt getting styled fully
this is my code:
<input type="range" min="0" max="100 " value="50" id="slider" class="volume">
#slider {
width: 0;
opacity: 0;
transform: translateX(-50px);
position: absolute;
transition: 0.5s;
}
#slider::-webkit-slider-runnable-track {
-webkit-appearance: none;
height: 3px;
background-color: var(--white2);
}
#slider::-webkit-slider-thumb {
-webkit-appearance: none;
height: 7px;
width: 7px;
transform: translateY(-5px);
background-color: var(--white);
border: 1px solid;
}
somehow the transform: translateY(-5px); is getting applied but nothing else is.
Nevermind, it was an issue cause by an experimental chrome flag :/ sorry for wasting your time.

My responsive image gallery does not transition captions correctly

I would quite like to have captions that fade in at the bottom of the image. Whilst debugging I have found that div.desc is where it should be, as in, where it should appear, but no transition so to speak.
It could well be that the syntax for the way a div.item should hover is not correct.
Can someone help guide what I am doing wrong.
CSS:
div.img {
border: 1px solid #ccc;
}
div.img:hover {
border: 1px solid #777;
}
div.img img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
position: absolute;
background: rgba(0,0,0,0.75);
color: white;
padding: 10px 20px;
opacity: 0;
bottom: 0;
-webkit-transition: all 0.6s ease;
-moz-transition: all 0.6s ease;
-o-transition: all 0.6s ease;
}
a:hover .item {
opacity: 1;
left: 0;
z-index: 500;
}
With my HTML:
<div class="responsive">
<div class="img">
<a target="_blank" href="img_fjords.jpg">
<img src="/images/demo.jpg" alt="Find" width="535" height="535">
</a>
<div class="desc"><div class="item">This is the caption</div></div>
</div>
</div>
It looks like you're trying to transition the opacity on .desc, no?
If so, the reason it doesn't work is because you've selected the wrong element in your :hover code. You'll want to write this instead of what you have:
a:hover + .desc
The reason is that neither .item nor .desc is a child of your anchor tag. .desc is an adjacent sinling of it, and using + in CSS selects them. Also, you want to transition the elements that have properties to transition between (in this case, only .desc has its opacity changed initially).

Keep input placeholder always visible

I am trying to style all the inputs in my website in a way that when they have a value or have focus the palceholder becomes the title of the input (it moves to the top of the input) but the default behavior of the browser hides the placeholder when there is data on it.
I really want to stay away from JS solutions.
Current results :
My css :
input:focus::-webkit-input-placeholder {
transform: translate(-1rem,calc(-100% - 0.8rem));
font-size: 0.9rem !important;
opacity: 1 !important; //this doesnt seem to keep the placeholder visible
display:block !important; //this doesnt seem to keep the placeholder visible
}
input::-webkit-input-placeholder{
display:block !important; //this doesnt seem to keep the placeholder
opacity: 1 !important; //this doesnt seem to keep the placeholder
}
It cant be done using just the placeholder. Here is sample.
body {
padding: 25px 10px
}
* {
margin: 0
}
.fieldOuter {
position: relative;
margin: 0 0 30px 0;
font-family: impact;
font-size: 16px
}
.fieldOuter input {
padding: 10px;
width: 250px;
transition: all 1s;
border: 2px solid #999;
font-size: 17px;
color: #666
}
.fieldOuter label {
position: absolute;
left:0px;
top: 0;
line-height:15px;
transition: all 0.5s;
overflow: hidden;
color: #999;
white-space: nowrap;
z-index: 1;
opacity: 0;
}
.fieldOuter input:focus + label {
opacity: 1;
top: -18px;
}
.fieldOuter input:focus {
outline: none;
border-color: rgba(82, 168, 236, 0.8);
}
<div class="fieldOuter">
<input id="Name" placeholder="Name" type="text" />
<label for="Name">Name</label>
</div>
<div class="fieldOuter">
<input id="LastName" placeholder="Last Name" type="text" />
<label for="LastName">Last Name</label>
</div>

Input text tooltip doesn't show up

I'm going to add the tooltip for the input text in the page, this page has their own css!
my code is work on local machine but when i pasted code on that page it doesn't work, it seems there is a conflict on the page, but i've ran out of finding the issue.
the js is :
<script src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js"></script>
<script>
// execute your scripts when the DOM is ready. this is a good habit
$(function() {
// select all desired input fields and attach tooltips to them
$("#myform :input").tooltip({
// place tooltip on the right edge
position: "center right",
// a little tweaking of the position
offset: [-2, 10],
// use the built-in fadeIn/fadeOut effect
effect: "fade",
});
});
</script>
the css is :
#myform {
}
.tooltip{
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
background-color: #fff;
border: 1px solid;
position: absolute;
border-color: #bbb #bbb #a8a8a8;
padding: 16px;
width: 255px;
line-height: 17px;
opacity: 0;
left: 16px;
top: 48px;
-webkit-transition: all 0.218s;
-moz-transition: all 0.218s;
-o-transition: all 0.218s;
transition: all 0.218s;
}
and the code is :
<form id="myform" action="#">
<!-- username -->
<label for="username">Username</label>
<input id="username" title="Must be at least 8 characters."/>
</form>
and below is the current input css of the page:
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
textarea:focus {
color: #000;
font-size: 1.4rem;
font-size: 14px;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"] {
padding: 8px 10px 8px 46px;
width: 83%;
}
You can overwrite style by adding your own .tooltip style and overwriting each style using !important . do it for each style in .tooltip. hope this help. here is a simple JSFiddle example.
.tooltip{
background-color:red !important;
}

Resources