how to prevent text inside an input from being overridden - html

I'm trying to implement an html control similar to the how search works in google chrome. I'm aware that in chrome it might not be built in html, but I'm trying to achieve the same functionality.
The way the search works is that adjacent to the text entered into the input, there's an extra text field that present the current index of a total number. It's also worth while noticing that the highlighted border is of the entire input (including the entered text and the index and sub total count). Also, when entering a long text, the index and sub total indicator (e.g. 0 of 10) doesn't get overridden, and the text itself scrolls.
Does anyone have any simple approach for implementing this feature set?

A simple aproach would be adding padding to the input, and positioning the text you want to keep over it. Rewriting the value of the input with pogramming.
HTML
<div class="form-text">
<input type=text placeholder="0 of 0" id="youridhere"/>
<label for="youridhere" class="static-value">Get this label to appear</label>
</div>
CSS
.form-text{
position:relative;
}
input{
padding:5px 5px 5px 150px;
}
.static-value{
position:absolute;
left:10px;
font-size:0.85em;
top:9px;
}
Pen of it working
This is the simplest solution, but you can find other better results and best practices using javascript. Wich I think would be something like detecting the pressed key and adding it the to string programatically instead of the standart browser behaviour.
I like this CSS based solution cause you can customize the fixed text, and don't need to change the standart behaviour of input fields.
-------- Edit --------
Actually, the best solution would be with the label element, with the for attribute, link it to the field. So when clicked it leads the user to the field. Edited.

I've made the foundation of it with only CSS, see the demo follows.
jsfiddle
* {
box-sizing: border-box;
}
div {
position: relative;
width: 10em;
}
input {
width: 100%;
padding: 4px;
border: 1px solid;
padding-right: 52px;
}
span {
display: block;
border-left: 1px solid;
width: 50px;
text-align: center;
position: absolute;
right: 0;
top: 2px;
}
<div><input type="text"><span>etc</span></div>

Related

Custom input field border behavior when trying to include password eye

I am trying to create a custom input field with a text input and a button with an eye icon to show/hide the password text.
Now, I know that simply create an input field and absolutely position the eye button but the problem with that is that on certain browsers, the Lastpass extension or Safari keychain will insert their respective icons thus overlapping the eye icon which I always want to be visible and clickable. As an example, this is bad:
Therefore, this is what I want to achieve:
I am trying something like this:
<div className="input-wrapper">
<input className="password-input" type="password" />
<button className="password-eye">
</div>
CSS
.input-wrapper {
position: relative;
border: 1px solid #ccc;
}
.password-input {
border: none;
width: calc(100% - 32px);
height: 40px;
}
.password-eye:extend(.icon-password-eye all) {
background: white;
border: none;
height: 40px;
font-size: 24px;
position: absolute;
right: 0px;
top: 0px;
padding-right: 8px;
}
.icon-password-eye::before {
content: '\e618';
}
The problem that I'm facing is that because I want the whole wrapper to behave as if it were an input component, when the user selects the input field, only the actual input part is selected. In addition, if the password validation errors out, only input field is shown to be red while I want the entire portion to be red.
This is what is happening:
Any help would be greatly appreciated.
what you want to do is changing the border CSS of the input-wrapper class.
and not the input
you need to change the code that changing the input css to change the input-wrapper css.
if you need help in that , please give the full code.

Can I implement rich text via invisible textarea over a pre?

