How do I target div class within a form? - html

I am trying to target what and where, as well as
search.
Here is my html:
<div class="entry-content">
<p> </p>
<div class="entry-content">
<div class="job_listings" data-location="" data-keywords="" data-show_filters="true" data-show_pagination="false" data-per_page="10" data-orderby="featured" data-order="DESC" data-categories="">
<form class="job_filters">
<div class="search_jobs">
<div class="search_keywords">
<label for="search_keywords">What?</label><br />
<input id="search_keywords" name="search_keywords" type="text" value="" placeholder="Chef, Cleaner, Manager" />
</div>
<div class="search_location">
<label for="search_location">Where?</label><br />
<input id="search_location" name="search_location" type="text" value="" placeholder="London, Berlin, Bristol" />
<input name="filter_job_type[]" type="submit" value="search" />
</div>
</div>
<div class="showing_jobs"></div>
<div></div>
<div>
Post A Job
</div>
</form>
</div>
</div>
<p><a class="load_more_jobs" style="display: none;" href="#"><strong>Load more listings</strong></a></p>
</div>
Tried everything including.
.entry-content {color: green;}
Interestingly,
. entry-content {background-color: green;}
works, but
.entry-content {color: green! important;}
does nothing.

you can use the following style to target all the labels inside entry-content. This works unless the style is not overrided by other styles
.entry-content label{
color:green;
}
For specific labels, you can use,
.search_keywords label{
color:green;
}
.search_location label{
color:green;
}
UPDATE
For input fields like chef,manager etc you can use
.search_keywords input{
//Your style here
}
or since you have id for the input field, use
#search_keywords{
//Style here
}
and for the submit button search, you can use the following,
.search_location input[type=submit]{
//style here
}

You can target by attribute and value:
label[for="search_keywords"]{ /* what label*/
background-color: red;
}
label[for="search_location"]{ /* where label */
background-color: blue;
}
input[type="submit"]{ /* search button */
background-color: green;
}
The color attribute refers to the text color, not the background colour.

Try attribute selectors
[for="search_keywords"],
[for="search_location"],
[name="filter_job_type[]"] {
color: green;
}
<div class="entry-content">
<p> </p>
<div class="entry-content">
<div class="job_listings" data-location="" data-keywords="" data-show_filters="true" data-show_pagination="false" data-per_page="10" data-orderby="featured" data-order="DESC" data-categories="">
<form class="job_filters">
<div class="search_jobs">
<div class="search_keywords">
<label for="search_keywords">What?</label><br />
<input id="search_keywords" name="search_keywords" type="text" value="" placeholder="Chef, Cleaner, Manager" />
</div>
<div class="search_location">
<label for="search_location">Where?</label><br />
<input id="search_location" name="search_location" type="text" value="" placeholder="London, Berlin, Bristol" />
<input name="filter_job_type[]" type="submit" value="search" />
</div>
</div>
<div class="showing_jobs"></div>
<div></div>
<div>
Post A Job
</div>
</form>
</div>
</div>
<p><a class="load_more_jobs" style="display: none;" href="#"><strong>Load more listings</strong></a></p>
</div>

Related

How to properly use nth-child css selector [duplicate]

This question already has answers here:
Why doesn't nth-of-type/nth-child work on nested elements?
(1 answer)
nth-of-type vs nth-child
(7 answers)
Closed 10 months ago.
I am trying to implement some css with nth child selector and unfortunately it's not working.
div.abc input:nth-child(3)
{
background: red;
color: red;
border: 1px solid red;
}
<div class="abc">
<p>This is some text.</p>
<div class="bc">
<input type="text"/>
</div>
<div class="bc">
<input type="text"/>
</div>
<div class="bc">
<input type="text"/>
</div>
<div class="bc">
<input type="text"/>
</div>
</div>
If you want the third input:
.abc div:nth-child(4) input
/* OR */
.abc div:nth-of-type(3) input
nth-child will seek all direct descendant tags so that would be:
<p> -> <div> -> <div> -> <div>
nth-of-type will seek all direct descendants of a specific type:
<div> -> <div> -> <div>
.abc div:nth-child(4) input {
color: gold;
}
.abc div:nth-of-type(3) input {
background: red;
border: 1px solid red;
}
<div class="abc">
<p>This is some text.</p>
<div class="bc">
<input type="text" />
</div>
<div class="bc">
<input type="text" />
</div>
<div class="bc">
<input type="text" value='TEST'/>
</div>
<div class="bc">
<input type="text" />
</div>
</div>
Your input tags are not siblings. They are wrapped in divs, so you need to select the nth-child of a div element and get the input inside that div.
.abc > div:nth-child(4) > input{
background: red;
color: yellow;
border: 1px solid red;
}
<div class="abc">
<p>This is some text.</p>
<div class="bc">
<input type="text" />
</div>
<div class="bc">
<input type="text" />
</div>
<div class="bc">
<input type="text" />
</div>
<div class="bc">
<input type="text" />
</div>
</div>
What your code is doing is not valid. nth-of-child is a selector for direct children of the parent container - in this case abc - and this parent element does not have any direct input-elements as children.
Instead, you need to target the bc-elements, as they are direct children of the the parent element abc, and then target the input.
In this example, I used nth-of-type. They are similiar, but nth-of-type targets DOM-elements directly, which are divs in this example.
div.abc .bc:nth-of-type(3) input {
background: red;
color: red;
border: 1px solid red;
}
<div class="abc">
<p>This is some text.</p>
<div class="bc">
<input type="text" />
</div>
<div class="bc">
<input type="text" />
</div>
<div class="bc">
<input type="text" />
</div>
<div class="bc">
<input type="text" />
</div>
</div>

