I am trying to add an expandable search box to a row of items. I'm using the example here as the core of this. Here is my jsfiddle. I tried to simulate the problem by limiting the widths. All of the style statements are just for formatting it here. The main problem is that I want to give the search div just enough room to display a search icon. And then, when it's moused over, it should expand to allow input. As you can see, it expands but in the wrong direction.
The original code had "float: right !important;" instead of the "position:fixed !important; z-index:100;" I changed it to. I did that thinking I could control the placement. And it worked, sort of. But the result isn't what I want.
In short, the code as provided by the source site works correctly but only when the search icon is on a line by itself. Can it be placed on a line with other elements and still expand as needed?
Here's the code I am using:
<style>
.search-form .form-group {
position:fixed !important;
z-insex:100;
transition: all 0.35s, border-radius 0s;
width: 32px;
height: 32px;
background-color: #fff;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
border-radius: 25px;
border: 1px solid #ccc;
}
.search-form .form-group input.form-control {
padding-right: 20px;
border: 0 none;
background: transparent;
box-shadow: none;
display:block;
}
.search-form .form-group input.form-control::-webkit-input-placeholder {
display: none;
}
.search-form .form-group input.form-control:-moz-placeholder {
/* Firefox 18- */
display: none;
}
.search-form .form-group input.form-control::-moz-placeholder {
/* Firefox 19+ */
display: none;
}
.search-form .form-group input.form-control:-ms-input-placeholder {
display: none;
}
.search-form .form-group:hover,
.search-form .form-group.hover {
width: 100%;
border-radius: 4px 25px 25px 4px;
}
.search-form .form-group span.form-control-feedback {
position: absolute;
top: -1px;
right: -2px;
z-index: 2;
display: block;
width: 34px;
height: 34px;
line-height: 34px;
text-align: center;
color: #3596e0;
left: initial;
font-size: 14px;
}
</style>
<div style="width:250px;border:1px solid">
<div style="display:inline-block;width:100px;border:1px solid;"><img src="example.com/test.png" width="100"></div>
<div style="display:inline-block;width:80px;border:1px solid;vertical-align:top;">A block of text</div>
<div class="search" style="display:inline-block;vertical-align:top;">
<div class="searchbox-margin">
<form action="" class="search-form">
<div class="form-group has-feedback">
<label for="search" class="sr-only">Search</label>
<input type="text" class="form-control" name="keywords" id="search" placeholder="Search">
<span class="glyphicon glyphicon-search form-control-feedback"></span>
</div>
</form>
</div>
</div>
</div>
Try the following code.
.search-form .form-group input.form-control::-webkit-input-placeholder {
display: none;
}
.search-form .form-group input.form-control:-moz-placeholder {
/* Firefox 18- */
display: none;
}
.search-form .form-group input.form-control::-moz-placeholder {
/* Firefox 19+ */
display: none;
}
.search-form .form-group input.form-control:-ms-input-placeholder {
display: none;
}
.search-form .form-group:hover,
.search-form .form-group.hover {
width: 50%;
border-radius: 4px 25px 25px 4px;
/*transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;*/
}
.search-form .form-group span.form-control-feedback {
position: absolute;
top: -1px;
right: -2px;
z-index: 2;
display: block;
width: 34px;
height: 34px;
line-height: 34px;
text-align: center;
color: #3596e0;
left: initial;
font-size: 14px;
}
.search-form .form-group input.form-control {
border: 0 none;
box-shadow: none;
display: block;
height: 27px;
margin-top: 2px;
width: 87%;
padding-right: 20px;
background: transparent;
}
.search-form .form-group {
position: fixed !important;
z-index: 100;
transition: all 0.35s, border-radius 0s;
width: 48px;
height: 32px;
background-color: #fff;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
border-radius: 25px;
border: 1px solid #ccc;
margin-top:2px;
}
<div style="width:250px;border:1px solid">
<div style="display:inline-block;width:100px;border:1px solid;"><img src="example.com/test.png" width="100"></div>
<div style="display:inline-block;width:80px;border:1px solid;vertical-align:top;">A block of text</div>
<div class="search" style="display:inline-block;vertical-align:top;">
<div class="searchbox-margin">
<form action="" class="search-form">
<div class="form-group has-feedback">
<input type="text" class="form-control" name="keywords" id="search" placeholder="Search">
<span class="glyphicon glyphicon-search form-control-feedback"></span>
</div>
</form>
</div>
</div>
</div>
Related
As you can see below, I have a working tabular div (the gray background is just to show the elements of the tabbed area like the border radius. The key here is I want each 'tab' to actually look more tabular which would consist of a top border and then a right border that extends under the rightmost or leftmost tab like this:
The issue is that when I edit the tabs (currently they have a navy background when active but I want to make the navy be the top and right borders and everything else be white)
What am I doing wrong here and why can't my changes affect the whole tab (lilke the border radius part above the title)? Also, this has to be all CSS and that's why I've gone about it this way so far
/*TABBED SIDEBAR*/
.sidebar-tabs {
max-width: 700px;
margin: 32px auto;
padding: 32px;
background: transparent;
}
.sidebar-tabs-div{
border-radius: 8px 8px 0 0;
}
.tabbed-sb {
overflow-x: hidden; /* so we could easily hide the radio inputs */
/*margin: 32px 0;*/
/*padding-bottom: 16px;*/
background: transparent;
border-radius: 8px 8px 0 0;
}
.tabbed-sb [type="radio"] {
/* hiding the inputs */
display: none;
}
.sidebar-tab-list{
height: 40px;
}
.sidebar-tabs {
border-radius: 8px 8px;
margin-top: 0px !important;
display: flex;
align-items: stretch;
list-style: none;
padding: 0;
/*margin-bottom: 15px;*/
border-bottom: 1px solid #fff;
background: #fff;
}
.tab{
margin-top: -15px;
font-weight: 400;
font-size: 18px;
padding-top: 0px !important;
padding-bottom: 0px !important;
}
.tab > label {
display: block;
margin-bottom: -1px;
padding: 12px 15px;
background: #082552;
color: #bbb;
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
cursor: pointer;
transition: all 0.3s;
}
.tab:hover label {
border-top-color: #333 !important;
color: #eee !important;
}
.sidebar-tab-content {
display: none;
color: #777;
.block{
.block-container{
.block-minorHeader{
display: none;
}
}
}
}
/* As we cannot replace the numbers with variables or calls to element properties, the number of this selector parts is our tab count limit */
.tabbed-sb [type="radio"]:nth-of-type(1):checked ~ .sidebar-tabs .tab:nth-of-type(1) label,
.tabbed-sb [type="radio"]:nth-of-type(2):checked ~ .sidebar-tabs .tab:nth-of-type(2) label,
.tabbed-sb [type="radio"]:nth-of-type(3):checked ~ .sidebar-tabs .tab:nth-of-type(3) label,
.tabbed-sb [type="radio"]:nth-of-type(4):checked ~ .sidebar-tabs .tab:nth-of-type(4) label,
.tabbed-sb [type="radio"]:nth-of-type(5):checked ~ .sidebar-tabs .tab:nth-of-type(5) label {
border-bottom: 2px solid white;
background: #082552;
color: #fff;
}
.tabbed-sb [type="radio"]:nth-of-type(1):checked ~ .sidebar-tab-content:nth-of-type(1),
.tabbed-sb [type="radio"]:nth-of-type(2):checked ~ .sidebar-tab-content:nth-of-type(2),
.tabbed-sb [type="radio"]:nth-of-type(3):checked ~ .sidebar-tab-content:nth-of-type(3),
.tabbed-sb [type="radio"]:nth-of-type(4):checked ~ .sidebar-tab-content:nth-of-type(4) {
display: block;
}
<div style="background-color:gray; padding:20px;">
<!--This is a tabular div for latest threads and posts-->
<div class="sidebar-tabs sidebar-tabs-div">
<div class="tabbed-sb">
<input type="radio" id="tab1" name="css-tabs" checked>
<input type="radio" id="tab2" name="css-tabs">
<ul class="sidebar-tabs sidebar-tab-list">
<li class="tab block-minorHeader"><h3><label for="tab1">Recent Threads</label></h3></li>
<li class="tab block-minorHeader"><h3><label for="tab2">Latest Posts</label></h3></li>
</ul>
<div class="sidebar-tab-content">
Pane One
</div>
<div class="sidebar-tab-content">
Pane Two
</div>
</div>
</div>
</div>
I tried recreating the image best I could. Your styling was all over the place, so I simplified as much as I could.
This could be much better accomplished with vanilla javascript, let me know if you would want to see that, I could post in another answer.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.tabbar {
height: 40px;
display: flex;
align-items: center;
background-color: rgb(255, 255, 255);
}
input[type="radio"]{
display: none;
}
.tab {
cursor: pointer;
box-sizing: border-box;
height: 100%;
padding-left: 10px;
padding-right: 10px;
display: flex;
flex-direction: column;
justify-content: center;
background-color: rgb(255, 255, 255);
border-top: 2px solid rgb(211, 211, 211);
border-bottom-right-radius: 2px;
border-bottom-left-radius: 2px;
box-shadow: inset 0px -5px 8px -6px rgba(0,0,0,0.5);
}
.pane {
display: none;
position: absolute;
top: 40px;
left: 0;
}
.pane .content {
padding: .5rem;
}
.tabbar input[type="radio"]:checked + label{
border-top: 2px solid rgb(77, 216, 58);
border-bottom-right-radius: 0;
background-color: rgb(255, 255, 255);
box-shadow: none;
}
.tabbar input[type="radio"]:checked + label + .pane{
display: flex;
}
<div class="tabbar">
<input type="radio" id="tab1" name="tabs" checked>
<label class="tab" for="tab1">
Recent Threads
</label>
<div class="pane">
<div class="content">
Pane One
</div>
</div>
<input type="radio" id="tab2" name="tabs">
<label class="tab" for="tab2">
Latest Posts
</label>
<div class="pane">
<div class="content">
Pane Two
</div>
</div>
</div>
I've only been doing HTML and CSS for a total of one month. I'm currently trying to replicate a Google search bar, but the problem is that I can't seem to fit the search icon and the voice icon inside the search bar. I've read that you're supposed to put the search bar's position as relative and the icons' as absolute, but I've apparently screwed up the code somewhere and can't figure it out. Thank you <3
My code (HTML and CSS):
input {
color: rgba(0,0,0,.87);
width: 600px;
padding: 15px;
border-radius: 50px;
border: 1px solid #dcdcdc;
outline-color: none;
cursor: text;
background-color: transparent;
z-index: -1;
}
input:focus {
outline: none;
}
input:hover {
box-shadow: 1px 1px 8px 1px #dcdcdc;
}
.voice {
height:20px;
top: 5px;
left: 10px;
position: absolute;
margin-right: 30px;
}
.search-icon {
color: rgb(154, 160, 166);
position: absolute;
z-index: 0;
}
.wrapper {
position: relative;
}
<form id="search-form">
<div class="wrapper">
<img class="search-icon" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDU2Ljk2NiA1Ni45NjYiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDU2Ljk2NiA1Ni45NjY7IiB4bWw6c3BhY2U9InByZXNlcnZlIiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4Ij4KPHBhdGggZD0iTTU1LjE0Niw1MS44ODdMNDEuNTg4LDM3Ljc4NmMzLjQ4Ni00LjE0NCw1LjM5Ni05LjM1OCw1LjM5Ni0xNC43ODZjMC0xMi42ODItMTAuMzE4LTIzLTIzLTIzcy0yMywxMC4zMTgtMjMsMjMgIHMxMC4zMTgsMjMsMjMsMjNjNC43NjEsMCw5LjI5OC0xLjQzNiwxMy4xNzctNC4xNjJsMTMuNjYxLDE0LjIwOGMwLjU3MSwwLjU5MywxLjMzOSwwLjkyLDIuMTYyLDAuOTIgIGMwLjc3OSwwLDEuNTE4LTAuMjk3LDIuMDc5LTAuODM3QzU2LjI1NSw1NC45ODIsNTYuMjkzLDUzLjA4LDU1LjE0Niw1MS44ODd6IE0yMy45ODQsNmM5LjM3NCwwLDE3LDcuNjI2LDE3LDE3cy03LjYyNiwxNy0xNywxNyAgcy0xNy03LjYyNi0xNy0xN1MxNC42MSw2LDIzLjk4NCw2eiIgZmlsbD0iIzAwMDAwMCIvPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K" />
<input class="search" type="text">
<img class="voice" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/Google_mic.svg/716px-Google_mic.svg.png" title="Search by Voice">
</div>
</form>
So what you need to do is that it's not the text field that has the rounded corners and shadows, with the icons on top, but it's the wrapper that needs to have the rounded corners and borders and every, then the three elements all go inside of it.
so what I did is that I took your styles for the input, and moved it too the wrapper, then make the border:none, so the input is basically invisible.
then I removed all of your position styles because they aren't needed, so now we are basically done, except the elements are slightly off center, and the input doesn't fill the whole width.
I just decided to use display:flex on the wrapper, with flex-direction:row to make all of it horizontal, with align-items: center to center everything. I also added flex-grow:1 to the input so it fills the entire width.
input {
color: rgba(0,0,0,.87);
outline-color: none;
background-color: transparent;
border:none;
height:100%;
flex-grow:1;
font-size: 15px;
}
input:focus {
outline: none;
}
.voice {
height:20px;
margin: 0px 5px;
}
.search-icon {
color: rgb(154, 160, 166);
margin: 0px 5px;
}
.wrapper {
width: 600px;
height: 30px;
padding: 2px;
border-radius: 50px;
border: 1px solid #dcdcdc;
outline-color: none;
cursor: text;
background-color: transparent;
display:flex;
flex-direction: row;
align-items: center;
}
.wrapper:hover{
box-shadow: 1px 1px 8px 1px #dcdcdc;
}
<form id="search-form">
<div class="wrapper">
<img class="search-icon" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDU2Ljk2NiA1Ni45NjYiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDU2Ljk2NiA1Ni45NjY7IiB4bWw6c3BhY2U9InByZXNlcnZlIiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4Ij4KPHBhdGggZD0iTTU1LjE0Niw1MS44ODdMNDEuNTg4LDM3Ljc4NmMzLjQ4Ni00LjE0NCw1LjM5Ni05LjM1OCw1LjM5Ni0xNC43ODZjMC0xMi42ODItMTAuMzE4LTIzLTIzLTIzcy0yMywxMC4zMTgtMjMsMjMgIHMxMC4zMTgsMjMsMjMsMjNjNC43NjEsMCw5LjI5OC0xLjQzNiwxMy4xNzctNC4xNjJsMTMuNjYxLDE0LjIwOGMwLjU3MSwwLjU5MywxLjMzOSwwLjkyLDIuMTYyLDAuOTIgIGMwLjc3OSwwLDEuNTE4LTAuMjk3LDIuMDc5LTAuODM3QzU2LjI1NSw1NC45ODIsNTYuMjkzLDUzLjA4LDU1LjE0Niw1MS44ODd6IE0yMy45ODQsNmM5LjM3NCwwLDE3LDcuNjI2LDE3LDE3cy03LjYyNiwxNy0xNywxNyAgcy0xNy03LjYyNi0xNy0xN1MxNC42MSw2LDIzLjk4NCw2eiIgZmlsbD0iIzAwMDAwMCIvPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K" />
<input class="search" type="text">
<img class="voice" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/Google_mic.svg/716px-Google_mic.svg.png" title="Search by Voice">
</div>
</form>
I also changed some padding and stuff slightly to make it work better but I guess that's optional
input {
font-size:20px;
width: 88%;
border:none;
margin-left:60px;
height:30px;
padding:0;
}
input:focus {
outline: none;
}
.wrapper:hover {
box-shadow: 1px 1px 8px 1px #dcdcdc;
}
.voice {
height:20px;
top: 10px;
left: 40px;
position: absolute;
margin-right: 30px;
}
.search-icon {
color: rgb(154, 160, 166);
position: absolute;
z-index: 0;
left: 15px;
top: 10px;
cursor:default;
}
.wrapper {
position: relative;
color: rgba(0,0,0,.87);
width: 600px;
padding:5px;
border-radius: 50px;
border: 1px solid #dcdcdc;
outline-color: none;
cursor: text;
background-color: transparent;
}
<form id="search-form">
<div class="wrapper">
<img class="search-icon" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDU2Ljk2NiA1Ni45NjYiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDU2Ljk2NiA1Ni45NjY7IiB4bWw6c3BhY2U9InByZXNlcnZlIiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4Ij4KPHBhdGggZD0iTTU1LjE0Niw1MS44ODdMNDEuNTg4LDM3Ljc4NmMzLjQ4Ni00LjE0NCw1LjM5Ni05LjM1OCw1LjM5Ni0xNC43ODZjMC0xMi42ODItMTAuMzE4LTIzLTIzLTIzcy0yMywxMC4zMTgtMjMsMjMgIHMxMC4zMTgsMjMsMjMsMjNjNC43NjEsMCw5LjI5OC0xLjQzNiwxMy4xNzctNC4xNjJsMTMuNjYxLDE0LjIwOGMwLjU3MSwwLjU5MywxLjMzOSwwLjkyLDIuMTYyLDAuOTIgIGMwLjc3OSwwLDEuNTE4LTAuMjk3LDIuMDc5LTAuODM3QzU2LjI1NSw1NC45ODIsNTYuMjkzLDUzLjA4LDU1LjE0Niw1MS44ODd6IE0yMy45ODQsNmM5LjM3NCwwLDE3LDcuNjI2LDE3LDE3cy03LjYyNiwxNy0xNywxNyAgcy0xNy03LjYyNi0xNy0xN1MxNC42MSw2LDIzLjk4NCw2eiIgZmlsbD0iIzAwMDAwMCIvPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K" />
<input class="search" type="text">
<img class="voice" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/Google_mic.svg/716px-Google_mic.svg.png" title="Search by Voice">
</div>
</form>
input {
color: rgba(0,0,0,.87);
width: 600px;
padding: 15px;
border-radius: 50px;
border: 1px solid #dcdcdc;
outline-color: none;
cursor: text;
background-color: transparent;
}
input:focus {
outline: none;
}
input:hover {
box-shadow: 1px 1px 8px 1px #dcdcdc;
}
.voice {
height:20px;
top: 10;
right: 40;
position: absolute;
margin-right: 30px;
}
.search-icon {
color: rgb(154, 160, 166);
position: absolute;
right:20;
top:10;
}
.wrapper {
width:600px;
position: relative;
}
<form id="search-form">
<div class="wrapper">
<img class="search-icon" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDU2Ljk2NiA1Ni45NjYiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDU2Ljk2NiA1Ni45NjY7IiB4bWw6c3BhY2U9InByZXNlcnZlIiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4Ij4KPHBhdGggZD0iTTU1LjE0Niw1MS44ODdMNDEuNTg4LDM3Ljc4NmMzLjQ4Ni00LjE0NCw1LjM5Ni05LjM1OCw1LjM5Ni0xNC43ODZjMC0xMi42ODItMTAuMzE4LTIzLTIzLTIzcy0yMywxMC4zMTgtMjMsMjMgIHMxMC4zMTgsMjMsMjMsMjNjNC43NjEsMCw5LjI5OC0xLjQzNiwxMy4xNzctNC4xNjJsMTMuNjYxLDE0LjIwOGMwLjU3MSwwLjU5MywxLjMzOSwwLjkyLDIuMTYyLDAuOTIgIGMwLjc3OSwwLDEuNTE4LTAuMjk3LDIuMDc5LTAuODM3QzU2LjI1NSw1NC45ODIsNTYuMjkzLDUzLjA4LDU1LjE0Niw1MS44ODd6IE0yMy45ODQsNmM5LjM3NCwwLDE3LDcuNjI2LDE3LDE3cy03LjYyNiwxNy0xNywxNyAgcy0xNy03LjYyNi0xNy0xN1MxNC42MSw2LDIzLjk4NCw2eiIgZmlsbD0iIzAwMDAwMCIvPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K" />
<input class="search" type="text">
<img class="voice" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/Google_mic.svg/716px-Google_mic.svg.png" title="Search by Voice">
</div>
</form>
I have an image and some text that both work as a checkbox. However when I try to align them horizontally it does not work with me.
I've tried using dividers but when I do I can't include the text part into a button.
CSS Folder:
.hidden {
display: none;
}
.registerCheckbox {
padding: 10px;
display: block;
position: relative;
margin: 10px;
cursor: pointer;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
border-width: 1px;
border-color: #ddd;
border: 1px solid rgb(212, 212, 212);
box-shadow: 7px 7px 2px -3px rgb(212, 212, 212);
border-radius: 25px;
transition: 0.2s;
}
.registerCheckbox::before {
background-color: white;
color: white;
content: " ";
display: block;
border-radius: 50%;
border: 1px solid grey;
position: absolute;
top: -5px;
left: -5px;
width: 25px;
height: 25px;
text-align: center;
line-height: 28px;
transition-duration: 0.4s;
transform: scale(0);
}
.registerCheckbox img {
height: 100px;
width: 100px;
transition-duration: 0.2s;
transform-origin: 50% 50%;
}
:checked+.registerCheckbox {
border-radius: 25px;
border: 5px solid #5BDEBE;
transition: 0.2s;
}
:checked+.registerCheckbox::before {
border-color: #ddd;
border: 1px solid grey;
}
JS Folder:
<link rel="stylesheet" type="text/css" href={require('../static/css/planCheckbox.css')} />
<input type="checkbox" id="google" value={this.state.google} checked={this.state.google} onChange={() => { this.setState({ google: !this.state.google }) }} />
<label class="registerCheckbox" htmlFor="google-ads"><img alt="Google ads" src={require('../static/img/register/google.png')} /> <br></br>
<b>{this.props.t('TEST')}</b>:<br />{this.props.t('This doesnt work!')}.</label>
What I get (top) and what I want (bottom)
Any help is highly appreciated!
I left out some HTML attributes that doesn't really make it easy to understand what is happening in this demo-code. I also needed to make a new container around your text elements.
Hopefully this demo gives you a headstart to figure out how you want to build it.
I tried to leave your original styling for what it is.
To better understand the changes I placed them inside an extra class called "flex".
.hidden {
display: none;
}
.registerCheckbox {
padding: 10px;
display: block;
position: relative;
margin: 10px;
cursor: pointer;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
border-width: 1px;
border-color: #ddd;
border: 1px solid rgb(212, 212, 212);
box-shadow: 7px 7px 2px -3px rgb(212, 212, 212);
border-radius: 25px;
transition: 0.2s;
}
/* Flexbox solution */
.flex.registerCheckbox {
display: flex;
}
.flex.registerCheckbox .text-container {
display: flex;
flex-direction: column;
padding: 0 10px 10px;
}
.registerCheckbox::before {
background-color: white;
color: white;
content: " ";
display: block;
border-radius: 50%;
border: 1px solid grey;
position: absolute;
top: -5px;
left: -5px;
width: 25px;
height: 25px;
text-align: center;
line-height: 28px;
transition-duration: 0.4s;
transform: scale(0);
}
.registerCheckbox img {
height: 100px;
width: 100px;
transition-duration: 0.2s;
transform-origin: 50% 50%;
}
input:checked + .registerCheckbox {
border-radius: 25px;
border: 5px solid #5BDEBE;
transition: 0.2s;
}
input:checked + .registerCheckbox::before {
content: "";
border-color: #ddd;
border: 1px solid grey;
}
<input type="checkbox" id="google-1" class="hidden" />
<label for="google-1" class="flex registerCheckbox">
<img alt="Google ads" src="https://placehold.it/400x400" />
<div class="text-container">
<strong>Test</strong>
<span>This doesn't work.</span>
</div>
</label>
<input type="checkbox" id="google-2" class="hidden" />
<label for="google-2" class="flex registerCheckbox">
<img alt="Google ads" src="https://placehold.it/400x400" />
<div class="text-container">
<strong>Test</strong>
<span>This doesn't work.</span>
</div>
</label>
You could use the following code:
Display: flex;
on the parent div. This should put everything next to each other.
add parent div to your checkbox and label and set display:flex; to that parent class.
here is the updated code:
.checkboxdiv {
display: flex;
}
<div class="checkboxdiv">
<input type="checkbox" id="google" value={this.state.google} checked={this.state.google} onChange={()=> { this.setState({ google: !this.state.google }) }} />
<label class="registerCheckbox" htmlFor="google-ads"><img alt="Google ads" src={require('../static/img/register/google.png')} /> <br></br>
<b>{this.props.t('TEST')}</b>:<br />{this.props.t('This doesnt work!')}.</label>
</div>
What i am doing is that in search box when user enter a search term, i display a close button ('x' character to be specific, embedded as content after reset button) to clear the contents of search box.
It works fine in both Chrome and IE but not in firefox.
Any kind of help would be highly appreciated.
.search-box,.close-icon,.search-wrapper {
position: relative;
padding: 10px;
}
.search-wrapper {
width: 500px;
margin: auto;
margin-top: 50px;
}
.search-box:focus {
box-shadow: 0 0 15px 5px #b0e0ee;
border: 2px solid #bebede;
}
.close-icon {
border:1px solid transparent;
background-color: transparent;
display: inline-block;
vertical-align: middle;
outline: 0;
cursor: pointer;
}
.close-icon:after {
content: "X";
display: block;
width: 15px;
height: 15px;
position: absolute;
z-index:1;
right: 35px;
top: 0;
bottom: 0;
margin: auto;
padding: 2px;
border-radius: 50%;
text-align: center;
color: black;
font-weight: normal;
font-size: 12px;
cursor: pointer;
}
.search-box:not(:valid) ~ .close-icon {
display: none;
}
<div class="search-wrapper">
<form>
<input type="text" name="focus" required class="search-box" placeholder="Enter search term" />
<button class="close-icon" type="reset"></button>
</form>
</div>
This code should help you
.search-box,.search-wrapper {
position: relative;
padding: 10px;
}
.search-wrapper {
width: 500px;
margin: auto;
margin-top: 50px;
}
.search-box
{
width:300px;
}
.search-box:focus {
box-shadow: 0 0 15px 5px #b0e0ee;
border: 2px solid #bebede;
}
.close-icon {
border:1px solid transparent;
background-color: transparent,
display: inline-block;
vertical-align: middle;
outline: 0;
position: absolute;
top:19px;
left:305px;
z-index:1;
padding: 1px 2px;
border-radius: 50%;
text-align: center;
color: black;
font-weight: normal;
font-size: 12px;
cursor: pointer;
}
.search-box:not(:valid) ~ .close-icon {
display: none;
}
<div class="search-wrapper">
<form>
<input type="text" name="focus" required class="search-box" placeholder="Enter search term" />
<button class="close-icon" type="reset">X</button>
</form>
</div>
NOTE : set your .search-box width and according to it set left of your .close-icon
Try this code: Hope this solve your problem. Adjust "outer_box" class for width.
<style>
.search-box, .search-wrapper {
padding: 10px;
box-sizing: border-box;
}
.search-box {
position:relative;
width:100%;
}
.outer_boxs{
position:relative;
width:60%;
}
.search-wrapper {
width: 500px;
margin: auto;
margin-top: 50px;
}
.search-box:focus {
box-shadow: 0 0 15px 5px #b0e0ee;
border: 2px solid #bebede;
}
.close-icon {
border:1px solid transparent;
background-color: transparent,
display: inline-block;
vertical-align: middle;
outline: 0;
cursor: pointer;
position: absolute;
right:5px;
top: 10px;
background:#f2f2f2;
}
.search-box:not(:valid) ~ .close-icon {
display: none;
}
</style>
<div class="search-wrapper">
<form>
<div class="outer_boxs" >
<input type="text" name="focus" required class="search-box" placeholder="Enter search term" />
<button class="close-icon" type="reset">X</button>
</div>
</form>
</div>
Currently I developing a registration form ... And I wish to include step by step for the user ... Code at the bottom I get from other site and I already modified some css ... however the element are showing in vertical ... What I need is horizontal ... I tried to position but it doesn't work ...
Currently Display
What I need
In HTML
<div class="steps">
<div id='genger' name='genger'/><label >Step 1</label></div>
<div id='genger' name='genger'/><label>Step 2</label></div>
<div id='genger' name='genger'/><label >Step 3</label></div>
<div id='genger' name='genger'/><label>Step 4</label></div>
<div id='genger' name='genger'/><label >Step 5</label></div>
</div>
In CSS
.steps{
width: 200px;
display:inline-block;
position: relative;
padding: 1em 2em 1em 3em;
vertical-align: top;
}
label{
background: #393D40;
height: 69px;
line-height: 69px;
width: 100%;
display: block;
border-bottom: 1px solid #44494e;
color: #889199;
text-transform: uppercase;
font-weight: 900;
font-size: 11px;
letter-spacing: 1px;
text-indent: 52px;
cursor: pointer;
transition: all 0.3s ease
}
label:before{
content:"";
width: 12px;
height: 12px;
border: 2px solid #25292e;
display: block;
position: absolute;
margin: 26px 0px 0px 18px;
border-radius: 100%;
transition: border 0.7s ease
}
label[for=genger]{
border-radius: 3px 3px 0px 0px;
}
label:hover{
background: #2B2E30;
color: #46b7e5
}
label:hover:before{
border: 2px solid #46b7e5;
}
Click for JSFiddle
Demo on Fiddle
HTML:
<div class="steps">
<div class='genger'>
<label>Step 1</label>
</div>
<div class='genger'>
<label>Step 2</label>
</div>
<div class='genger'>
<label>Step 3</label>
</div>
<div class='genger'>
<label>Step 4</label>
</div>
<div class='genger'>
<label>Step 5</label>
</div>
</div>
CSS:
.genger {
display: inline-block;
vertical-align: top;
margin: -1px;
}
.steps {
width: 100%;
display:inline-block;
position: relative;
vertical-align: top;
}
label {
background: #393D40;
height: 69px;
line-height: 69px;
width: 150px;
display: block;
border-bottom: 1px solid #44494e;
color: #889199;
text-transform: uppercase;
font-weight: 900;
font-size: 11px;
letter-spacing: 1px;
text-indent: 52px;
cursor: pointer;
transition: all 0.3s ease
}
label:before {
content:"";
width: 12px;
height: 12px;
border: 2px solid #25292e;
display: block;
position: absolute;
margin: 26px 0px 0px 18px;
border-radius: 100%;
transition: border 0.7s ease
}
label:hover {
background: #2B2E30;
color: #46b7e5
}
label:hover:before {
border: 2px solid #46b7e5;
}
First i have taken out your .steps width just removed the padding
you had also given your genger div codes as
<div id='genger' name='genger'/><label >Step 1</label></div>
you have closed the div before the label had started, I changed it to,
<div class='genger' name='genger'><label >Step 1</label></div>
also named your id genger to class
hence here is the final code...
#wrapper{
width:1200px;
margin:0 auto
}
.steps{
display:inline-block;
position: relative;
/*padding: 1em 2em;*/
vertical-align: top;
background:red;
width:100%;
}
.genger{
width:20%;
min-width:150px;
float:left;
}
label{
background: #393D40;
height: 69px;
line-height: 69px;
width: 100%;
display: block;
border-bottom: 1px solid #44494e;
color: #889199;
text-transform: uppercase;
font-weight: 900;
font-size: 11px;
letter-spacing: 1px;
text-indent: 52px;
cursor: pointer;
transition: all 0.3s ease
}
label:before{
content:"";
width: 12px;
height: 12px;
border: 2px solid #25292e;
display: block;
position: absolute;
margin: 26px 0px 0px 18px;
border-radius: 100%;
transition: border 0.7s ease
}
label[for=genger]{
border-radius: 3px 3px 0px 0px;
}
label:hover{
background: #2B2E30;
color: #46b7e5
}
label:hover:before{
border: 2px solid #46b7e5;
}
<div id="wrapper">
<div class="steps">
<div class='genger' name='genger'><label >Step 1</label></div>
<div class='genger' name='genger'><label>Step 2</label></div>
<div class='genger' name='genger'><label >Step 3</label></div>
<div class='genger' name='genger'><label>Step 4</label></div>
<div class='genger' name='genger'><label >Step 5</label></div>
</div>
<div>
Hope this helps.
P.S : you can center this menu as well . just wrap it inside a bigger div and give margin: 0 auto
EDIT:: If you want to be more flexible in your widths, you can add width:100% in the steps class and width 20% in genger class. See updated code snippet now
DEMO
check the demo, i have added in css
.steps {
width: 100%;
margin: 20px;
vertical-align: top;
}
.genger {float: left;width: 150px; }