Solved

CSS.. Using first child selectors in Internet Explorer.

Posted on 2007-04-03
5
1,170 Views
Last Modified: 2012-06-27
I am curious if there is a way to reference first-child attributes in CSS for Internet Explorer. It seems to work well with Firefox but not with any version of IE. Currently the code looks like this:

CSS code:

#bodyText > div:first-child {
      border:none;
}

HTML code:

<div id="bodyText" visible="true">
      
      <div><a href="#">link1</a></div>

      <div><a href="#">link2</a></div>


The border still shows up in IE 6 and 7 but not FF. Maybe there is some kind of small hack to get it to work?
0
Comment
Question by:dgelinas
  • 3
5 Comments
 
LVL 14

Expert Comment

by:xberry
ID: 18844642
The first-child attribute cannot be used with IE versions up to IE 6, see this diagram:

http://www.css4you.de/browsercomp.html
0
 
LVL 14

Expert Comment

by:xberry
ID: 18844776
Apart from that: >> The border still shows up ...

which border ?
0
 
LVL 6

Author Comment

by:dgelinas
ID: 18844817
<style type="text/css">

body {
      font-family:Arial, Helvetica, sans-serif;
      font-size:12px;
}

#bodyText div {
      float:left;
      margin-right:10px;
      display:block;
      border-left:1px solid #000;
      padding-left:10px;
}

#bodyText > div:first-child {
      border:none;
}

#titleText {
      font-size:17px;
      margin-left:auto;
      margin-right:auto;
      margin-bottom:8px;
      position:relative;
      font-weight:bold;
      width:600px;
      text-align:center;
}

#bodyText {
      margin-left:auto;
      margin-right:auto;
      position:relative;
      width:600px;
      text-align:center;
      left:78px;
}

</style>

<div id="titleText">Get your degree fast!! Browse 648 degrees in Information Systems</div>

<div id="bodyText" visible="true">
      
      <div><a href="http://">Associates</a></div>

      <div><a href="http://">Bachelors</a></div>

      <div><a href="http://">Doctorate</a></div>

      <div><a href="http://">Masters</a></div>

      <div><a href="http://">Professional Certificates</a></div>

</div>
0
 
LVL 14

Accepted Solution

by:
xberry earned 500 total points
ID: 18845282
Ok, see it now.
Actually, I strongly refrain from considering any hack for the first-child CSS attribute.
Reason is, from information I found about the problem of IE 7 being able
to process any first-child hacks: it seems that first IE 7 versions can't process
hacks made for IE 6, but if you would create any hack exclusively for IE 7, then
in any modified IE 7 version (which is likely to happen) it could be that that version
would again go blind about the hack you inplemented. So risk is that any future IE version
would simpl not be able to handle any hack implemented here. Preventing any risk
for IE users, simply solve it the 'simple' way here:
style area

div#first_child{
      border:none;

....

<div id="first_child"><a href="http://">Associates</a></div>

<div><a href="http://">Bachelors</a></div>

and so on . . .

...

Sure not as elegant as you'd like, but safe
and working and since you want to make use of <div> around your <a>'s
why not use them for your exclusive first-child purpose in a 'moderate' semantic way
that can be used by all browsers? ; )
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now