How to format label and input tags

In my project, I have a dialog div with four labels, four text input, one submit button and one shutdow button.
I want it appears like this:
AAAAAAAA:input text
BBBBBBBB:input text
CCCCCCCC:input text
DDDDDDDD:input text
submit shutdown
But acturally, it does not appear format, it likes this:
AAAAAAAA:input text
BBBBBBBB:
input text
CCCCCCCC:input text
DDDDDDDD:
submit input text
shutdown
It is ugly, I don't want it like that.
Here is my css and html code:
<style>
.addDiv{width:25%;height:20%;position:absolute;top:35%;left:35%;border:2px solid #ffffff;color:white;display:none;border-radius:15px;background:rgba(0,0,0,0.7);}
.firDiv{height:80%;width:100%}
.firDiv label{float:left;margin-left:10%;margin-top:2%;width:20%}
.firDiv input{float:right;border:1px solid #99ccff;background:rgba(0,0,0,0.35);margin-right:10%;
margin-top:2%;color:white;width:45%}
.secDiv{height:20%;text-align:center;width:100%;margin-top:5%}
</style>
<div id="addCnt" class="addDiv">
<form action="mng.php?act=add&table=IDC" method="POST">
<div class="firDiv">
<label>AAAAAAA:</label><input type="text" name="prdSty"><br />
<label>BBBBBBB:</label><input type="text" name="diffLvl"><br />
<label>CCCCCCC:</label><input type="text" name="repTm"><br />
<label>DDDDDDD:</label><input type="text" name="fixTm"><br />
</div>
<div class="secDiv">
<input type="submit" value="add" /><input id="sdnBt" type="button" value="shutdown" >
</div>
</form>
</div>
Who can help me?
may be something like this?
* {
box-sizing: border-box;
}
.firDiv label {
padding: 5px;
text-align: right;
float: left;
width: 17%;
}
.firDiv .control {
float: left;
width: 83%;
}
.form-group {
clear: both
}
.secDiv {
margin-left: 16%;
padding-top:10px;
}
<form action="mng.php?act=add&table=IDC" method="POST">
<div class="firDiv">
<div class='form-group'>
<label>AAAAAAA:</label>
<div class='control'><input type="text" name="prdSty"></div>
</div>
<div class='form-group'>
<label>BBBBBBB:</label>
<div class='control'><input type="text" name="prdSty"></div>
</div>
<div class='form-group'>
<label>CCCCCCCC:</label>
<div class='control'><input type="text" name="prdSty"></div>
</div>
<div class='form-group'>
<label>DDDDDDDDD:</label>
<div class='control'><input type="text" name="prdSty"></div>
</div>
</div>
<div class="secDiv">
<input type="submit" value="add" />
<input id="sdnBt" type="button" value="shutdown">
</div>
</form>
Two things you need to do here. First you have to clear the floats after the first Div completed. Second is apply float left to your input fields.
.firDiv input{float:left;border:1px solid #99ccff;background:rgba(0,0,0,0.35);margin-right:10%;
margin-top:2%;color:white;width:45%;}
.secDiv{height:20%;text-align:center;width:100%;margin-top:10%; clear:both;}
I have applied clear:both in secDiv and float:left in firDiv.
DEMO
add this to your css fiddle
.secDiv input {
width: 50%;
}
Rather try adding each input and label to their own div, something like this:
https://jsfiddle.net/ba0cL61b/5/
What this does is adds a div .row inside your firDiv div and inside the .row adds a div for your label and one for your input. So it would look like this:
<div class="row">
<div class="label">
<label>AAAAAAA:</label>
</div>
<div class="input">
<input type="text" name="prdSty">
</div>
</div>
This is a bit easier to understand and style.

html tags in the same line do not work

In my html i have two input tags and i want them on the same line, after i search and try more code.
It doesn't change anything, what wrong is my code?
<div class="form-group">
<label class="col-lg-3 control-label">Meaning:</label>
<div class="col-lg-8">
<div class="">
<div class="lnw">
<span class="inline">
<input class="form-control" type="text" name="meaning[]" id="meaning " style="float: right">
<input type="image" src="/images/pjdict/plus.png" alt="Submit" width="48" height="48" class="add_field_button">
</span>
<br>
</div>
</div>
</div>
</div>
You have give some width for input["type="text"] or input["type="image"] like below:
Otherwise you cad custom class in form-control class and replease this class to .form-control
See Bootply link
.form-control {
float: left !important;
width: 90%;
}
.add_field_button {
float: right;
text-align: center;
width: 10%;
}
There is no need for a float:right in your code a form could simple be put
<input type="text">
<input type="text">
and they will show up beside each other also you should always put the type first
simply you can use display:inline-block to container of input tags
<html>
<body><div class="form-group">
<label class="col-lg-3 control-label">Meaning:</label>
<div class="col-lg-8">
<div class="">
<div class="lnw">
<span class="inline" style="display:inline-block"> //inline-block added here
<input class="form-control" type="text" name="meaning[]" id="meaning " style="float: right">
<input type="image" src="/images/pjdict/plus.png" alt="Submit" width="48" height="48" class="add_field_button">
</span>
<br>
</div>
</div>
</div>
</div>
</body>
</html>
Please use the below code for the same.
.inline input[type="text"] {
float:left;
margin:10px 10px 0px 0px;
}
<div class="form-group">
<label class="col-lg-3 control-label">Meaning:</label>
<div class="col-lg-8">
<div class="">
<div class="lnw">
<span class="inline">
<input class="form-control" type="text" name="meaning[]" id="meaning " >
<input type="image" src="/images/pjdict/plus.png" alt="Submit" width="48" height="48" class="add_field_button">
</span>
<br>
</div>
</div>
</div>
</div>
You are setting the type of your input field to 'image', which according to this page isn't valid in bootstrap, and in general isn't valid for html. I can only guess what you're trying to do, but from the way things look, you want:
a text input field
a submit button to the right of the text input field
an image instead of the regular submit button appearance
If that is accurate, take a look at the following snippet:
#formElementContainer {
margin-top: 60px; /* this is only important for display within this snippet */
}
#formElementContainer input[type='text'] {
width: calc(100% - 50px);
}
#formElementContainer input[type='submit'] {
background: transparent url('https://www.gravatar.com/avatar/eb603bf5dd01c06880fdb8e4e1d04df3?s=32&d=identicon&r=PG&f=1') center center no-repeat;
border: none;
width: 32px;
height: 32px;
}
<div id="formElementContainer">
<input type="text" />
<input type="submit" value="" />
</div>

