Underline single letter in an input placeholder - css

One can apply CSS styling to a placeholder, such as for Firefox:
::-moz-placeholder { text-decoration: underline; }
However, what I would like to do is underline a single letter in a placeholder, for the purpose of hinting at a hotkey for the user to press (similar to Windows in file menus), such as making the F in First Name underlined below:
<input type='text' placeholder='First Name' />
Is there any way to do this?

I think you can achieve this with CSS only in google chrome. For example:
You can select the first letter of placeholder
::-webkit-input-placeholder::first-letter {
color: red;
text-decoration:underline;
}
Result:
The text-decoration does not render when set with :first-letter in Chrome (Version 39.0.2171.71). So we can achieve the underline with border-bottom.
::-webkit-input-placeholder::first-letter {
color: red;
border-bottom: 1px solid red;
}
Result:
UPDATE: text-decoration works fine on Chrome 41.0.2235.0 Canary.
Here is the DEMO: http://codepen.io/MizR/pen/myeJZe
Unfortunately, this solution doesn't work on Firefox. :(
Update 2: No longer works. :(

You can use an absolute-positioned u tag, being careful to use the same font and padding as the input.
You'll need to hide the u when the input has content:
document.getElementById('iFirstName').onkeyup= function() {
var u= document.getElementById('uFirstName');
u.style.display= this.value>'' ? 'none':'inline';
};
u {
position: absolute;
font: 10pt verdana;
padding: 4px;
}
input {
padding: 3px;
font: 10pt verdana;
border: 1px solid #ddd;
}
<u id="uFirstName">F</u>
<input id="iFirstName" type='text' placeholder='First Name' />

If you are comfortable using contenteditable instead of input, you can try:
http://jsfiddle.net/lotusgodkk/GCu2D/473/
HTML:
<div contenteditable="true" data-ph="First Name">Hello</div>
CSS:
div {/*For styling div similar to input*/
width:300px;
height:24px;
border:1px solid grey;
}
div[contentEditable=true]:empty:not(:focus):before {
content:attr(data-ph);
color:grey;
}
div::first-letter {
text-decoration:underline;
}

Related

how to change text color in bootstrap-cue

Want button on dark-blue background with white text
code in xxx.vue
<b-dropdown text="user" right variant="blue" class="signout-button">
<b-dropdown-item #click="toMain()">sign out</b-dropdown-item>
</b-dropdown>
and style is
.bg-blue {
}
.signout-button {
border-radius: 10px;
color: white !important;
background-color: #183450;
border-color: #183450;
border-style: solid;
}
the result look like this
it still back text
For example should do the job, as b-dropdown will generate that button tag inside.
.signout-button button{
color: red;
}
Well, you need styling on the <b-dropdown> compiles it converts to button tag.
.signout-button button {
color: green;
}
Here is working Jsfiddle
Hope this helps!

Removing underlining from image link

I have a page with a single large image that also has a link element, and I'd like to remove the underlining from the image link. I am working in Chrome, which displays the highlighting under the image link and claims the css is introduced byuser agent stylesheet, which I understand is Chrome's default css. The user agent stylesheet brings the following style to my page:
a:-webkit-any-link {
color: -webkit-link;
text-decoration: underline;
cursor: auto;
}
How can I remove the underlining from this image link? I tried setting the id of my link and image to img-link then targeting that id with the following css, but haven't had any luck:
<a id="img-link" href="/images/post_images/mapping_early_english_books/provincial_printing.png" data-lightbox="provincial_printing" data-title="My caption">
<img id="img-link" src="/images/post_images/mapping_early_english_books/provincial_printing.png" alt="Provincial Printing" style="width:100%" /></a></p>
#img-link {
text-decoration: none;
}
Any help others can provide on removing this underlining will be greatly appreciated!
#img-link, #img-link img{
text-decoration: none !important;
border:0px !important;
outline:none;
border-width: 0px;
outline-width:0px;
border-bottom: none;
}
just set the border property to zero:
#img-link {
text-decoration: none;
border: 0 !important;
}
I m not pretty sure but can you try this :
#img-link {
text-decoration: none !important;
}
I hope it would solve it
Don't give multiple elements the same ID value.
If you want your CSS to also target an img element inside your element with the ID of img-link, use the following CSS.
#img-link, #img-link img{
text-decoration:none;
border-width: 0px;
}
The problem appears to be from an underline added in your css .content a, try adding:
border-bottom: none;
to your img-link css

What is the command that can change the text color to #000000 when clicked upon

