Smoothening CSS transition - html

Based on a few examples here and there I made one o those search elements in which there's only the icon visible and the text field slides to the right when hovering either the icon or its parent element:
#import URL( 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css' );
:root {
--darker-gray: 22, 22, 22; /** #191919 */
--mid-gray: 89, 89, 89; /** #595959 */
}
header .top {
background-color: rgba( var( --darker-gray ) );
-webkit-box-shadow: 0 3px 5px -2px #0D0D0D;
box-shadow: 0 3px 5px -2px #0D0D0D;
color: rgba( var( --light-text ) );
padding: 2.5rem;
position: fixed;
top: 0;
width: 100%;
}
.wrapper input {
background: transparent;
border: none;
color: rgba( var( --mid-gray ) );
cursor: pointer;
display: inline-block;
font-size: 2rem;
height: 3.75rem;
left: 2.5rem;
outline: none;
position: absolute;
top: 0;
transition: all .5s;
width: 0;
z-index: 3;
}
.wrapper svg {
cursor: pointer;
margin-top: -1.5rem;
position: relative;
top: -1px;
}
.wrapper:hover input,
.wrapper:focus input,
.wrapper:focus-within input {
border-bottom: 1px solid rgba( var( --mid-gray ) );
cursor: text;
width: 24rem;
z-index: 1;
}
.wrapper:hover svg,
.wrapper:focus svg,
.wrapper:focus-within svg {
left: 22rem;
}
.icon.search {
fill: rgba(var(--mid-gray));
height: 2.25rem;
width: 2.25rem;
}
<header>
<div class="top">
<div class="d-flex justify-content-between">
<div class="wrapper">
<input placeholder="search" type="text" />
<svg class="icon search button">
<path d="M9.516 14.016q1.875 0 3.188-1.313t1.313-3.188-1.313-3.188-3.188-1.313-3.188 1.313-1.313 3.188 1.313 3.188 3.188 1.313zM15.516 14.016l4.969 4.969-1.5 1.5-4.969-4.969v-0.797l-0.281-0.281q-1.781 1.547-4.219 1.547-2.719 0-4.617-1.875t-1.898-4.594 1.898-4.617 4.617-1.898 4.594 1.898 1.875 4.617q0 0.984-0.469 2.227t-1.078 1.992l0.281 0.281h0.797z"/>
</svg>
</div>
</div>
</div>
</header>
There's some misalignment on the icon but, for some reason, it's just here
Worked nicely but it was too blunt. So I've added a transition transition: all .5s; and it worked perfectly... on the opening. When the text field gets hidden, the grey line goes first, then the placeholder text and finally the SVG icon.
Also, after I've added the transition, on page load the text box flickers for a moment. After a few tests I've found out the culprit is the all defined in the transition tule that's, as expected, is also affecting the background-color required to make the text field transparent.
How could I make it smoother, showing/hiding everything at the same time without this flickering?

if you also add a transition on SVG and its left coordonates, does it look better to you ?
Also, transition can be set only on a single or more properties alike :
transition: width .5s, z-index 0.5s; to occur only on width and z-index.
#import URL( 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css' );
:root {
--darker-gray: 22, 22, 22; /** #191919 */
--mid-gray: 89, 89, 89; /** #595959 */
}
header .top {
background-color: rgba( var( --darker-gray ) );
-webkit-box-shadow: 0 3px 5px -2px #0D0D0D;
box-shadow: 0 3px 5px -2px #0D0D0D;
color: rgba( var( --light-text ) );
padding: 2.5rem;
position: fixed;
top: 0;
width: 100%;
}
.wrapper input {
background: transparent;
border: none;
color: rgba( var( --mid-gray ) );
cursor: pointer;
display: inline-block;
font-size: 2rem;
height: 3.75rem;
left: 2.5rem;
outline: none;
position: absolute;
top: 0;
transition: width .5s, z-index 0.5s;
width: 0;
z-index: 3;
}
.wrapper svg {
cursor: pointer;
margin-top: -1.5rem;
position: relative;
top: -1px;
left:0;
transition:left .5s;
}
.wrapper:hover input,
.wrapper:focus input,
.wrapper:focus-within input {
border-bottom: 1px solid rgba( var( --mid-gray ) );
cursor: text;
width: 24rem;
z-index: 1;
}
.wrapper:hover svg,
.wrapper:focus svg,
.wrapper:focus-within svg {
left: 22rem;
}
.icon.search {
fill: rgba(var(--mid-gray));
height: 2.25rem;
width: 2.25rem;
}
<header>
<div class="top">
<div class="d-flex justify-content-between">
<div class="wrapper">
<input placeholder="search" type="text" />
<svg class="icon search button">
<path d="M9.516 14.016q1.875 0 3.188-1.313t1.313-3.188-1.313-3.188-3.188-1.313-3.188 1.313-1.313 3.188 1.313 3.188 3.188 1.313zM15.516 14.016l4.969 4.969-1.5 1.5-4.969-4.969v-0.797l-0.281-0.281q-1.781 1.547-4.219 1.547-2.719 0-4.617-1.875t-1.898-4.594 1.898-4.617 4.617-1.898 4.594 1.898 1.875 4.617q0 0.984-0.469 2.227t-1.078 1.992l0.281 0.281h0.797z"/>
</svg>
</div>
</div>
</div>
</header>

