3

I'm trying to write a custom style for a website and am running into a bit of trouble. The following bit of code appears a lot, and I need to remove the float attribute of the span. There are other spans on the page inside <td> elements with floats that must stay untouched, and CSS doesn't have any parent selectors. I can't edit the html in anyway or add any Javascript. What can I do?

<table class="forum_post box vertical_margin" id="post00001">
   <tbody>
     <tr class="colhead-dark">
       <td colspan="2">
         <span style="float: left">
           <a class="post_id" href="stuff.com">text</a>
       </span>
     </td>
   </tbody>
</table>
6
  • side note: 1. <td> without <tr> ? double check your HTML. 2. <tbody> is optional 3. <a href> without http:// ?
    – Raptor
    Aug 12, 2015 at 3:56
  • 1
  • Apologies I retyped all of this. And I know I have to use the !important flag, I'm not sure how to select the <span>
    – Ian Hyzy
    Aug 12, 2015 at 4:01
  • @Ian Hyzy does my answer work?
    – zer00ne
    Aug 12, 2015 at 4:02
  • @zer00ne No, and I tried modifying it to fit the new HTML in the post.
    – Ian Hyzy
    Aug 12, 2015 at 4:04

1 Answer 1

5

.box > tbody > tr > td > span { float: none !important; }

This says:

Find all

  1. spans that are the direct descendant (child) of a...
  2. td which is a child of a...
  3. tr which in turn is a child of...
  4. tbody and finally it being the one and only child of...
  5. table

OR maybe ...

span[style*="float"] { float: none !important; }

This says:

Any span with an attribute of style containing the word float. rel *=[external]

4
  • Second answer did the trick, thank you! Can you explain what it does?
    – Ian Hyzy
    Aug 12, 2015 at 4:08
  • Whoa sorry, spoke a bit too soon. This breaks a lot of stuff on other pages.
    – Ian Hyzy
    Aug 12, 2015 at 4:13
  • Are you adding this style to a shared external sheet?
    – zer00ne
    Aug 12, 2015 at 4:15
  • Yes. It applies globally on the site. I just tried your first suggestion again after fixing a typo somewhere else and that seems to have done it. Thanks and sorry for the confusion.
    – Ian Hyzy
    Aug 12, 2015 at 4:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.