473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

first-child on form elements

damir
14
Expand|Select|Wrap|Line Numbers
  1. <div class="box-title">
  2.                <h3>Login</h3>
  3.                <label>Username:</label>
  4.                <input type="text" name="username" />
  5.                <label>Password:</label>
  6.                <input type="password" name="pass" />
  7.             </div>
I have a situation as above where there are two form elements (two imputs with labels). Now I can't make :first-child to work with form elements, neither with labels nor inputs.

Can somebody help me with this?
Dec 1 '10 #1
5 5500
JKing
1,206 Expert 1GB
This is because the h3 tag is the first child in the example you have given.
Dec 1 '10 #2
damir
14
Yes, h3 is the first child, but if I put
Expand|Select|Wrap|Line Numbers
  1. .box-title label:first-child{}
it won't work. Not even with input, but if I put more h3's it works normally.

--
i've tested without h3 and it works normally. will have to find how to select the first label beside the elements before him.
Dec 1 '10 #3
JKing
1,206 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. .box-title label:first-child{}
This will only work if your structure looks like this
Expand|Select|Wrap|Line Numbers
  1. <div class="box-title">
  2. <label>First Child</label>
  3. <h3>Second Child</h3>
  4. </div>
  5.  
The label has to be the first nested element.
Dec 1 '10 #4
damir
14
Ok, I got it. But how to make if labels are nested anywhere inside the div and then to select the first of them?
Dec 1 '10 #5
JKing
1,206 Expert 1GB
There is a couple things you can do.

1) You can make a class and apply it to the elements you want.

Expand|Select|Wrap|Line Numbers
  1. .myclass {}
Expand|Select|Wrap|Line Numbers
  1. <div>
  2. <label class="myclass">This is a label</label>
  3. <label>This label has no class.</label>
  4. </div>
  5.  
2) CSS also has an nth:child pseudo class which can be used as follows
Expand|Select|Wrap|Line Numbers
  1. .box-title label:nth-child(2){}
  2.  
That would select all the second children. The only problem with this is it is not fully supported by IE.

3) For cross browser compatibility using the nth:child selector you could use jquery to accomplish the same thing.
Dec 1 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: user | last post by:
when i first load index.php with arguments ie: "index.php?page=x", the $_SERVERvalue is null. I then get the session id appended to each link. If i refresh the page, I get the $_SERVER I want, but...
3
by: bettina | last post by:
How should it be named the first site in a website in PHP? Is there any special rule? index.php for example? I would like to know how it functions that by giving the wed address (www.jfdhjdfh.de...
24
by: Hung Jung Lu | last post by:
Hi, Does anybody know where this term comes from? "First-class object" means "something passable as an argument in a function call", but I fail to see the connection with "object class" or...
1
by: Patrick | last post by:
I am trying to get "first-letter" to work inline withing an anchor. Actually I have not been able to get it to work within an <a> tag whether inline, linked, or embedded. Using IE6 service pack 1....
3
by: Chris Tanger | last post by:
I am creating a class that has a method "Write" that I wish to make threadsafe. The method must block calling threads until the task performed in write is complete. Only 1 thread at a time can...
4
by: KJ | last post by:
We use a third party software package for acctg that limits us on field size - as a result, we at times have to enter an item into the app multiple times in order to get all the information. I...
43
by: Roger L. Cauvin | last post by:
Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. "xyz123aaabbaabbbbababbbbaaabb" I'm...
4
by: Milan Krejci | last post by:
int first=15,latest=15; QString typ=NULL; std::map<int,std::string>::iterator i; for(i = SeznamPracovniDoby.begin(); i != SeznamPracovniDoby.end(); i++) { if (typ==NULL) typ=i->second.c_str(); if...
3
by: cs | last post by:
Hi, I'm new to C and would appreciate any feedback on the following program, asplit, which splits a file into 2 new files, putting a certain number of lines in the first file, and all the rest...
3
by: dmalhotr2001 | last post by:
Hi, For string extraction function in vb, if I feed in a paragraph, how do I extract the first sentence of that paragraph. Thanks :D
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.