I wanted to implement a syntax highlighting feature in my app.
Please ignore the possibility of contenteditable.
I'd like to implement the feature via:
textarea with invisible font and background, floating over a pre with appropriate colors applied to the text. The cursor and selection background should render in the textarea, but the highlighted text should show through from the underlying pre.
Now, it seems there is something special about textarea (or my CSS ignorance) that makes this not render correctly (e.g. making background/color of a textarea also makes the cursor invisible).
Is there a way to achieve my goal?
I don't need general help. Attached is an image of my editor in action. Highlighting and selection are visible, cursor is not. :(.
You could use thee CSS-property caret-color for the textarea. This will set the color specifically for the cursor/ caret and ignore the color of the background/ text for the textarea. This does unfortunately not work in IE/ Edge (It is however supported by the remaining major browsers).
I clearly did not get what you meant before and pointed you toward a code editor like ace.
I see now I just created the example of what you asked above. You can hide the text in the textarea by doing something like this color: rgba(0,0,0,0); But that will also hide the cursor.
*{
box-sizing: border-box;
}
div{
position: relative;
}
pre{
background: black;
color: white;
font-size: 14px;
}
textarea {
font-size: 14px;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: none;
border: none;
padding: 0;
color: rgba(0,0,0,0);
}
<div>
<pre>This is my pre
-
-
</pre>
<textarea>This is my pre</textarea>
</div>

Printing a checked checkbox / tick box with HTML and CSS

