Transition input width - html

I have the input search field. When I click on it I need it to become wider performing smooth transition from right to left, i.e. the input is located on the right side of the page and when I click on it it should stretch to the left in some number of pixels and become wider.
Here's my css:
#header #search input {
background: #FFF;
padding: 1px 1px 1px 5px;
width: 178px;
height: 21px;
border: 1px solid #CCCCCC;
border-radius: 6px;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
}
#header #search input:focus {
background: #FFF;
padding: 1px 1px 1px 5px;
width: 300px;
height: 21px;
border: 1px solid #CCCCCC;
Could you help me with implementing that?

input[type="search"] {
background: #FFF;
padding: .5rem 1rem;
position: relative;
top: 0;
left: 0;
width: 178px;
height: 40px;
outline: none;
border: 1px solid #CCCCCC;
border-radius: 6px;
transition: all .5s;
}
input[type="search"]:focus {
width: 300px;
top: 0;
right: 100%;
}
<div style="text-align:right;">
<input type="search" id="search" />
</div>

Position the input absolutely and set the right property to zero:
position:absolute;
right:0;
That forces the expansion to the left when focused.
jsFiddle example

Make your containers offset parents using position: relative.
#header, #search {
width: 100%;
position: relative;
}
Then position your input using position: absolute and place it using right.
#header #search input {
position: absolute;
right: 0px;
background: #FFF;
padding: 1px 1px 1px 5px;
width: 178px;
height: 21px;
border: 1px solid #CCCCCC;
border-radius: 6px;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
}
#header #search input:focus {
background: #FFF;
padding: 1px 1px 1px 5px;
width: 300px;
height: 21px;
border: 1px solid #CCCCCC;
Your animation will now stretch to the left.

Related

Adding right: 50% to input tag doesn't do anything [duplicate]

This question already has answers here:
How can I center an absolutely positioned element in a div?
(37 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 2 years ago.
Below, the left: 50% in the css does not move the input element in any way. Anyone know why? Is this just not possible? Do I have anything blocking it? I don't want to use margins because it will look different on different computers. If left: is not possible, how can this be centered either way?
(I put the left: 50% at the bottom of css for the searchbar)
#searchbar{
border-radius: 4px;
background-color: transparent;
cursor: pointer;
color: transparent;
background: #FFF;
padding: 1px 1px 1px 5px;
width: 30px;
height: 30px;
outline: none;
border: 1px solid #CCCCCC;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
text-align: center;
background: url(https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Simpleicons_Interface_magnifier-1.svg/768px-Simpleicons_Interface_magnifier-1.svg.png) no-repeat scroll 0 0;
background-size: contain;
border:none;
right: 50%
}
<input id = "searchbar" name = "search" size = "1" autocomplete="off" maxlength="27">
Try,
<input id = "searchbar" name = "search" size = "1" autocomplete="off" maxlength="27">
CSS
#searchbar{
position:absolute;
left:50%;
border-radius: 4px;
background-color: transparent;
cursor: pointer;
color: transparent;
background: #FFF;
padding: 1px 1px 1px 5px;
width: 30px;
height: 30px;
outline: none;
border: 1px solid #CCCCCC;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
text-align: center;
background: url(https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Simpleicons_Interface_magnifier-1.svg/768px-Simpleicons_Interface_magnifier-1.svg.png) no-repeat scroll 0 0;
background-size: contain;
border:none;
}
OR
<div id="searchbardiv">
<input id = "searchbar" name = "search" size = "1" autocomplete="off" maxlength="27">
</div>
CSS
#searchbardiv{
width:100%;
display:flex;
position relative
}
#searchbar{
position:absolute;
left:50%;
border-radius: 4px;
background-color: transparent;
cursor: pointer;
color: transparent;
background: #FFF;
padding: 1px 1px 1px 5px;
width: 30px;
height: 30px;
outline: none;
border: 1px solid #CCCCCC;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
text-align: center;
background: url(https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Simpleicons_Interface_magnifier-1.svg/768px-Simpleicons_Interface_magnifier-1.svg.png) no-repeat scroll 0 0;
background-size: contain;
border:none;
}
You can use a flex box to center content.
.flex {
display: flex;
flex-direction: row;
justify-content: center;
}
#searchbar {
border-radius: 4px;
background-color: transparent;
cursor: pointer;
color: transparent;
background: #FFF;
padding: 1px 1px 1px 5px;
width: 30px;
height: 30px;
outline: none;
border: 1px solid #CCCCCC;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
text-align: center;
background: url(https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Simpleicons_Interface_magnifier-1.svg/768px-Simpleicons_Interface_magnifier-1.svg.png) no-repeat scroll 0 0;
background-size: contain;
border: none;
}
<div class="flex">
<input id="searchbar" name="search" size="1" autocomplete="off" maxlength="27">
</div>