Related

Issue when creating an expanding search bar using :focus-within

I want to make a search bar as this website's search bar: https://www.arrivalguides.com/en.
I tried with this code: (Here's a codepen)
HTML:
<div class="col-md-4 d-flex justify-content-end all-buttons">
<div class="col-md-4 d-flex justify-content-end search-bar">
<a nbButton outline class="text-decoration-none add-btn" id="add-btn-hide" >
<i class="nb-plus fa-1x"> </i> Add User
</a>
<button nbButton class=" multi-delete-btn" id="delete-btn-hide" >
<i class="nb-trash fa-2x"></i>
Delete All
</button>
<input type="text" class="search-input" id="search-input" fullWidth nbInput placeholder="Enter Search" (keyup)="onKey($event)" />
<button nbButton class="search-btn" nbTooltip="Quick Search " nbTooltipPlacement="top" status="primary">
<!-- <nb-icon icon="search-outline"></nb-icon> -->icon
</button>
</div>
</div>
CSS:
body{
margin:40px;
}
.all-buttons {
height: 30px;
padding-right: 0;
}
.info-btn {
padding: 0.4rem;
border-radius: 0.25rem;
margin-right: 3px;
background-color: blue;
border-color: blue;
}
.advanced-filters {
background-color: green;
padding: 0.6rem 0 0 0;
border-radius: 0.5rem;
margin-left: 1px;
}
.multi-delete-btn {
margin: 0 8px 0 3px;
color:white;
background-color: orange;
border-color:orange;
border-radius: 0.25rem ;
padding: 0 5px 0 0 ;
opacity: 1 !important;
transition: width 0.5s ease-out;
}
.add-btn {
border-color:blue ;
background-color: blue ;
color: white;
padding: 0.5rem;
border-radius: 0.25rem;
margin: 0 ;
opacity: 1 !important;
transition: width 0.5s ease-out;
}
.search-bar {
border: none !important;
margin-right: 2px !important;
border-radius: 100px ;
min-width: 33px !important;
position: relative;
transition: width 0.5s ease-out;
}
.search-input {
background: transparent;
border: 0;
background-color: lightblue;
opacity: 0;
width:40px !important;
transition: width 0.5s ease-out;
&:focus {
outline: 0;
}
}
.search-btn {
cursor: pointer;
border: 2px solid blue;
border-radius: 0.25rem !important;
background: transparent;
margin: 0 !important;
position: absolute ;
top:0 ;
bottom:0;
right: 0;
}
.search-bar:focus-within{
width:50% !important;
border: 2px solid brown !important;
.search-input{
width: 100% !important ;
background-color: rgba(196, 158, 233, 0.205);
color: black !important;
cursor: initial ;
opacity: 1;
}
.add-btn{
display: none !important;
}
.multi-delete-btn{
display: none!important;
}
}
The issue:
When I click outside of the search icon, the "Add" button and "Delete-all" button should appear. But in my case they are just moving. (When I click the search icon, the add-button and delete-all button disappear– this is okay)
Here is an approach isolating only the search input and a search input container. The input is absolutely positioned inside a relative container so that I could grow the input from right to left. I did this by anchoring it to the right side of the parent container using right: 0.
I'm combining focus-within and placeholder-shown to grow/shrink the input. Using placeholder-shown is needed to prevent the input from shrinking if the user has typed something in the input. To hide the placeholder text and only show the search icon when the input is shrunk, I'm making the placeholder text color transparent.
.search-input-container {
position: relative;
}
.search-input {
--search-icon-width: 24px;
--search-max-width-expanded: 20rem;
--search-max-width-collapsed: 2.3rem;
--search-color: #ccc;
background-color: var(--search-color);
max-width: var(--search-max-width-collapsed);
padding: .5rem 0.75rem;
overflow: hidden;
transition: 0.3s max-width, 0.3s margin;
border: none;
background-image: url(https://image.flaticon.com/icons/png/512/93/93642.png);
background-size: 18px;
background-repeat: no-repeat;
background-position: calc(100% - 10px) 50%;
position: absolute;
right: 0;
font-size: 16px;
border-radius: 15px;
}
.search-input:focus-within,
.search-input:not(:placeholder-shown) {
max-width: var(--search-max-width-expanded);
padding-right: var(--search-icon-width);
}
.search-input:not(:focus-within)::placeholder {
color: transparent;
}
/* Ignore */
body {
display: grid;
place-items: center;
}
<div class="search-input-container">
<input placeholder="search" type="search" class="search-input">
</div>

How can I styling this design only with CSS?

I want to design the above image using pure CSS.
Following is the HTML and CSS I have come up with so far:
<div>
<input
className="my_file"
type="file"
onChange={(event) => {
setImageSelected(event.target.files[0]);
}}
/>
<svg
width="20"
height="18"
viewBox="0 0 20 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className="upload_image_icon"
>
<path
d="M7 0L5.17 2H2C0.9 2 0 2.9 0 4V16C0 17.1 0.9 18 2 18H18C19.1 18 20 17.1 20 16V4C20 2.9 19.1 2 18 2H14.83L13 0H7ZM10 15C7.24 15 5 12.76 5 10C5 7.24 7.24 5 10 5C12.76 5 15 7.24 15 10C15 12.76 12.76 15 10 15Z"
fill="white"
/>
</svg>
<Avatar
src={picture}
alt="Avatar"
id="hello"
className="avatar--profile_image"
/>
</div>
and here is my scss:
.profile--card_container {
width: 348px;
height: 448px;
// border: 1px solid rgb(211, 211, 211);
// border-radius: 5px;
.avatar--profile_image {
justify-content: center !important;
margin-bottom: 10px;
margin-top: 10px;
margin-left: 6.50rem;
height: 100px !important;
width: 100px !important;
box-shadow: rgba(0, 0, 0, 0.01) 0px 5px 16px 0px,
rgba(0, 0, 0, 0.10) 0px 0px 0px 0px;
position: relative;
overflow: hidden;
background-size: cover;
background-position: center;
background-blend-mode: multiply;
color: transparent;
transition: all .3s ease;
cursor: pointer;
border: 2px solid rgba(0, 0, 0, 0.54);
&:after {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.6);
opacity:0;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
&:hover:after {
opacity:1;
}
}
input[type=file]::-webkit-file-upload-button {
cursor: pointer;
}
.my_file {
position: absolute;
outline: none;
color: transparent;
box-sizing: border-box;
transition: 0.5s;
margin: 45px 0 0 100px;
z-index: 1;
opacity: 0;
cursor: pointer;
}
.upload_image_icon {
margin: 44px 0 0 144px;
cursor: pointer;
position: absolute;
outline: none;
box-sizing: border-box;
z-index: 1;
}
}
here is how my result look like for now:
I am trying to achieve like when I hover profile picture the image will overlay black color and appear camera icon. How can I do that ?
Wrap the image within a div. and then use a pesudo-element with a z-index that onyl dispalys when you hover that div like in the snippet below:
.avatar {
width: 100px;
height: 100px;
position: relative;
}
.avatar img {
width: 100%;
object-fit: cover;
border-radius: 50%;
}
.avatar > div {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
border-radius: 50%;
background-color: rgba(0, 0, 0, 0.6);
z-index: 2;
display: none;
}
.avatar:hover > div {
display: flex;
justify-content: center;
align-items: center;
}
<div class="avatar">
<img src="https://via.placeholder.com/500x500.jpg">
<div>Icon</div>
</div>

CSS background layers bug

I am trying to implement button I took from codepen on my existing "box-list" div.
But in my form the button gets fathers background and I cant perform my original button blue background as it should be.
On the bottom of the page you can see the button outside the "box-list" how it should look.
<link rel="stylesheet" type="text/css" href="style.css">
<div class="box-list">
<!-- FREE TEXT BOX -->
<div class="box" >
<div class="box__inner">
<h1>Free Text</h1>
Get you free text processed and analyzed, and get opinion summery about.
<button class="analyzeBtn mybtn1" >hover</button>
</div>
</div>
<!-- TWITTER BOX -->
<div class="box" >
<div class="box__inner">
<h1>Twitter Search</h1>
Get Twitter post and comments about any subject you choose and analyze the dat
</div>
</div>
<div class="box" >
<div class="box__inner">
<h1>URL</h1>
Get your URL article analyzed
</div>
</div>
</div>
<button class="analyzeBtn mybtn1" >hover</button>
.box-list {
background: #119bc9;
overflow: hidden;
display: flex;
}
.box {
min-height: 300px;
color: #fff;
transition: all 0.5s;
max-height: 300px;
background-image: url('http://lorempixel.com/400/300/sports');
background-size: cover;
width: 33.33%;
}
.box__inner {
padding: 20px;
min-height: 300px;
background-color: rgba(17, 155, 201, 0.7);
}
.box:hover {
width: 150%!important;
font-size: 18px;
}
.box:nth-child(odd) {
background-image: url('/images/text.jpg');
}
.box:nth-child(odd) .box__inner{
background: rgba(71, 83, 157, 0.8);
}
.analyzeBtn {
border: 1px solid #3498db;
background: none;
padding: 10px 20px;
font-size: 20px;
font-family: "montserrat";
margin: 10px;
transition: 0.8s;
position: relative;
cursor: pointer;
overflow: hidden;
border-radius: 5px;
}
.mybtn1 {
color: #fff;
}
.mybtn1:hover {
color: #3498db;
transform: translateY(-7px);
transition: 0.4s;
}
.analyzeBtn::before {
content: "";
position: absolute;
left: 0;
width: 100%;
height: 0%;
background: #3498db;
z-index: -1;
transition: 0.6s;
}
.mybtn1::before {
top:0;
border-radius: 0 0 50% 50%;
height: 180%;
}
.mybtn1:hover::before {
height: 0%;
}
JSfiddle example
You need to add z-index: 1; to the button so that it is displayed on top of the backgrounds:
.analyzeBtn {
border: 1px solid #3498db;
background: none;
padding: 10px 20px;
font-size: 20px;
font-family: "montserrat";
margin: 10px;
transition: 0.8s;
position: relative;
cursor: pointer;
overflow: hidden;
border-radius: 5px;
z-index: 1;
}

How to format text with hover overlay image

I have the following code with the goal to display a name without hovering centered in the shape, then after hovering having a bio of 5 lines all centered with minimal spacing between line breaks.
The problem in my code currently is formatting the front-side to be all centered and have the same big font as the after-hover, and even more notably wrong- the info on the back is coming off the end of the shape. Not centered.
<html>
<div id="box">
John Doe
<div id="overlay">
<span id="plus">Title:<br>DOB:<br>Hometown:<br>Info4:<br>Info5:</span>
</div>
</div>
<style>
body {
background: -1;
}
#box {
width: 300px;
height: 200px;
box-shadow: inset 1px 1px 40px 0 rgba(0, 0, 0, 0.45);
border-bottom: 2px solid #fff;
border-right: 2px solid #fff;
margin: 5% auto 0 auto;
background-size: cover;
border-radius: 5px;
overflow: hidden;
/* NEW */
line-height: 200px;
text-align: center;
position: relative;
}
#overlay {
background: rgba(0, 0, 0, 0.75);
text-align: center;
padding: 45px 0 66px 0;
opacity: 0;
-webkit-transition: opacity 0.25s ease;
-moz-transition: opacity 0.25s ease;
/* NEW */
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
#box:hover #overlay {
opacity: 1;
}
#plus {
font-family: Helvetica;
font-weight: 900;
color: rgba(255, 255, 255, 0.85);
font-size: 24px;
}
</style>
</html>
This isn't an answer to all of your questions, but to get the font styles to be the same, add the font styling that you have for #plus to the #box selector instead. You will have to change the color for the box selector to black and for #plus you can leave what you currently have for the color.