I have the following problem: I have to use an HTML->PDF conversion service to render a piece of HTML. However, this service is a bit limited in it's functionality, so I need a way to "work around" it.
I'm mainly just printing text, so it's not a big deal, but the only problem is that I have to print some "unticked" and some "ticked" check boxes, my converter is failing at this. In particular I've tried:
Using the unicode ☐ ("☐") and ☑ ("☑") characters, but the converter doesn't render them (probably the font it's using doesn't
have them)
Using the WingDing characters þ and ¨ but again, the wingding font is not recognized
The converter doesn't support images, so can't just use an image
I was thinking, at this point, to "simulate" a checkbox by using spans with borders, something like:
<span style="border: 1px solid black; height: 12px; width: 12px;"></span>
However, I can't make it look correct (no fault of the converter this time, even browsers show the above as just one vertival line.
Can anyone help me "draw" checkboxes using just "basic" html elements? What would be the cleanest way?
PS: checkboxes need to be inline with the text.
You're on the right track.
Using HTML and CSS:
/* The standalone checkbox square*/
.checkbox {
width:20px;
height:20px;
border: 1px solid #000;
display: inline-block;
}
/* This is what simulates a checkmark icon */
.checkbox.checked:after {
content: '';
display: block;
width: 4px;
height: 7px;
/* "Center" the checkmark */
position:relative;
top:4px;
left:7px;
border: solid #000;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
<div class="checkbox"></div> Unchecked<br><br>
<div class="checkbox checked"></div> Checked
The reason YOUR code didn't work was because you were using a span element, which is an inline element. You can use a span for this, but you'll need to add the style of display: block to the element (making it act as a block element instead of an inline element).
The div tag is a block, so no need for setting it's display style. If you would like the div to display inline, set the display: inline-block
Try this :
<div style="border: 1px solid black;
width: 10px;
height: 10px;
display: inline-block;
margin-right: 4px;">
</div>
https://jsfiddle.net/8rt4dqfc/

Fixed placement of element, but considering pseudo before element

I have an annoying issue with the html layout of a form. I cannot really change the general setup, since it is part of a huge framework. But I have to "move" a button to a more suitable location. I am close, but not happy with the solution so far. Maybe you can give me some idea in this. Here is a dramatically simplified version to demonstrate my approach:
I have two container divs, top and bottom.
The top container shows a button on the left side. That button is fixed, but can have a different width due to the translation of its label.
The bottom container holds lots of stuff. Amongst that a second button at its top which works fine, but looks wrong. I want to optically move it into the top container, since there is a logical connection to the button in there. Sure, really placing it in there would be the correct solution, but I currently cannot do that. Instead I use a fixed position which works fine, except for the horizontal placement. I have to decide how far pushed from the left to place the button, so that it certainly does not overlap the first button in the container. I obviously have to consider all translations, the result works, but depending on the first buttons label I have an annoying horizontal gap between the two buttons.
I tried to use a pseudo element (::before) on the second button to help with the layout. Since when rendering the view I obviously have the translated label of the first button I can copy that into some property of the second button and use that property in my css to fill a before pseudo element of the second button which has exactly the same length as the first button. That is what is shown in the code example posted below.
What I completely fail to do is to place that pseudo element such that is it left in the top container (so exactly below the first button). The idea is to indirectly place the second button that way. Looks like this is not possible, obviously. But since I am a bloody beginner in markup and styling I thought it might be worth asking here...
Below is some drastically stripped down code to demonstrate my approach.
I create a jsfiddle for you to play around with. Here is the code:
HTML:
<div id="top-container">
<button>multilingual button text</button>
</div>
<div id="bottom-container">
<h2>
Some title opening the bottom container
<span class="into-top-container">
<button id="place-me" reference-text="multilingual button text">button to be placed</button>
</span>
</h2>
<p>Some content</p>
<p>Some content</p>
<p>Some content</p>
</div>
CSS:
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
div {
margin: 0;
padding: 5px;
}
button {
margin: 0;
padding: 5px;
white-space: nowrap;
}
div#top-container {
width: 100%;
border: 1px solid green;
}
div#bottom-container {
width: 100%;
border: 1px solid blue;
}
#place-me {
position: fixed;
top: 0;
left: 400px;
margin: 5px;
background: yellow;
}
#place-me::before {
z-index: 0;
/*visibility: hidden;*/
position: absolute;
content: attr(reference-text);
margin: 0 5px;
padding: 0;
background: gold;
right: 100%;
}
Notes:
that in the above code the second button is placed with left: 400px;. That is more or less what I want to change. But obviously left: 0 is not correct...
the visibility css rule for the pseudo element is currently commented out for demonstration purpose
keep in mind that the second button is *not* contained inside the top container, but actually logically below the title of the bottom container. The goal is to move it optically up into the top container which already is where close to what I want. Except for the horizontal alignment...
Upon request here is a screenshot:
It is taken from the fiddle I posted above. I added the red ellipse which shows what element pair I want to move and the left pointing arrow indicating where I want to move that too. I want to move it exactly that far, that the two tests "multilingual button text" are exactly placed on top of each other, but without specifying an explicit left placement obviously. That is why the pseudo element exists: as a dummy placeholder. I would then hide that pseudo element and have the second button placed exactly right of the first button, regardless of how long the translated text in there is.
So the final result should like like that:
OK, I invested some more time, since this issue popped up again after a regression in our code and I found, as often after allowing some time to pass, a logical and relatively clean solution:
I use the same stripped down code to for demonstration purposes.
The jsfiddle is based on the one provided in the question itself.
HTML: no real change, except for the reference-text having moved from button to container, for the why see below:
CSS:
* {
font-size: 12px;
font-weight: normal;
font-family: Arial;
}
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-size: 12px;
font-weight: normal;
}
span,
div {
margin: 0;
padding: 5px;
}
button {
margin: 0;
padding: 5px;
white-space: nowrap;
}
div#top-container {
width: 100%;
border: 1px solid green;
}
div#bottom-container {
width: 100%;
border: 1px solid blue;
}
span.into-top-container {
position: fixed;
top: 0;
left: 0;
pointer-events: none;
border: 1px solid transparent;
}
span.into-top-container::before {
visibility: hidden;
content: attr(reference-text);
position: relative;
margin-right: 5px;
padding: 5px;
border: 2px solid;
background: gold;
}
#place-me {
background: yellow;
pointer-events: all;
}
The basic change in strategy: it is the container holding the button to be placed that has to be positioned in a fixed manner, not that button itself (so the <span class="into-top-container">)! That allows to use the pseudo before element, now also anchored to that container, not the button, to take the space as required without actually getting part of the button itself.
Since that container is now place over the original multilingual button that one is not clickable any more. That issue is fixed by a css pointer-events set to none for the container and set to all for the placed button again. That makes the container itself simply ignore all events (clicks) and have them passed to the original button beneath.
I had to make sure that the font used inside the pseudo element is style exactly like the original multilingual button. That actually makes sense, since the font styling defines the actual width used by that button, so the actual width used by the pseudo element should be defined in exactly the same manner. In the example above I forced that by simply setting all elements font style rules to some fixed values (the initial * {...} in the CSS code). That can obviously also be done right inside the css rules for the pseudo element itself. I chose the more simple and brute variant here to keep the code clean.

