Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1082503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:18:30+00:00 2026-05-16T22:18:30+00:00

Ok, I have code like this: <div id=header> (yeah, have to use div instead

  • 0

Ok, I have code like this:

<div id="header"> (yeah, have to use div instead of header tag, don't ask me why)
     <a href="link"><img src="image1.png" alt="image1" /></a>
     <a href="link"><img src="image2.png" alt="image2" /></a>
     <a href="link"><img src="image3.png" alt="image3" /></a>
</div>

And I want to select the first image after div (first link image) and two last links in css.

I know I could do it by nth-child or first/last child selectors. But I want to use “+” and “~”. But they doesn’t seem to work!

For example:

#header + a {
     border: solid 1px red;
}

Gives border to… Nothing!

This one also doesn’t seem to work:

#header a + img {
     border: solid 1px red;
}

What’s wrong?

Same effect with “~”. Tested in all major browsers….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:18:32+00:00Added an answer on May 16, 2026 at 10:18 pm

    You’ve got it wrong. The selector you’re looking for is

    #header > a:first-child
    

    This will select the first anchor that are direct decedent of #header. The > is the direct decedent selector, while :first-child gets you the… well, first child. To get the image, you would need

    #header > a:first-child > img
    

    The direct decendent selector is not supported in IE6. You can choose not to use it if there are no non-direct decedents you would not want to select, like with the structure you have above, which doesn’t have any other anchors other than the ones you want to select.

    The + is the adjacent sibling selector: http://meyerweb.com/eric/articles/webrev/200007a.html. The following HTML structure is what you would need for your selector to work:

    <div id="header"></div>
    <a href="#"><img src="somewhere" alt="" /></a> <-- Selects this one for #header + a
    <a href="#"><img src="somewhere" alt="" /></a>
    <a href="#"><img src="somewhere" alt="" /></a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that looks like this: <div id="header"> <ul class="tabs"> <li><a href="/user/view"><span class="tab">Profile</span></a></li>
I have some code generated by a CMS: <div class=block> <a class=link href=#>Link</a> <h4>Header
I have Repeater Control and in that i have code like this <div runat=server
I have nav code like this in my HTML file: <div id="center_links"> <ul> <li><a
I have a code like this $(document).ready(function(){ $(.add).bind ('click', function () { $('.main').append('<div class=add>Add
I have a piece of code like this: <div id=container runat=server> <div id=parent runat=server>
Within my code I have list items like this; <div id=content> <ul class=kwicks> <li
I have a form like this <div data-role=page id=callAjaxPage> <div data-role=header> <h1>Login</h1> </div> <div
I have a basic code like this (that duplicates several times): <h3 class=header>The header</h3>
I have this code on a login page: <div id=header> <div id=homeBanner> ... </div>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.