clearable input overwrite label padding - css

Try to make input with close-icon button,<input type=search> but I need more styling so I decided to make it on my own,but the problem is the position of input and label also moved slightly when want to clear input.
form.component.html
<div class="flex-center ">
<input class="input" [(ngModel)]="value">
<button *ngIf="value" class="button-close" (click)="value=''">
</button>
<label class="desc">description</label>
</div>
form.component.css
.flex-center {
display: flex;
align-items: center;
justify-content: center;
}
.desc {
padding-left: 16px;
}
.button-close {
margin-left: -5%;
}
this is what I had tried so far, clereable input demo. need advice how to solve this,

The problem is that the button does not exist when the input is empty and when some text is entered, the button is inserted into the DOM taking some space which makes the label move. One way of putting the button on a different layer is to use position: absolute on an element.
Try something like this:
clearable-input.component.html
<div class="input-wrapper">
<input class="input" [(ngModel)]="value">
<button *ngIf="value" class="button-close" (click)="value=''">X</button>
</div>
<label>Description</label>
clearable-input.component.ts
.input-wrapper {
position: relative;
display: inline-block;
}
button {
position: absolute;
top: 50%;
right: 5px;
transform: translateY(-50%);
border: none;
background-color: transparent;
}
label {
margin-left: 15px;
}
Working demo

Related

How to change position of a an icon inside a combobox in html?

I have a search box on page and there is an icon on that box which I found sample code for the icon.
But I want to put that icon to the right of the combo box. I have played around style but I could not achieve to position icon to right.
Can you help me?
My code is:
<mat-form-field class="search">
<div class="icon-div">
<span class="fa fa-search"></span>
</div>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Search office">
</mat-form-field>
and my style file is:
.search {
position: center;
text-align: center;
}
.search input {
text-indent: 4px;
}
.search .fa-search {
position: absolute;
top: 4px;
left: 0px;
font-size: 20px;
text-align: right;
}
.icon-div {
padding-top: 4px;
}
.search .fa-search {
right: 0px;
}
Swap left for right
.search .fa-search {
position: absolute;
top: 4px;
right: 0px;
font-size: 20px;
text-align: right;
}
.search {
position: center;
text-align: center;
}
Position center values is invalid property value. To achieve the position icon right please change this below property to
position: relative;

How to separate label text respective to div?

I have a label defined where one half needs to be at left side and the other half of text needs to be on right side. How can I solve this so that the other half is pulled right?
I have added margin-right to get the text to pull at right but it's not consistent for other divs.
<div class="radio">
<input class="radio-test" type="radio" value="3" checked="checked" name="test[id]" id="test_id">
<label class="radio-label" for="test_id_1">
Test of $12.0
<span class="test-cost">Free</span>
</label>
<hr class="test-hr">
<p class="test-message"></p><p>- First test message</p><p></p>
</div>
Expected Result:
Current Result:
How can I make text in above image i.e. 'Free' to appear on the right most side as shown on expected result? Also make it always consistent on other div such that the space from div is same across.
Here is a complete working example with JsBin: https://jsbin.com/yafesuyola/1/edit?html,css,output
It uses flexbox with justify-content: space-between. I also added a div around the label and the input to keep them on the same line with 100% width.
<div class="radio">
<div class="radio-and-label">
<input class="radio-test" type="radio" value="3" checked="checked" name="test[id]" id="test_id">
<label class="radio-label" for="test_id_1">
Test of $12.0
<span class="test-cost">Free</span>
</label>
</div>
<hr class="test-hr">
<p class="test-message"></p><p>- First test message</p><p></p>
</div>
.radio {
border: 2px solid #33c;
border-radius: 5px;
padding: 10px;
background: #e0eeff;
color: #33c;
font-weight: bold;
}
.radio-and-label {
display: flex;
}
.radio-label {
width: 100%;
display: flex;
justify-content: space-between;
}
.test-cost {
text-align: right;
}
.test-hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
}
Hope that helps!
Clip the element to always be pinned to top right of the element?
.radio {
position: relative;
}
.test-cost {
position: absolute;
top: 2px;
right: 2px; // or whatever px/rem/etc value that fits your need
}

Icon inside textbox - almost like glyphicon icon

I've got a textbox in which I need to add a Symbol. This symbol should always be visible and not be used in code behind (when getting the value of the textbox) - basicall like a glymphicon icon. I've tried using a span but it is not displaying the way it should.
This is what I've done:
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon"><b>$</b></i></span>
#Html.TextBoxFor(m => m.AgreedValue, new { #class = "form-control", placeholder = "Agreed Value" })
</div>
This is how it's currently being displayed:
And this is what I need it to display like:
Is there anything I'm missing? or how can I get it to look like the 2nd image?
Its all about style, If Html can be changed, then this is my solution:
.input-group {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
}
.input-text {
border: none;
height: 100%;
width: 100%;
background: transparent;
padding-left: 10px;
}
.input-text:focus {
outline: none;
}
.input-group {
padding-left: 10px;
width: 300px;
height: 40px;
border: 1.5px solid rgba(0,0,0,0.2);
box-sizing: border-box;
border-radius: 4px;
}
<div class="input-group">
<div>
<span class="input-group-addon"><i class="glyphicon"><b>$</b></i></span>
</div>
<input type="text" class="input-text">
</div>

