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

  • SEARCH
  • Home
  • 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 650561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:04:00+00:00 2026-05-13T22:04:00+00:00

With the example below, I need to add padding and background-color properties to the

  • 0

With the example below, I need to add padding and background-color properties to the text anchor. I then need to exclude padding and background-color from anchors that contain images.

<p>
  <a href="#">this is a text link that needs to be styled</a>
  <a href="#"><img src="image/name.jpg" alt="this needs to be excluded from styling" /></a>
</p>

If I have a red background and padding on my text links, I do not want that same red background and padding to appear on my linked images. The images will always be in their own anchors, not mixed with text within the same anchor.

The rub is that I can not add classes or IDs to the img tags – I do not have edit control of that data.

So how can I add CSS attributes to all anchors, while excluding anchors that contain images?

  • 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-13T22:04:00+00:00Added an answer on May 13, 2026 at 10:04 pm

    Currently, you cannot select the parent of a matched child selector. You’ll have to use javascript to accomplish this.

    That being said, if your page background is solid, you could use negative margins and a background on your img tags to overlay your a background… Here’s the example. I have not tested on all browsers, but it seems to work for me in Safari, Firefox, and MSIE8.

    a {
       display: inline;
       padding:10px;
       background:red;
    }
    
    a img {
       border: none;
       vertical-align: bottom;
       margin:-10px;
       padding: 0px;
       background:white;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The example below, is just an example, I know that I don't need an
Tech used: PHP 5.3.10 Hi, I have an array (example below) I need to
The example below is from a REST database driver on Python 2.7. In the
I need to know code to fix my example below to initiate a method
I have added multi-language using the short article below. When you add for example
I need to create instances of a custom object (Bar in the example below)
I need some web.config examples for each expression types below : $number The last
this example below works when hover event is trigered and when its not, its
The example below shows the code I am using to test whether a user
JSFIDDLE EXAMPLE BELOW I want to make the following CSS layout and currently im

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.