I don't know what the command is called to change the text color when clicked upon. I've tried different variations of textarea:focus, input:focus and textarea:active, input:active but it didn't work.
input, textarea {
background: #fff;
border: none;
color: #aaa;
font-size: 12px;
line-height: 1.0em;
margin: 0;
outline: none;
text-align: center;
padding: 0;
text-decoration: none;
}
input: active textarea: active {
color: #000000;
}
input:focus will work fine, see this Fiddle.
<input type="text" value="Click me to make me green!">
CSS:
input {
color:red;
width:20em;
}
input:focus {
color:green;
background:#dfd;
}
The :focus state indicates that the element is currently selected and accepting input. Read more over at W3.
If you want to permanently change the color on first click you're introducing 'custom persistent state', which is not behavioral and as such not possible via CSS but only by using Javascript, for example to add a class to the element.
There are some CSS ways to do it- like an answer here already. Here's an example with Javascript. Like it has been said, Javascript should be used if you want to permanently change the color.
HTML
<p id="change">Hello World!</p>
Javascript
document.getElementById('change').onclick = changeColor;
function changeColor() {
document.body.style.color = "blue";
return false;
}
Fiddle Here

Reset input style for checkboxes to default in IE

I have a CSS rule for input like this:
input {
border: 1px solid black;
}
The problem is that checkboxes in IE (have tested on IE 8 and 9) and Opera also inherit this border and instead of showing the default style they show their custom mode for checkboxes with white background and black checks like this:
instead of the native style, like in Windows 7 with gradient-grey background and dark blue checks that are shown in Chrome and Firefox:
I would like to keep the border for the input-rule in the CSS, but I have a class called "checkbox" that I put on all checkboxes like this:
<input type="checkbox" class="checkbox" />
Is there any way to reset the border style with the .checkbox rule?
I have tried:
.checkbox {
border: none;
}
which works in Opera to revert to the default style, but not in IE. I have also tried many different combinations of:
.checkbox {
border: 1 none transparent;
}
but none of these seems to reset to the default style of the checkboxes in IE.
Is it possible to revert the default style for checkboxes in IE do without removing the border for the input-rule and instead use the .checkbox class?
In many browsers, it's not possible to reset the checkbox back to the default native style.
This is probably the reason why CSS resets generally do not include a rule to this effect:
input {
border: 0;
}
The most compatible technique is to do this:
input[type="text"], input[type="password"] {
border: 1px solid black;
}
and explicitly list every type of input you wish to style.
See: http://jsfiddle.net/EPpJ9/
This will work in IE7+ and all modern browsers.
You could also do this more neatly with the not() CSS3 pseudo-class, but that doesn't work in IE8, which is a deal breaker for me:
input:not([type="checkbox"]) {
border: 1px solid black;
}
In case you are still wondering there is indeed a way to style checkboxes and have it work in most browsers including IE. And you only need some css and just a little javascript and jquery. Works in IE6+
First make your checkbox like this.. Only add a label element with the for element pointing to the id of the checkbox.
<input id="mycheckbox" type="checkbox">
<label id="mylabel" for="mycheckbox"></label>
Next include some css:
#mycheckbox {
display: none;
}
Draw your checkbox using your label control, here is one I made:
#mylabel {
float: left;
margin-top: 11px;
background-color: #fff;
border: 1px solid #000;
display: block;
height: 12px;
width: 12px;
margin-right: 10px;
-webkit-border-top-right-radius: 20px;
-webkit-border-bottom-right-radius: 20px;
-moz-border-radius-topright: 20px;
-moz-border-radius-bottomright: 20px;
border-top-right-radius: 20px;
border-bottom-right-radius: 20px;
background-position: left center;
}
You have to create a look for when the box is checked:
#mylabel.checked {
background-color: #808080;
}
Finally some jquery:
$(document).ready(function () {
$("#mycheckbox").change(function () {
if ($("#mycheckbox").is(":checked")) {
$("#mylabel").addClass("checked", "checked");
} else {
$("#mylabel").removeClass("checked");
}})
});
Don't forget to include the jquery libraries (put this in your head tag):
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
Check out the fiddle to see it in action:
fiddle
Couldn't you include ie8-js to make IE8 recognize not() CSS3 pseudo-class?
http://code.google.com/p/ie7-js/
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->

Change input element look

Is it possible to make an input HTML element with a value make to look just like a text in a div using CSS? Make the border disappear and make the background color of the input same as the page backgound color.
If I understand correctly: yes.
See: http://jsfiddle.net/zaK7j/
Test CSS:
input, div {
border: 0;
padding: 0;
margin: 0;
background: transparent;
font: 13px sans-serif
}
HTML:
<input type="text" value="Yes." />
<div>Yes.</div>
input[type=text], textarea {background:none;border:0;padding:0;margin:0;}
Will reset your input and also your textarea.
Edit: Note that this works in IE7 and above.
You could use the CSS
input{
border: none;
}
Your htlm like this i presume :
<div>
<input type="text" value="some text"/>
</div>
And your css :
div {
background-color: olive;
}
input[type=text] {
border: none;
background-color: olive;
}

Resources