How to design non fill rounded checkbox using pure css

I am making a styled rounded checkbox for woocommerce . The Problem is my checkbox is now fill inside . How Can I make it thin inside without filling?
input#createaccount:checked {
background-color: #253849;
}
input#createaccount{
position: relative;
margin-left: 4px;
width: 25px;
float: left;
margin: 2px 10px 2px 1px;
height: 25px;
border-radius: 50%;
vertical-align: middle;
border: 4px solid #295282;
-webkit-appearance: none;
outline: none;
cursor: pointer;
}
<input class="input-checkbox" id="createaccount" type="checkbox" name="createaccount" value="1">
One way to do this without javascript would be to create one wrapper element with input and one more element as a indicator for checkbox state. That way you can use selector input:checked + nextElement and change style of second element based on checkbox status.
Then you just have to hide checkbox with opacity: 0. With this approach you can also use transitions and transforms on the inner element.
.checkbox-el {
position: relative;
margin-left: 4px;
width: 25px;
float: left;
margin: 2px 10px 2px 1px;
height: 25px;
border-radius: 50%;
vertical-align: middle;
border: 2px solid #295282;
-webkit-appearance: none;
outline: none;
cursor: pointer;
padding: 5px;
}
.checkbox-el input {
width: 100%;
height: 100%;
position: absolute;
top: -3px;
left: -3px;
z-index: 5;
opacity: 0;
cursor: pointer;
}
.checkbox-circle {
position: relative;
border-radius: 50%;
width: 100%;
height: 100%;
z-index: 1;
transform: scale(0.5);
transition: all 0.25s ease-in;
}
.checkbox-el input:checked + .checkbox-circle {
background-color: #253849;
transform: scale(1)
}
<span class="checkbox-el">
<input class="input-checkbox" id="createaccount" type="checkbox" name="createaccount" value="1">
<div class="checkbox-circle"></div>
</span>
Simple adding inner shadow solve the issue
box-shadow: inset 0px 0px 0px 5px #ffffff;
input#createaccount:checked {
background-color: #253849;
box-shadow: inset 0px 0px 0px 5px #ffffff;
transition: 0.5s;
}
input#createaccount{
position: relative;
margin-left: 4px;
width: calc(3em - 4px);
height: calc(3em - 4px);
float: left;
margin: 4px 10px 2px 1px;
border-radius: 50%;
vertical-align: middle;
border: 5px solid #295282;
-webkit-appearance: none;
outline: none;
cursor: pointer;
transition: 0.5s;
}
<input class="input-checkbox" id="createaccount" type="checkbox" name="createaccount" value="1">
Here is another trick with a simple background where you color the content-box and you animate the padding. You will also have transparency:
input#createaccount:checked {
padding:3px;
}
input#createaccount {
width: 25px;
float: left;
margin: 2px 10px 2px 1px;
height: 25px;
border-radius: 50%;
vertical-align: middle;
border: 4px solid #295282;
-webkit-appearance: none;
outline: none;
cursor: pointer;
box-sizing:border-box;
background: #253849 content-box;
padding:8.5px; /* 25/2 - 4 */
transition:0.3s all;
}
body {
background:pink;
}
<input class="input-checkbox" id="createaccount" type="checkbox" name="createaccount" value="1">

Making a div expand to all the screen overlaying other divs

