I want a text field where i can insert text into and when i enter the text there should appear a button on the end of the textfield to clear the text. But I want this with only HTML/Less so without any JS.
As you can see in the code below I used the display: none attribute and i want to change the display: none to display: block after there is text entered in the input field.
code below:
<div class="input-field">
<input name="{{field.name}}" ng-model="field.value" type="text"/>
<button class="icon-assistant8 ci-cancel" type="reset">
</button>
</div>
And this is the relevant Less file:
.icon-assistant8 {
position: absolute;
right: 3px;
top: 5px;
width: 20px;
height: 20px;
display: none;
}
.icon-assistant8:after {
display: block;
}
Edit: After this example https://codepen.io/shidhincr/pen/ICLBD I know it is possible to do it with only HTML and CSS. I want to do that too but I can't get it to work and I do not know why.
Also I know I can do this with JS, I am just courious what i'm doing wrong.
They key parts of the example you've linked to that you haven't implemented in your own solution are
.search-box:not(:valid) ~ .close-icon {
display: none;
}
<input type="text" name="focus" required class="search-box" placeholder="Enter search term" />
In order for :not(:valid) to match, you need the required attribute on the input. When the input is empty, it's considered not valid.
Here's a basic example
input:not(:valid) ~ button { display: none; }
<input type="text" required>
<button type="button">Foo</button>
Related
When I make an input button and add a label, the label appears on the side of the input field. How can I make it appear inside the input field?
I have tried to put the label inside the input field with CSS, but when I write in the input, the label and the text overlap, and the text becomes unreadable. How can I make the label disappear when I type in the input field? If you have any other options, please tell me.
<div class="holder">
<label>username</label>
<input type="text">
</div>
.holder {
position: relative;
}
.holder label {
position: absolute;
left: 2px;
top: 2px;
width: 20px;
height: 20px;
}
.holder input {
padding: 2px 2px 2px 25px;
}
<div class="holder">
<label>username</label>
<input type="text" placeholder="username">
</div>
Try this by adding placeholder.
Just use the placeholder attribute for the input tag. Like this:
<input type="text" placeholder="username"/>
In HTML using the input placeholder attribute, show the text inside the input text
example:-
<input type="text" placeholder="username"/>
I hate css, I really do. I think this one will be trivial for most of you so please help me with this one.
I would like to create a radiobutton which have to change the background color of the label it's in. Here's the code which obviously does not work:
js:
<div className="container">
<label className="check" htmlFor="id">
<input {...radio.input} name="radio" type="radio" id="id" />
</label>
</div>
and css:
.check {
background-color: green;
display: inline-block;
height: 34px;
position: relative;
width: 60px;
cursor: pointer;
}
.check input {
display:none;
}
input[type="radio"]:checked + .check {
background-color: blue;
}
.container {
margin: 0 auto;
}
The + selector in CSS selects the next element in the HTML. Doing input + label is not going to work because your input is wrapped in the label.
The easiest solution for this would be to apply a checked CSS class in react when the input is checked. The other option would be to place the label AFTER the input in your markup, but that will probably require you to apply more CSS to get the appearance you need.
I really love CSS, I really do! ;)
Change your HTML to:
<div className="container">
<input {...radio.input} name="radio" type="radio" id="id" />
<label className="check" htmlFor="id">
</label>
</div>
and style the radio button individually.
I'm trying to make a custom file selection button in HTML and CSS.
I've read on the internet that it can be done, hiding the original button and 'drawing' a new one over it, like so:
HTML:
<div class="upload">
<input type="file" class="upload" name="upload"/>
</div>
CSS:
div.upload {
width: 157px;
height: 57px;
background-color: silver;
}
div.upload input {
display: block !important;
width: 157px !important;
height: 57px !important;
opacity: 0 !important;
overflow: hidden !important;
}
And it's working, obviously... but I want only a text, not a image.
So I tried it like this way:
<div class="upload">
Choose File
<input type="file" class="upload" name="upload"/>
</div>
And it won't work when I click on the label. It only works when I click below it.
Why doesn't this work and how can I make this work? I also tried with pointer-events and nothing...
You have to assign your text to your <button>, using a <label> with a for attribute equal to the id of the <input>.
<div class="upload">
<label class="uploadLabel" for="uploadBtn"> Choose File</label>
<input id="uploadBtn" type="file" class="upload" name="upload" />
</div>
In order to completely cover the button with your label, you'll also have to add absolute positioning.
.uploadLabel {
position: absolute;
}
Demo
Why is this necessary?
The event is triggered on your button. This basically means, clicking on a plain text element won't do anything. To trigger a click event on your button, you simply delegate the click on your label to your button.
use an actual label element. that will take care of delegating the click from the container to the input.
set opacity to 0, as you did in your original post (another, more verbose, and arguably more semantic approach will be to position the input absolutely and the label relatively, and set a lower z-index to the input. that will cover the input completely, effectively hiding it — see the second example).
the benefit here is you get clickable area that matches the label surface only, so you can style and set the dimensions to the label alone.
.upload {
display: block;
width: 157px;
height: 57px;
background-color: blue;
}
.upload input {
opacity: 0;
}
<label class="upload">
Choose File
<input type="file" class="upload" name="upload" />
</label>
… and the more verbose approach:
.upload {
position: relative;
display: block;
width: 157px;
height: 57px;
background-color: blue;
}
.upload input {
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<label class="upload">
Choose File
<input type="file" class="upload" name="upload" />
</label>
For fun I have taken a piece of code I got from a friend and tried to create a login field with username and password and I am having a hard time get the fields next to the words. There is a big gap between the word username and the box you type in.The same applies for password.
This is my code:
<form method="post" action="https://www.mattepunkten.com/action_login.php">
<input type="hidden" name="error_url" value="http://www."here you write url to webpage one should be directed to when typing wrong login".com">
Username:
<input type="text" name="fld_userid" size="15" style="width: 120px"><br>
Password:
<input type="password" name="fld_password" size="15" style="width: 120px"><br>
<input type="submit" name="cmd_invia" value="Login">
</form>
And my css code is the following.
input {
color: black;
margin: 10px 100px 0px 400px;
}
form {
color: white;
text-align: right;
position: fixed;
margin-top: 30px;
}
I am pretty new at this and would appreciate some tips! Thanks!
Well your margins are huge, try to make them smaller and see how it looks:
input {
color: black;
margin: 10px;
}
The style you are using has the following format:
margin: <top> <right> <down> <left>;
So with 100px right and 400px left they will get very far away :)
To be able to style the text you need it to be an element, so a simple answer would be to wrap it in some tag, but this is a style I personally enjoy, and adds a lot more meaning:
html
<label>
<span>Username:</span>
<input name="fld_userid">
</label>
css
label { display: block; text-align: center; }
input, span { display: block; width: 200px; }
This should stack both the text and the input on top of each other, while keeping them grouped by the label, so when you interact with the text the browser properly focus its related input.
I will add an explanation
margin: 10px 100px 0px 400px;
stands for:
top margin is 10px
right margin is 100px
bottom margin is 0px
left margin is 400px
Have you tried working with labels at all - keeping it semantic, and formatted, plus if you wrap your inputs it'll give it a larger hit area for said fields. In addition - I removed the input margin, removed the forms positioning and float so it retained it's block level, and adjusted the overall form margin so it's centered.
HTML
<form method="post" action="https://www.mattepunkten.com/action_login.php">
<input type="hidden" name="error_url" value="#"/>
<label>Username:
<input type="text" name="fld_userid" size="15"/><label>
<label>Password:
<input type="password" name="fld_password" size="15"/></label>
<input type="submit" name="cmd_invia" value="Login"/>
</form>
CSS
label {
display: block;
}
form {
text-align: center;
margin-top: 30px auto;
}
http://jsfiddle.net/evanbriggs/kad7yy1L/
Its better form to contain your labels in a <label> tag.
For example:
<div class="form-element">
<label for="foo">Label</label>
<input type="text" name="foo" id="foo" />
</div>
CSS to style it left justified:
.form-element label {
display: inline-block;
width: 150px;
}
I have an input of type button that is used to validate a form an input of type text.
I have seen that, for example, bootstrap lets you append some values to input. I am wondering how would I do append this input of type button into my input of type text.
I have added a screenshot of how I am thinking of it to be, but I am not sure which CSS strategy I would choose.
Thanks
It is nothing but a submit button with a text field
Demo
HTML
<div class="wrap">
<input type="text" />
<input type="button" value="Demo" />
</div>
CSS
.wrap {
display: inline-block;
position: relative;
}
input[type=text] {
padding: 10px;
width: 300px;
padding-right: 60px;
}
input[type=button] {
padding: 2px;
position: absolute;
right: 5px;
top: 5px;
}