how to display 3 input box with text & submit button in a row

Following is the code :
in this code the 1st box is not coming in a row else other 2 are having no problem
<div class="foo">
<div class="bar">1<input id="J" type="textt" style="width:40% height:20%" autocomplete="off" autofocus class="textboxx"/>
</div>
<div class="bar"><input type="submit"></div>
</div>
</br>
<div class="bar">2<input id="J" type="textt" style="width:40% height:20%" autocomplete="off" autofocus class="textboxx"/>
</div>
<div class="bar"><input type="submit"></div>
</div>
</br>
<div class="bar">3<input id="J" type="textt" style="width:40% height:20%" autocomplete="off" autofocus class="textboxx"/>
</div>
<div class="bar"><input type="submit"></div>
</div>
& the CSS
.foo {
display: table;
width: 100%;
}
.bar {
display: table-cell;
}
.bar:first-child, input[type="text"] {
width: 20%;
}
input {
box-sizing: border-box;
}
Help regarding this asap.
Check this Fiddle
CSS:
.foo {
display: block;
width: 100%;
}
.row
{
display:block;
}
.bar {
display: inline-block;
}
input {
box-sizing: border-box;
}
HTML:
<div class="foo">
<div class = "row">
<div class="bar"> 1
<input id="J" type="text" style="width:40% height:20%" autocomplete="off" autofocus class="textboxx"/>
</div>
<div class="bar"><input type="submit"/></div>
</div>
<div class = "row">
<div class="bar"> 2
<input id="J" type="text" style="width:40% height:20%" autocomplete="off" autofocus class="textboxx"/>
</div>
<div class="bar"><input type="submit"/></div>
</div>
<div class = "row">
<div class="bar"> 3
<input id="J" type="text" style="width:40% height:20%" autocomplete="off" autofocus class="textboxx"/>
</div>
<div class="bar"><input type="submit"/></div>
</div>
just change the width from 20px to 29.5%
.bar:first-child, input[type="text"] {
width: 29.5%;
}
DEMO:http://jsfiddle.net/LrshX/
use table instead of div. give every input in a
<td> <input type ="text"\> <\td>
tag
Change foo class from display:table to display:inline
I think you are overcomplicating things for no reason. And you have messed up (somewhat) your HTML tags, your CSS styles etc.
What (I believe) you are after, could be achieved (among many ways) like this:
HTML
<div class="foo">
<div class="bar">
1
<input type="text" id="J1" class="textbox"
autocomplete="off" autofocus />
</div>
<div class="bar"><input type="submit" /></div>
</div>
<br />
...
CSS
.foo {
display: table;
width: 100%;
}
.bar { display: table-cell; }
.bar:first-child { width: 20%; }
input[type="text"] { width: 80%; }
See, also, this short demo.
Some additional remarks:
Do not use the same id on multiple elements in your DOM, or you're very likely to experience unexpected behaviour.
If you use autofocus on all text-fields, the ladt one will receive the focus.
If you want your submit buttons to actually do something, don't forget to include them in form or bind them using JavaScript.