I have a 2 by 2 grid of divs displaying each time I enter the page that fills the entire browser screen.
I want to make it in a way that if I hover over each of the divs that one will fullscreen expand over the other three, hiding them while those stay still.
What I have right now doesn't quite work because when I hover over one of the divs it moves all the other ones and ruins the screen. I would really appreciate any advice.
HTML (it's just this inside the body):
<div class="box" id="sup-izq"></div>
<div class="box" id="sup-der"></div>
<div class="box" id="inf-izq"></div>
<div class="box" id="inf-der"></div>
CSS:
.box {
box-sizing: border-box;
float: left;
width: 50%;
height: 50%;
z-index: 1;
-webkit-transition: width 1s, height 1s;
transition: width 1s, height 1s;
}
.box:hover {
width: 100%;
height: 100%;
}
#sup-izq {
border-right: 1px solid black;
border-bottom: 1px solid black;
background-color: #8cff66;
}
#sup-der {
border-left: 1px solid black;
border-bottom: 1px solid black;
background-color: #ff751a;
}
#inf-izq {
border-top: 1px solid black;
border-right: 1px solid black;
background-color: #3385ff;
}
#inf-der {
border-top: 1px solid black;
border-left: 1px solid black;
background-color: #d147a3;
}
The best and most performant way to do that is to use transform: scale and transform-origin
The scale(2) will double its size in both directions (width/height) and the transform-origin, which defaults to center center (50% 50%), controls the origin.
Note, for an element to have a height set in precent, its parent need a height, hence I added the html, body rule. Another option would be to use viewport units vw/vh
html, body { /* added rule */
margin: 0;
height: 100%;
}
.box {
position: relative;
box-sizing: border-box;
float: left;
width: 50%;
height: 50%;
z-index: 0;
transition: transform 0.5s, /* changed property */
z-index 0.5s;
}
.box:hover {
transform: scale(2); /* added property */
z-index: 10; /* added so hovered is on top */
}
#sup-izq {
border-right: 1px solid black;
border-bottom: 1px solid black;
background-color: #8cff66;
transform-origin: left top; /* added property */
}
#sup-der {
border-left: 1px solid black;
border-bottom: 1px solid black;
background-color: #ff751a;
transform-origin: right top; /* added property */
}
#inf-izq {
border-top: 1px solid black;
border-right: 1px solid black;
background-color: #3385ff;
transform-origin: left bottom; /* added property */
}
#inf-der {
border-top: 1px solid black;
border-left: 1px solid black;
background-color: #d147a3;
transform-origin: right bottom; /* added property */
}
<div class="box" id="sup-izq"></div>
<div class="box" id="sup-der"></div>
<div class="box" id="inf-izq"></div>
<div class="box" id="inf-der"></div>
This is rough and ready, but works. The approach was to wrap everything in a relatively positioned wrapper, then position the squares absolutely. That way they can have a z-index, which was the crux of the matter.
.wrap {
position: relative;
height: 500px;
}
.box {
display: block;
width: 50%;
height: 50%;
z-index: 1;
-webkit-transition: width 1s, height 1s;
transition: width 1s, height 1s;
position: absolute;
}
.box:hover {
width: 100%;
height: 100%;
z-index: 2;
}
#sup-izq {
top: 0px;
left: 0px;
border-right: 1px solid black;
border-bottom: 1px solid black;
background-color: #8cff66;
}
#sup-der {
top: 0px;
right: 0px;
border-left: 1px solid black;
border-bottom: 1px solid black;
background-color: #ff751a;
}
#inf-izq {
bottom: 0px;
left: 0px;
border-top: 1px solid black;
border-right: 1px solid black;
background-color: #3385ff;
}
#inf-der {
bottom: 0px;
right: 0px;
border-top: 1px solid black;
border-left: 1px solid black;
background-color: #d147a3;
}
<div class="wrap">
<div class="box" id="sup-izq"></div>
<div class="box" id="sup-der"></div>
<div class="box" id="inf-izq"></div>
<div class="box" id="inf-der"></div>
</div>

Design a input box with extended lines

