How to make Search bar slide from right to left - css

This search bar now expands from left to right while hover or click. How to modify it, so it expands from right to left. CSS Only, no JS. I want to place this on the right side of the page.
Please help in modifing this code so it expands from the right to left.
Now, when the bar is sticky to the right side, it shakes a bit while expanding. Changing expand direction will remove shake effect.
.search-sticky {
position: sticky;
top: 30px;
left: 100%;
z-index: 55;
border-radius: 50px;
background-color: red;
padding: 2.5rem;
}
.search-icon {
position: relative;
width: 24px;
height: 24px;
flex-shrink: 0;
top: 3px
}
.search-input {
outline: none;
border: none;
background: none;
width: 0;
padding: 0;
color: white;
float: left;
transition: .3s;
line-height: 1.5;
font-size: 6rem;
position: relative;
left: 1rem;
}
.search-btn {
float: right;
width: 40px;
height: 40px;
border-radius: 50px;
display: flex;
justify-content: center;
align-items: center;
text-decoration: none;
transition: .3s;
}
.search-input:focus,
.search-input:not(:placeholder-shown) {
width: 200px;
}
.search-box:hover>.search-input {
width: 200px;
}
.search-box:hover>.search-btn,
.search-input:focus+.search-btn,
.search-input:not(:placeholder-shown)+.search-btn {
background: grey;
}
.search-sticky:hover,
.search-sticky:focus-within {
background-color: grey;
}
.search-sticky button {
padding: 0;
background: none;
border: none;
border-radius: 0;
outline: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
cursor: pointer;
}
<div class="search-sticky">
<form class="search-box">
<input type="text" name="q" id="search-query" class="search-input" placeholder="Search ....">
<a class="search-btn" href="#">
<button type="submit" class="search-button"><img class="search-icon" alt="Search" src="/icons/search.svg" /></button>
</a>
</form>
</div>

Updated
I hope this helps
.search-sticky {
position: sticky;
top: 30px;
left: 100%;
z-index: 55;
border-radius: 50px;
background-color: whitesmoke;
padding: 0.5rem 2.5rem;
}
.search-box{
display: flex;
justify-content: space-between;
align-items: center;
}
.search-icon {
position: relative;
width: 40px;
height: 40px;
margin-left: auto;
}
.search-input {
outline: none;
border: none;
background: none;
width: 0;
padding: 0;
color: white;
transition: .3s;
line-height: 1.5;
font-size: 4rem;
position: relative;
display: inline-block;
}
.search-btn {
width: 40px;
height: 40px;
border-radius: var(--br-md);
display: inline-block;
justify-content: center;
align-items: center;
text-decoration: none;
transition: .3s;
}
.search-input:focus,
.search-input:not(:placeholder-shown) {
width: calc(100% - 60px);
}
.search-box:hover>.search-input {
width: calc(100% - 60px);
}
/*.search-box:hover>.search-btn,
.search-input:focus+.search-btn,
.search-input:not(:placeholder-shown)+.search-btn {
background: grey;
}
// not needed */
.search-sticky:hover,
.search-sticky:focus-within {
background-color: lightgray;
}
.search-sticky button {
padding: 0;
background: none;
border: none;
border-radius: 0;
outline: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
cursor: pointer;
}
<div class="search-sticky">
<form class="search-box">
<input type="text" name="q" id="search-query" class="search-input" placeholder="Search ....">
<a class="search-btn" href="#">
<button type="submit" class="search-button"><img class="search-icon" alt="Search" src="https://img.icons8.com/ios-filled/2x/search.png" /></button>
</a>
</form>
</div>

Related

Is there a way to edit the inside color of a color input selector?