HTML how to place a form in 2 divs/columns?

I have 1 form and I would like to place it in 2 divs, so that the following:
<div style="float:left; position:relative; margin-right:40px">
<form id="testForm2">
</form>
</div>
<div position:relative">
<form id="testForm2">
</form>
</div>
would be turned into something like this:
<div style="float:left; position:relative; margin-right:40px">
<form id="testForm2">
</div>
<div position:relative">
</form>
</div>
See the fiddle. Any ideas?
Thanks!
What you want, is to put the form around both divs like so:
<form id="testForm2">
<div style="float:left; position:relative; margin-right:40px">
</div>
<div style="position:relative">
</div>
</form>
Here's an updated version of your jsFiddle.
Edit
Also, your second div's style is incorrect. It's fixed now in my example.
The markup in your jsFiddle file required some tidying up. This is what i would go with, trying to minimize your code somewhat:
<div class="post_edit_modeling">
<div class="tab_trash">
<div id="prof_picture">
<form id="testForm2">
<fieldset id="left">
<legend>Sex:</legend>
<div>
<label>
<input type="radio" name="sex" id="genderMale" value="male" />
Male
</label>
</div>
<div>
<label>
<input type="radio" name="sex" id="genderFemale" value="female" />
Female
</label>
</div>
<div>
<label>Weight</label>
<input id="weightpounds" type="text" name="weightpounds"/>
</div>
<div>
<label>Bust</label>
<input id="bust" type="text" name="bust"/>
</div>
</fieldset>
<fieldset id="right">
<div>
<label>Cup</label>
<input id="cup" type="text" name="cup"/>
</div>
<div>
<label>Waist</label>
<input id="waist" type="text" name="waist"/>
</div>
<div>
<label>Hips</label>
<input id="hips" type="text" name="hips"/>
</div>
<div>
<label>Hair Color</label>
<select name="haircolor">
<option value="1">White</option>
<option value="2">Black</option>
<option value="3">Yellow</option>
<option value="4">Blue</option>
</select>
</div>
<div>
<label>Dress Size</label>
<input id="dress" type="text" name="dress"/>
</div>
</fieldset>
<fieldset>
<div>
<input type="button" name="btnUpdate" id="btnUpdate" value="Update" />
</div>
</fieldset>
</form>
</div>
</div>
</div>
CSS:
form div {float: left; margin-bottom: 15px;}
fieldset { float: left; width: 200px; border: 0; padding: 0; margin: 0;}
#left { }
#right { margin-right: 0; }
label {float: left;}
input {clear: both;; float: left}
Ive updated your jsFiddle file. Here.
Can you not just make the two divs live inside the form? Like this:
<form id="testForm2">
<div style="float:left; position:relative; margin-right:40px">
Form Content Here
</div>
<div position:relative">
Form Content Here
</div>
</form>
If the form is affecting your page layout, make sure that you set the form style to display:inline;!
As Drackir and joe_coolish said, you don't need to nest your form tags that way.
Typically I always open the entire content block with the form tag, totally isolated from the other content. There's absolutely no harm in doing things this way. ANything including <h1> and entire layouts can be nested in a form, as long as you know that every input within it will belong to that form.
<form>
<!-- tons of content here including layout -->
</form>
Can't you just put the 2 DIV's inside the FORM tags? Something like:
<form>
<div id="one">
...
</div>
<div id="two">
</div>
</form>
edit: Seems I'm a little too late :)
Just move your <div> tags within the <form>...
<form id="testForm2">
<div style="float:left; position:relative; margin-right:40px">
... left side ...
</div>
<div position:relative">
... right side ...
</div>
</form>
what about
<form id="testForm2">
<div style="float:left; position:relative; margin-right:40px">
</div>
<div position:relative">
</div>
</form>