I am trying to code an input box like in the image below.
However, I only end up with part of the lines with the current code.
When it's a button rather than an edit, everything in fine.
.sidebar-search input {
display: inline-block;
border-color: #ffd717 -moz-use-text-color #ffd717 #ffd717;
border-style: solid none solid solid;
border-width: 2px 0 2px 0px;
color: #ffd717;
padding: 15px 25px;
position: relative;
overflow: hidden;
}
.sidebar-search input::before,
.sidebar-search input::after {
content: '';
width: 2px;
height: 160%;
position: absolute;
top: -30%;
background-color: #FFD717;
-webkit-transition: all 0.3s;
transition: all 0.3s;
z-index: 9999;
}
.sidebar-search input::before {
left: 10%;
}
.sidebar-search input::after {
right: 10%;
}
<div class="right-sidebar-area">
<div class="single-right-sidebar">
<div class="sidebar-search">
<input type="text" name="Search">
</div>
</div>
</div>
You are very close. It looks like ::before and ::after pseudo-selectors don't work for input elements, so apply it directly to sidebar-search and add more styles to that div
.sidebar-search {
/*specify positioning, height and width */
position: relative;
height: 50px;
width: 175px;
}
.sidebar-search input {
display: inline-block;
border-color: #ffd717 -moz-use-text-color #ffd717 #ffd717;
border-style: solid none solid solid;
border-width: 2px 0 2px 0px;
color: #ffd717;
padding: 15px 25px;
position: relative;
top: 5px;
overflow: hidden;
}
.sidebar-search::before,
.sidebar-search::after {
content: '';
width: 2px;
height: 160%;
position: absolute;
top: -30%;
background-color: #FFD717;
-webkit-transition: all 0.3s;
transition: all 0.3s;
z-index: 9999;
}
.sidebar-search::before {
left: 10px; /*these values are more accurate according to the picture */
}
.sidebar-search::after {
right: 10px; /*these values are more accurate according to the picture */
}
<div class="right-sidebar-area">
<div class="single-right-sidebar">
<div class="sidebar-search">
<input type="text" name="Search">
</div>
</div>
</div>

Cleaning up CSS jitters

I've built these circles that expand a border when there is a mouseover. The only problem I'm getting now is some times the circle will jitter/shake. And it becomes more apparent when I set the transition: all .1s ease-in-out; to more than .2s.
Is there a work around to this problem or is that just the way it is?
Here's the code in JsFiddle
Thanks for any and all help!
EDIT: I am transitioning the dimensions (width and height) of the circles to maintain centering. I realize this is causing the jittering during the transition. Is there a work around?
I got rid of the percent values for top/left positioning, cleaned up the margins and aligned the border-width of the outer circle:
Here is a DEMO
.box {
position: relative;
width: 220px;
height: 220px;
float: left;
margin-right: 50px;
}
.clearcircle {
position: absolute;
top:15px;
left:15px;
width: 190px;
height:190px;
border-radius: 100%;
background-color: transparent;
border: 5px solid #c0392b;
transition: all .2s ease-in-out;
}
.clearcircle:hover {
width:220px;
height: 220px;
top: 0px;
left: 0px;
border: 5px solid #c0392b;
}
.circle {
position: absolute;
top:50%;
margin-top: -100px;
left: 50%;
margin-left:-100px;
width: 200px;
height:200px;
border-radius: 100%;
background-color: #e74c3c;
overflow: hidden;
transition: all .2s ease-in-out;
}
.circle p {
position:relative;
text-align: center;
top: 50%;
margin-top: -55px;
color: white;
transition: all .3s;
}
.circle:hover{
background-color: #e97468;
}
Don't transition the width and the height. Keep the same width and height and just transition the border of your outer circle.
For your inner circle (.circle), set a white border 12px solid #ffffff. Now it is always in the same place relative to the outer circle, and now it will not have to change size. Also the title can not jump around because it is always in the same position.
For the outer circle, when it is not hovered, make sure it has the same size and border as when it is, but make the border white, 5px solid #ffffff.
I think you can then also do away with a lot of your extra positioning.
Here is a modified jsFiddle so you can take a look, and here is the CSS modified:
.box {
position: relative;
width: 220px;
height: 220px;
float: left;
margin-right: 50px;
text-align: center;
}
.clearcircle {
width: 225px;
height:225px;
border-radius: 100%;
background-color: transparent;
border: 5px solid #ffffff;
transition: all .2s ease-in-out;
}
.clearcircle:hover {
border: 5px solid #c0392b;
}
.circle {
width: 200px;
height:200px;
border: 12px solid #ffffff;
border-radius: 100%;
background-color: #e74c3c;
overflow: hidden;
transition: all .2s ease-in-out;
}
.circle p {
position:relative;
text-align: center;
color: white;
transition: all .3s;
}
.circle:hover{
background-color: #e97468;
}
Incidentally, putting a div or a p in your a tag breaks the tag for validated XHTML. You may want to use a div instead, with an "on click" action added that causes it to behave as a link.
Debounce jitter by margin: 0 -12%; if adding padding padding: 0 12%;
menu li a:hover {
margin: 0 -12%;
padding: 0 12%;
color: #fff;
background: #ff5a5f;
display: inline-block;
}