How do I add a "search" button in a text input field?

How do I create a similar “search” element to the one in this site?
If we view source, he has one textbox followed by a <span> tag.
<input type="text" name="q" id="site-search-input" autocomplete="off" value="Search" class="gray" />
<span id="g-search-button"></span>
Where do I get a similar "magnifying glass" image?
Put the image into the span, for example using background-image, then give it a relative position and move it to the left so it overlaps the right end of the search box, for example:
#g-search-button {
display: inline-block;
width: 16px;
height: 16px;
position: relative;
left: -22px;
top: 3px;
background-color: black; /* Replace with your own image */
}
Working example on JSBin
Your eyes are deceiving you. The button is not within the text box. Using a background image is NOT the way to go, as it wont provide the clickable submit button.
What you need to do is add a wrapper div around the input:text and input:submit.
The wrapper will look like it's a text box, but will actually contain a transparent text box and a submit button. You'll need to specifically remove the styles for the input:text and input:submit elements.
It's very important that you keep the submit button, otherwise hitting enter while searching will not have a default reaction. Additionally placing the submit button after the text field allows people to actually click on the button.
You can make your own magnifying image, they're pretty easy to make in a 20x20px transparent png.
.search {
border: 1px solid #000000;
width: 200px;
}
.search input[type="text"] {
background: none;
border: 0 none;
float: left;
height: 1.5em;
line-height: 1.5em;
margin: 0;
padding: 3px 0;
width: 180px;
}
.search input[type="submit"] {
background: #CCCCCC url(path/to/image.jpg);
border: 0 none;
height: 1.5em;
line-height: 1.5em;
margin: 0;
padding: 3px 0;
text-indent: 100px;
width: 20px;
}
<form ...>
<div class="search">
<input type="text" />
<input type="submit" />
</div>
</form>
If you view the page in Google Chrome, right-click on the search button and select “Inspect element”, you’ll be able to see the CSS used to achieve this effect.
If you’re not familiar with CSS, I thoroughly recommend ‘CSS: The Definitive Guide’.
A site like Iconspedia has a number of free icons that are similar.
Wherever you get the icon be careful to ensure that you have the rights to use it in your application. Many graphics are protected and some have restrictive licenses.
If you use a background image on the field then there's no way to bind to it to get the click action. So the solution is to have a separate search field and image, so you can bind click event in jQuery to the image. Fiddle here:
http://jsfiddle.net/Lzm1k4r8/23/
You can adjust left: position to be left or right side of the search box.
To help with user feedback why not add the pointer icon to your mouse when you're hovering over the magnifying glass? Just att this to your CSS:
.search:hover {
cursor:pointer;
}
I'd like to plug a new jQuery plugin I wrote because I feel it answers to the OP's request.
It's called jQuery.iconfield: https://github.com/yotamofek/jquery.iconfield.
It lets you easily add an icon to the left side of your text field. For using the icon as a button, you can easily bind to the 'iconfield.click' event, which is triggered when the user clicks the icon. It also takes care of changing the cursor when the mouse is hovering over the icon.
For instance:
$('#search-field').iconfield( {
'image-url': 'imgs/search.png', // url of icon
'icon-cursor': 'pointer' // cursor to show when hovering over icon
} );
$('#search-field').on( 'iconfield.click', function( ) {
$('#search-form').submit()
}
I would love to get some feedback on my work.