Why background is blinking on hover when I move mouse cursor in DP box

I am trying to create a DP box for the user which is containing a user profile picture in it, where on image hover an edit profile image link will appear, but it is not working. When I hover over on the image it is blinking and the link doesn't appear correctly.
Here is the codepan link click here
#import url(https://fonts.googleapis.com/css?family=Roboto);
body {
font-family: 'Roboto', sans-serif;
background-color: #eee;
}
.dp {
width: 128px;
height: 128px;
margin: 0 auto;
border-radius: 50%;
border: 4px solid #fff;
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.52);
overflow: hidden;
position: relative;
}
.edit-dp a {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
line-height: 130px;
background-color: rgba(0, 0, 0, .9);
text-align: center;
transition: all .2s ease-in-out;
color: #fff;
font-size: 15px;
text-decoration: none;
display: none;
}
.dp img:hover ~ .edit-dp a {
display: block;
}
<div class="dp">
<img src="http://rs618.pbsrc.com/albums/tt265/davejarrett/Avatars/check-in-minion_zps7ee060ac.jpg~c200" alt="" width="128">
<div class="edit-dp">
Edit Image
</div>
</div>
The blinking glitch is because of that :hover effect of display: block on image instead of container div.
Since every time you :hover on the image you ultimately gonna edit it, so instead of display: none you can set it to opacity: 0 and on :hover you can set it to opacity: 1 and by doing this you'll get a nice transition effect too.
Here's the Snippet for a better view:
#import url(https://fonts.googleapis.com/css?family=Roboto);
body {
font-family: 'Roboto', sans-serif;
background-color: #eee;
}
.dp {
width: 128px;
height: 128px;
margin: 0 auto;
border-radius: 50%;
border: 4px solid #fff;
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.52);
overflow: hidden;
position: relative;
}
.edit-dp a {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
line-height: 130px;
background-color: rgba(0, 0, 0, .9);
text-align: center;
color: #fff;
font-size: 15px;
text-decoration: none;
opacity: 0;
-webkit-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
}
.dp:hover .edit-dp a {
opacity: 1;
}
<div class="dp">
<img src="http://rs618.pbsrc.com/albums/tt265/davejarrett/Avatars/check-in-minion_zps7ee060ac.jpg~c200" alt="" width="128">
<div class="edit-dp">
Edit Image
</div>
</div>
Solution 1:
Use following css will make your effect nice.
.dp:hover > .edit-dp a{
display: block;
}
Make hover effect on div instead of image
#import url(https://fonts.googleapis.com/css?family=Roboto);
body {
font-family: 'Roboto', sans-serif;
background-color: #eee;
}
.dp {
width: 128px;
height: 128px;
margin: 0 auto;
border-radius: 50%;
border: 4px solid #fff;
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.52);
overflow: hidden;
position: relative;
}
.edit-dp a {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
line-height: 130px;
background-color: rgba(0, 0, 0, .9);
text-align: center;
transition: all .2s ease-in-out;
color: #fff;
font-size: 15px;
text-decoration: none;
display: none;
}
.dp:hover > .edit-dp a{
display: block;
}
<div class="dp">
<img src="http://rs618.pbsrc.com/albums/tt265/davejarrett/Avatars/check-in-minion_zps7ee060ac.jpg~c200" alt="" width="128">
<div class="edit-dp">
Edit Image
</div>
</div>
Working Codepen
Solution 2:
And Another solution is use pointer-events:none; on hover.
.dp img:hover ~ .edit-dp a{
display: block;
pointer-events:none;
}
Working Codepen