I want to change the inside color of a css so that it looks like this:
How i want it to look
How it looks so far:
Color i want to change
I've tried many things so that it looks like that, here is my html:
<div className="forms__highlightcolor">
<p>Highlight Color</p>
<input type="color" id="colorpicker" value="#0000ff"></input>
</div>
And the CSS i've made so far:
.forms__highlightcolor > input{
background: #F1F1F1;
width: 250px;
height: 35px;
border: 1px solid #F1F1F1;
border-radius: 20px;
}
.forms__highlightcolor > input[type="color"]::-webkit-color-swatch {
border: none;
width: 0px;
border-radius: 4px;
}
I want to change the inside color, but don't know how to do it.
Here is my code I hope this may help.
First You need to separate the input section and color has code section and wrap it inside a div.
#colorpicker {
border: 0;
padding: 0;
background: unset;
width: 30px;
height: 35px;
left: -5px;
position: absolute;
}
#colorpicker:hover {
cursor: pointer;
}
.color-input-wrapper {
display: flex;
align-items: center;
position: relative;
border-radius: 57px;
overflow: hidden;
width: 200px;
height: 25px;
position: relative;
background: #fdf8f5;
}
.color-input-wrapper:hover {
cursor: pointer;
}
.hash-code-section {
margin-left: 30px;
display: flex;
align-items: center;
flex:1;
margin-right: 10px;
text-transform: uppercase;
}
.arrow {
border: solid black;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 3px;
margin-left: auto;
}
.down {
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
<div className="forms__highlightcolor">
<p>Highlight Color</p>
<div class="color-input-wrapper"><input type="color" id="colorpicker" value="#FF5733"></input>
<div class="hash-code-section">#FF5733 <i class="arrow down"></i></div>
</div>
</div>

Text input - can't align text top or bottom, only center

folks! I'm trying to align the text inside a text form input to be next to the line at the bottom, but it doesn't quite concede, insisting on being center aligned.
I've put some vertical-align: bottom on different elements, but it didn't work (it's on the code below).
Here is the codepen: https://codepen.io/ironsand-sou-eu/pen/zYEmEdw
HTML:
<div class="form-input field">
<input type="text" name="my_input" id="my_input" value="I'd love to be a little closer to the line below! Can you help me?">
<label for="my_input" data-title="Just some label"></label>
</div>
CSS:
.form-input {
width: 100%;
background-color: transparent;
border-bottom: 1px green solid;
border-top: none;
border-right: none;
border-left: none;
}
.form-input::before {
content: '';
position: absolute;
background-color: green;
left: 0;
bottom: 0;
width: 0;
height: 2px;
transition: ease-out 300ms;
}
.form-input:hover::before {
width: 100%;
}
.form-input:focus-within::before {
width: 100%;
}
.form-input input {
border: none;
width: 100%;
}
.form-input input:focus-visible {
outline: none;
}
.field {
position: relative;
margin-bottom: 15px;
vertical-align: bottom;
}
.field label::before {
content: attr(title);
position: absolute;
top: 0;
left: 15px;
line-height: 40px;
font-size: 14px;
color: #777;
transition: 300ms all;
}
.field input {
width: 100%;
line-height: 40px;
padding: 0 8px;
box-sizing: border-box;
font-size: 14px;
color: green;
vertical-align: bottom;
}
Place this at the bottom of the CSS section:
input[type=text] {
height: 15px;
}

Custom Checkbox without label [duplicate]

This question already has answers here:
What are the various ways to hide a <div>?
(5 answers)
Can I have an onclick effect in CSS?
(14 answers)
Closed 2 years ago.
I have an a element that acts like a toggle button :
var container = document.getElementsByClassName("favorite");
for (var i = 0; i < container.length; i++) {
//For each element in the container array, add an onclick event.
container[i].onclick = function(event) {
this.classList.toggle('selected');
}
}
body {
background-color: #04246A;
}
.container {
position: relative;
width: 204px;
max-width: 204px;
height: 82px;
max-height: 82px;
padding: 24px;
background: #fff;
display: flex;
flex-direction: column;
justify-content: space-between;
box-sizing: border-box;
color: black;
list-style: none;
border: 2px solid black;
}
.container .favorite {
position: absolute;
top: 10px;
right: 10px;
width: 40px;
height: 40px;
display: flex;
border-radius: 50%;
cursor: pointer;
}
.container .favorite:hover {
background: #D9DEEA;
}
.container .favorite::after {
z-index: 2;
position: relative;
margin: auto;
height: 20px;
content: url("https://img.icons8.com/ios/16/000000/star.png");
}
.container .favorite.selected::after {
content: url("https://img.icons8.com/ios-filled/16/000000/star.png");
}
.container dl {
margin: 0;
}
.container dl dt {
display: block;
font-size: 12px;
color: #6B7790;
}
.container dl dd {
margin: 0;
font-weight: normal;
color: #04246A;
}
<div class="container">
<a class="favorite"></a>
<dl>
<dt>Ref</dt>
<dd>XXX123</dd>
</dl>
</div>
I want to transform it to a checkbox, but the solutions I find are for a checkbox with a label, I only want to use the checkbox in my html without the label or some additional div, this is what I tried :
body {
background-color: #04246A;
}
.container {
position: relative;
width: 204px;
max-width: 204px;
height: 82px;
max-height: 82px;
padding: 24px;
background: #fff;
display: flex;
flex-direction: column;
justify-content: space-between;
box-sizing: border-box;
color: black;
list-style: none;
border: 2px solid black;
}
input[type="checkbox"]{
height: 20px;
width: 20px;
position: absolute;
opacity: 1;
margin: auto;
height: 20px;
cursor: pointer;
top: 10px;
right: 10px;
}
input[type="checkbox"]::after{
content: url("https://img.icons8.com/ios/16/000000/star.png");
position: absolute;
top: 0;
left: 0;
border-radius: 50%;
margin: auto;
height: 20px;
width: 20px;
pointer-events: none;
}
input[type="checkbox"]:checked:after {
content: url("https://img.icons8.com/ios-filled/16/000000/star.png");
}
input[type="checkbox"]:hover:after{
background: #D9DEEA;
}
.container dl {
margin: 0;
}
.container dl dt {
display: block;
font-size: 12px;
color: #6B7790;
}
.container dl dd {
margin: 0;
font-weight: normal;
color: #04246A;
}
<div class="container">
<input type="checkbox" />
<dl>
<dt>Ref</dt>
<dd>XXX123</dd>
</dl>
</div>
Which doesn't look good.
How can I fix this ? and thanks in advance.
You can add appearance:none to remove to checkbox appearance and set fixed height/width to checkbox and :after, changing :after to flex allows you to center the background.
body {
background-color: #04246A;
}
.container {
position: relative;
width: 204px;
max-width: 204px;
height: 82px;
max-height: 82px;
padding: 24px;
background: #fff;
display: flex;
flex-direction: column;
justify-content: space-between;
box-sizing: border-box;
color: black;
list-style: none;
border: 2px solid black;
}
input[type="checkbox"]{
height: 40px;
width: 40px;
position: absolute;
opacity: 1;
margin: auto;
cursor: pointer;
top: 10px;
right: 10px;
appearance: none;
outline: none;
}
input[type="checkbox"]::after{
content: url("https://img.icons8.com/ios/16/000000/star.png");
position: absolute;
top: 0;
left: 0;
border-radius: 50%;
margin: auto;
height: 40px;
width: 40px;
pointer-events: none;
display: flex;
justify-content: center;
align-items: center;
}
input[type="checkbox"]:checked:after {
content: url("https://img.icons8.com/ios-filled/16/000000/star.png");
}
input[type="checkbox"]:hover:after{
background: #D9DEEA;
}
.container dl {
margin: 0;
}
.container dl dt {
display: block;
font-size: 12px;
color: #6B7790;
}
.container dl dd {
margin: 0;
font-weight: normal;
color: #04246A;
}
<div class="container">
<input type="checkbox" />
<dl>
<dt>Ref</dt>
<dd>XXX123</dd>
</dl>
</div>

How to transform/transition div without moving the text?

I created an overlay menu for the responsive menu of website. every thing is OK but when the menu will be closed, the texts (in menu) will be gathered and moved individually and then disappear but I want them to slide out without moving texts.
I tried these HTML:
<section class="overlaysection">
<div id="myoverlaynav" class="overlay">
×
<div class="overlay-content">
<li><a>num one one one one</a></li>
<li><a>num two two two two</a></li>
<li><a>num three three three three</a></li>
<li><a>num four four four four four</a></li>
</div>
</div>
<div class="overlaybtndiv" onclick="openNav()">
<button class="overlaybtn">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<h2>The Menu</h2>
</div>
</section>
CSS Codes:
#media (min-width: 631px){
.overlaysection {
display: none;
}
}
.overlaysection .overlay {
height: 100%;
width: 0;
position: fixed;
/* z-index: 1; */
z-index: 999999;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
direction:rtl;
}
.overlaysection a.closebtn {
position: absolute;
font-size: 40px;
padding: 0;
line-height: 40px;
top: 10px;
right: 10px;
color: #eee;
}
.overlaysection .overlay-content {
position: relative;
width: 100%;
text-align: center;
margin-top: 40px;
}
.overlaysection .overlay a {
display: block;
transition: 0.3s;
text-align: left;
color: #eee;
padding: 8px 8px 8px 20px;
text-decoration: none;
}
.overlaysection .overlay a:hover,
.overlaysection .overlay a:focus {
color: #f1f1f1;
}
.overlaysection .overlaybtndiv {
display: block;
padding: 6px 8px;
position: relative;
}
.overlaysection .overlaybtndiv h2 {
font-size: 14px;
color: black;
line-height: 40px;
margin-right: 10px;
}
.overlaysection .overlaybtn {
border-color: transparent !important;
float: right;
padding: 5px;
background: white;
outline: 0;
}
.overlaysection .overlaybtn .icon-bar {
display: block;
height: 2px;
border-radius: 1px;
padding: 1.5px;
width: 28px;
background-color: black !important;
margin-top: 5px;
}
.overlaysection .overlaybtn .icon-bar:first-child {
margin-top: 3px !important;
}
.
javascript codes:
function openNav() {
document.getElementById("myoverlaynav").style.width = "80%";
}
function closeNav() {
document.getElementById("myoverlaynav").style.width = "0%";
}
you can see this menu in https://end-eng.com/grammar/auxiliary-modal-verbs-in-english/ and this menu is like https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_sidenav
Add min-width and float:left to .overlay-content.
.overlaysection .overlay-content {
position: relative;
width: 100%;
text-align: center;
margin-top: 50px;
min-width: 270px;
float: left;
}
right now what happening is when close navbar its width is reduced so thus your li tag width to so, just give your li tag fixed width and your problem will be solved like.
#media (min-width: 631px){
.li {
width : 200px;
}
}
and only give this in media query for smaller devices otherwise it will replicate in whole website.
It's because you're using width's to control the display.
Instead of this, I suggest that you toggle a "shown" class to your overlay.
By default on your ".overlaysection .overlay" css, change the width to 100% and left to -100%;
Then on the "shown" class set the left to 0. Change the JS to toggle the
shown class and it should then slide out from the left without changing the text orientation.
function openNav() {
document.getElementById("myoverlaynav").classList.toggle('shown');
}
function closeNav() {
document.getElementById("myoverlaynav").classList.toggle('shown');
}
#media (min-width: 631px){
.overlaysection {
display: none;
}
}
.overlaysection .overlay {
height: 100%;
width: 100%;
position: fixed;
/* z-index: 1; */
left: -100%;
z-index: 999999;
top: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
direction:rtl;
}
.overlaysection a.closebtn {
position: absolute;
font-size: 40px;
padding: 0;
line-height: 40px;
top: 10px;
right: 10px;
color: #eee;
}
.overlaysection .overlay-content {
position: relative;
width: 100%;
text-align: center;
margin-top: 40px;
}
.overlaysection .overlay a {
display: block;
transition: 0.3s;
text-align: left;
color: #eee;
padding: 8px 8px 8px 20px;
text-decoration: none;
}
.overlaysection .overlay a:hover,
.overlaysection .overlay a:focus {
color: #f1f1f1;
}
.overlaysection .overlaybtndiv {
display: block;
padding: 6px 8px;
position: relative;
}
.overlaysection .overlaybtndiv h2 {
font-size: 14px;
color: black;
line-height: 40px;
margin-right: 10px;
}
.overlaysection .overlaybtn {
border-color: transparent !important;
float: right;
padding: 5px;
background: white;
outline: 0;
}
.overlaysection .overlaybtn .icon-bar {
display: block;
height: 2px;
border-radius: 1px;
padding: 1.5px;
width: 28px;
background-color: black !important;
margin-top: 5px;
}
.overlaysection .overlaybtn .icon-bar:first-child {
margin-top: 3px !important;
}
#myoverlaynav.shown {
left: 0;
}
<section class="overlaysection">
<div id="myoverlaynav" class="overlay">
×
<div class="overlay-content">
<li><a>num one one one one</a></li>
<li><a>num two two two two</a></li>
<li><a>num three three three three</a></li>
<li><a>num four four four four four</a></li>
</div>
</div>
<div class="overlaybtndiv" onclick="openNav()">
<button class="overlaybtn">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<h2>The Menu</h2>
</div>
</section>

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>

Resources