Is there anyway to target specific input text elements in a form and reposition it, because it's letting me do things such as adjust padding, but I cannot reposition it by using margin. I also can't change the color, unless I do a style on the label. But doing a color on the label is useless because there's still the color in the input that I want to change. In short, I don't know how to override the original rule that I have for my input elements. Margins are not working either.
code:
input[type=text] {
width: 75%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block border: 1px solid #ccc;
border-radius: 4px;
color: #ffb3ec;
font-size: 24px;
box-sizing: border-box;
background-color: #4d4100;
}
.sample {
width: 30px;
background-color;
green;
}
<div class="mainBox">
<form>
<fieldset>
<label>placeholder:
<input type="text" id="placeholder" name="placeholder">
</label>
<br>
<label>Targets
<input type="text" class="sample" name="sample">
</label>
</fieldset>
</form>
</div>
You can wrap your input into a div element like below and reposition that:
<div class = "mainBox" >
<form>
<fieldset>
<div class = "wrapper">
<label> placeholder: </label>
<input type = "text" id = "placeholder" name = "placeholder" >
</div>
<br>
<div class = "wrapper">
<label> Targets </label>
<input type = "text" class = "sample" name = "sample" >
</div>
</fieldset>
</form>
</div>
I have rearranged the code a bit to fix the colour problem. It occurred, because you wrapped your input element inside the label. It doesn't work this way. Also remember to use for = "[THE ID OF YOUR INPUT ELEMENT]" to bind them together like so:
<label for = "sample"> Targets </label>
<input id = "sample" type = "text" class = "sample" name = "sample" >
In addition, before trying to play with top, bottom, left, right, paddings and margins always define the position of the element, because the default position is set to static, which means it isn't supposed to be moved.
position: static /* default, not supposed to be moved */
position: relative; /* to have move around its relative area */
position: absolute; /* to have move around based on the parent element */
position: fixed; /* to have move around based on the body of the document */
Related
I have multiple inputs and for some of them the input is to small to display the whole text (can not be changed). Is there a way to show the whole content of the input when hovering without breaking the rest of the layout? I included an example. I am trying to have the input pop out and be on top of the other inputs without breaking the design.
https://jsfiddle.net/14e37gj0/
I am not realy good with css.
I tried something like this.
input {
width: 10%;
}
input:hover {
width: 100%;
}
Best regards
First way to come on my mind was using Flexbox
so first of all, you need to wrap all your input tags with a wrapper like this
<div class="wrapper">
<input type="text" value="This text is long and I want to see the whole input when hovering" />
<input type="text" />
<input type="text" />
<input type="text" />
</div>
And in CSS add the following rules
.wrapper {
display: flex;
}
input:hover {
flex: 1 1 auto;
}
The flex: 1 1 auto is the one responsible to fill remaining gap until the end of the row.
Things could still be more efficient, but i tried to make it as simple as possible, and i suggest you learn more about CSS Flexbox.
Wrap the inputs in a flexbox div:
.row{
display:flex;
width:100%;
}
input {
width: 10%;
}
input:hover {
width: 100%;
}
<div class="row">
<input type="text" value="This text is long and I want to see the whole input when hovering"/>
<input type="text" />
<input type="text" />
<input type="text" />
</div>
You can use javascript to create a mouseover and mouseout event to create an absolutely positioned element, then pass the value of the event.target into its content. Use insertAdjacentHTML to add it on mouseover and use .remove() to remove it on mouseout. Check the inputs clientWidth with the inputs scrollWidth to see if you have overflow, if you do, insertAdjacentHTML span tag with class of .content with the e.target.value as its content.
See below code in snip it with full explanation of code above each line:
// get nodelist of all inputs
let inputs = document.querySelectorAll('input')
// function for the event listeners, pass the event into it as poarameter => e
function showAllContent(e) {
// the following positions will be used to position our
// absolutely positioned span tag below the event.target element
// get the top position of the event target => "input" being hovered
let top = e.target.getBoundingClientRect().top
// get the left position of the event target => "input" being hovered
let left = e.target.getBoundingClientRect().left
// get the height of the event target => "input" being hovered
let height = e.target.getBoundingClientRect().height
/* set a root variable for e.target top and left to be used in CSS to style
the position of the absolutely positioned span tag
NOTE: if you change the inputs layout of have elements below,
you will likely have to play with these settings a bit */
document.documentElement.style.setProperty('--e-target-top', `${top + height}px`)
document.documentElement.style.setProperty('--e-target-left', `${left}px`)
// set variable for event target value
let allContent = e.target.value.trim()
// set variable to show all of event.target.value
let span = `<span class="content">${allContent}</span>`
// conditional to make sure event.target is not null and also
// make sure its scrollWidth is greater than its clientWidth
if (allContent && e.target.scrollWidth > e.target.clientWidth) {
// check type of event is mouseover
if (e.type === 'mouseover') {
// insert the span tag into the DOM
e.target.insertAdjacentHTML('afterend', span)
}
// check type of event is mouseout and .content is set
if (e.type === 'mouseout' && document.querySelector('.content')) {
// remove the element from DOM
document.querySelector('.content').remove()
}
}
}
// iterate over the input nodeList
inputs.forEach(input => {
// event listener for mouseover
input.addEventListener('mouseover', showAllContent)
// event listener for mouseout
input.addEventListener('mouseout', showAllContent)
})
:root {
/* this will set our top position in the .content class it is being sent
from JS using style.setProperty('--e-target-top', `${top + height}px`) */
--e-target-top: 0;
/* this will set our left position in the .content class it is being sent
from JS using style.setProperty('--e-target-left', `${left}px`) */
--e-target-left: 0;
}
input {
width: 10%;
}
.content {
display: inline-block;
position: absolute;
left: var(--e-target-left);
top: var(--e-target-top);
width: auto;
height: auto;
background: #ccc;
border-radius: .5rem;
padding: .5rem;
margin-top: 2px;
}
<div id="parent">
<input type="text" value="This text is long and I want to see the whole input when hovering" />
<input type="text" value="small text" />
<input type="text" value="this inputs scrollWidth will overflow the clientWidth" />
<input type="text" />
</div>
I need help aligning labels under input boxes such as a description of what should be input into the textbox, but I also need text aligned with the textbox after
I tried making new table rows below the input boxes and using margins, but this doesn't line up in Chrome, it does in IE, but not Chrome.
I've tried
< tr >< td colspan='1' >< span style='display: inline-block;' >You will arrive on: < input type='text' >< label >(Date)< /label >at < input type='text' > < label >(Time)< /label>< /span >, please bring all documents with you.
This should be:
You will arrive on: at (inline with textboxes) , please bring all documents with you.(align with previous text boxes, so this should be above the labels as well.)
Rephrasing: I need something like a paragaph, with a block of text, but with inputs mixed into this text. Then I need small descriptive labels directly under the inputs. I don't want these small descriptive labels to be inline with the other paragraph's text only right under the inputs... example:
"This is a paragraph < input text here > < label that goes under input > paragraph text continues on here < another input text here > < label that goes under this input > again the paragraph text goes on here inline with the other paragraph text and the inputs"
I think I've understood what you're trying to ask. You need to wrap the label and input in a div so that the label can be positioned off of the input tag.
.label-under {
position: relative;
display: inline;
}
.label-under label {
position: absolute;
left: 0px;
top: 10px;
}
span {
line-height: 2.5;
}
<span style='display: inline-block;' >You will arrive on: <div class="label-under"><input type='text' >
<label>(Date)</label></div> at <div class="label-under"><input type='text' >
<label>(Time)</label></div>, please bring all documents with you.</span>
Edit: You may need to adjust the line height of the span element if you're viewing on a device with a small width.
// Is optional and can be removed.
span {
line-height: 2.5;
}
// But top: 10px must be changed to top: 20px
skip the table and use display flex instead.
.form {
display: flex;
align-items: center;
}
.input-container {
display: flex;
align-items: flex-end;
margin-right: 2rem;
}
.input-container__label {
margin-right: .5rem;
}
<form action="" class="form">
<div class="input-container">
<label for="email" class="input-container__label">Email</label>
<input type="text" class="input-container__element">
</div>
<div class="input-container">
<label for="something" class="input-container__label">Something</label>
<input type="text" class="input-container__element">
</div>
</form>
I am looking to try something like in the below link, however I want different images for each checkbox. Is there any way to do this? I have tried setting different classes for each item and just adding the class to the checkbox, but that doesnt seem to work...the default checkboxes just remain the same.
MY ATTEMPT:
https://jsfiddle.net/9qjj7012/
<div class="AccordionPanel" id="acc-step-3">
<div class="AccordionPanelTab">Step Three - Equipment Package</div>
<div class="AccordionPanelContent">
<div class="">
<input type="checkbox" name="equipment" value="speakers" id="equipment_0" class="speaker">
<input type="checkbox" name="equipment" value="subwoofer" id="equipment_1" class="subwoofer">
<input type="checkbox" name="equipment" value="smoke-machine" id="equipment_2" class="smokemachine">
<input type="checkbox" name="equipment" value="moving-head" id="equipment_3" class="movinghead">
</div>
<div class="form-gap"></div>
<input name="previous" id="acc-step-prev-3" type="button" class="form-btn form-prev" value="Previous">
<input name="next" id="acc-step-next-3" type="button" class="form-btn form-next" value="Next"><br>
<input name="reset" type="reset" class="form-btn form-reset" value="Reset">
</div>
</div>
EXAMPLE OF THE RESULT I WOULD LIKE:
http://codepen.io/jointmedias/pen/HqCJe (Except with individual images for each checkbox)
NEW JSFIDDLE: https://jsfiddle.net/9qjj7012/
What you're doing wrong, is that you're assigning a class to the checkbox, while the CSS rules in the example you refer to don't select the check box, they select the label. The checkbox is actually hidden, it's the label you are seeing.
Check this out:
http://codepen.io/DavidvanDriessche/pen/xVwJgd
In this example the labels have different classes and the css rules act upon that as follows:
For all checkboxes:
input[type=checkbox] {
display: none;
}
For all labels with class background1 that are following a checkbox:
input[type=checkbox] + label.background1 {
background: url("http://www.corporatecomplianceinsights.com/wp-content/uploads/2013/06/Facebook-thumbs-up.jpg") no-repeat;
}
For all labels with class background2 that are following a checkbox
input[type=checkbox] + label.background2 {
background: url("http://www.clker.com/cliparts/e/2/a/d/1206574733930851359Ryan_Taylor_Green_Tick.svg.med.png") no-repeat;
}
For all labels with a class attribute that begins with "background" and are following a checkbox:
input[type=checkbox] + label[class*="background"] {
background-size: 50%;
height: 250px;
width: 250px;
display: inline-block;
padding: 0 0 0 0px;
}
The only reason I'm working with that last rule is that it allows you to put all common formatting code into one CSS rule and you don't have to repeat it for each of the rules that target a specific background class, but that's a nicety you could forego if you want.
So far checkbox does not support background attribute. Luckily checkbox label also work as a clickable area for the assigned (for=checkboxId) checkbox. So the idea is to make a fake checkbox using label element and then change it's background value when checked.
input { display:none; } /* hide the checkbox. Label is our clickable area */
label { /* define the clickable area */
height: 150px;
width: 150px;
display: inline-block;
border: 2px solid;
}
/* set background image of the clicked area */
input[id=speakers]:checked + label {background: url('speakers.jpg');}
input[id=subwoofer]:checked + label {background: url('subwoofer.jpg');}
input[id=smoke-machine]:checked + label {background: url('smachine.jpg');
}
See Demo
I have a html input textfield as follows:
<input type="text" name="fName" class="inpField" size="20" value="First Name *" />
Now I want to do selective styling of some text as follows:
I have the default value set as "First Name *". Using css- I want to apply a global style to that whole thing- such as font-family, font-size.
Then I want to selectively style the asterisk (*) after the First Name with color red. Since that * is a value contained in an attribute- how do I selectively select only the asterisk part in the value attribute to make it red.
Please help.
You can target input with the specified value of thevalue attribute (if you want to target value starting with "First Name", you can use ^= instead of =):
input[type="text"][value="First Name"] {
font-size: 10px;
color: red;
<...>
}
JSFiddle
Nowadays you can do this:
<input type="email"
name="email"
placeholder="Your Email"
id="newsletter-subscribe-email-field">
Then style it like:
#newsletter-subscribe-email-field::placeholder,
#newsletter-subscribe-email-field::-webkit-input-placeholder,
#newsletter-subscribe-email-field:-ms-input-placeholder,
#newsletter-subscribe-email-field::-ms-input-placeholder {
color:#5472e8;
}
::placeholder CSS pseudo-element
If you want to style only the *, you're out of luck. No way to do that in just CSS. There is, however, way of doing this with altering your DOM:
<div class="input-container">
<input type="text" name="fName" class="inpField" size="20" value="First Name" />
<span class="input-addon">*</span>
</div>
Then, the CSS:
.input-container {
position: relative;
display: inline-block;
}
.input-addon {
position: absolute;
right: 10px;
top: 5px;
color: red;
}
JSFiddle
Simply doing this will suffice:
input[value] {
}
You can also prepend the selector with a PARENT id / class name to ensure it's unique for each form if need be.
http://jsfiddle.net/samuidavid/vz9qxsfw/
you can use this ::
text.inpField {
font-size: 10px;
color: red;
}
I got this, but I do not want the yellow outline. How can I do?
My code:
<div class="ui-block-a">
<div class="ui-bar ui-bar-e" style="height:50px">
<input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" />
<label for="checkbox-1"></label>
</div>
You need to override checkbox style in three steps.
Position of checkbox itself, which lays behind the visual checkbox. I have added div.-ui-bar before each overridden style in order not to specific and to keep original styles elsewhere.
Demo
div.ui-bar input {
left: 10px !important
}
Width of label
div.ui-bar label {
width: 27px !important
}
Position of visual checkbox
div.ui-bar .ui-checkbox .ui-btn-icon-left .ui-icon {
left: 5px !important
}