Custom checkbox and radio button not support in all browser

I used custom checkbox and radio button for my project using :before and :after, but this work only in "Google Chrome" and not supported in other browsers, Is any trick that's why it should look same in all browser, I don't want to use label after checkbox or radio button.
CSS is here:
FIDDLE ( For example )
My actual radio button looks like this :
Google Chrome:
Firefox:
IE:
Pseudo Elements like :before and :after add content before and after the content of an element. Checkbox and Radio buttons do not have content, so they don't support before and after pseudo elements. Chrome is ' special ' , but the normal behavior is the one from FF and IE.
Furthermore checkbox and radio are browser default elements. They are very hard to change and not supposed to be changed.
Although you said you don't want to add a label, that's the way to go. Add it with position absolute to put it on top of the radiobutton/checkbox like in the example below
body {
padding: 50px;
}
input[type='radio'] {
margin: 0;
height: 13px;
width: 13px;
margin-top: 2px;
position: relative;
}
div.wrapper {
position: relative;
}
input[type='radio'] + label {
content: '';
display: inline-block;
width: 13px;
height: 13px;
border: none;
position: absolute;
left: 0;
top: 1px;
background: gray url("../images/i-radio-empty.png") no-repeat 0 0;
}
input[type='radio']:checked + label {
width: 13px;
height: 13px;
background: red url("../images/i-radio-checked.png") no-repeat 0 0;
}
<div class="wrapper">
<input type="radio" name="gender" value="male" id="male"> Male
<label for="male"></label>
</div>
<div class="wrapper">
<input type="radio" name="gender" value="female" id="female"> Female
<label for="female"></label>
</div>
<div class="wrapper">
<input type="radio" name="gender" value="other" id="other"> Other
<label for="other"></label>
</div>
Mihai T's solution isn't bad, but not checking checkbox when cliking on text can be really anoying. I personally hate it :)
Though it is true that radio and chekbox does not support pseudo elemens :before and :after but label does. So you can have normal label with text and pseudo element :before with position: absolute.
div.wrapper {
position: relative;
display: inline-block;
margin-right: 10px;
}
input[type='radio'] {
display: none;
}
input[type='radio'] + label {
padding-left: 20px;
}
input[type='radio'] + label:before {
content: '';
width: 13px;
height: 13px;
position: absolute;
left: 0;
top: 1px;
background: #FFF;
border: 1px solid #999;
border-radius: 50%;
cursor: pointer;
box-sizing: border-box;
}
input[type='radio']:checked + label:before {
background: #000;
border: 4px solid #F9CC55;
}
<div class="wrapper">
<input type="radio" name="gender" value="male" id="male">
<label for="male">Create Tabs Group</label>
</div>
<div class="wrapper">
<input type="radio" name="gender" value="female" id="female">
<label for="female">Update Existing Tabs Group</label>
</div>

Align child element to bottom with CSS

I have a form input, and the label spans multiple lines, and I want the corresponding checkbox to appear at the bottom (last line of the label element).
Here is what I was playing with
CSS
.standard-form {
width: 500px;
border: 1px solid red;
}
.standard-form .input-row {
overflow: hidden;
margin-bottom: 0.8em;
}
.standard-form label {
width: 25%;
float: left;
}
.standard-form .input-container {
width: 70%;
float: right;
}
.standard-form .checkbox .input-container {
display: table-cell;
height: 100%;
vertical-align: text-bottom;
}
HTML
<form class="standard-form">
<div class="input-row checkbox" id="permission">
<label for="input-permission">
Do I hereby grant you permission to do whatever tasks are neccessary to achieve an ideal outcome? </label>
<div class="input-container">
<input type="checkbox" id="input-permission" name="permission" value="true" /> </div>
</div>
</form>
It is also online at JSbin.
Is there any way to do this? I notice that div.input-container isn't expanding, which is the old multi column problem with CSS.
I thought I could get this going with display: table-cell and vertical-align: bottom but I haven't been able to do it yet. I don't mind that IE6/7 won't render it correctly.
I have also tried using a combination of position: relative; with the child position: absolute; bottom: 0; except then I need to specify a height which I can not guarantee will be the height of the label on the left.
See my changes in action: http://jsbin.com/ocovu/2/edit
Here are the relevant declarations:
.standard-form .input-row {
overflow: hidden;
margin-bottom: 0.8em;
position: relative;
}
.standard-form .checkbox .input-container {
position: absolute;
bottom:-2px;
left:25%;
}
Tried display: block?

Resources