WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Center HTML in Twenty Eleven theme (9 posts)

  1. thebookreporter
    Member
    Posted 1 year ago #

    I am trying to center a line of html code (for a blogads ad) in my Twenty Eleven theme. I have been consulting the forums on this topic over the past 2 days but nothing has worked.

    Specifically, I have tried sandwiching the code with <div align=center></div>, and <div style="text-align: center;"></div>, and I have also tried creating a class in my CSS for centering text, using .alignCenter {margin: 0 auto;} and then sandwiching my code with the new class (again using <div...></div>. Nothing has worked. Most often the ad gets placed behind the foreground frame of my blog and way off to the right.

    I have a class in my CSS that seems to be meant for centering things but sandwiching my code with this class (again using div) doesn't work either. Here's the CSS code:
    .aligncenter {
    clear: both;
    display: block;
    margin-left: auto;
    margin-right: auto;
    }

    Totally lost here, any help would be greatly appreciated!!

  2. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    Can you post a link to your page where this is? It's impossible to help with CSS issues without seeing it live.

    Or try using a browser tool such as Firebug to see what's going on with the CSS.

  3. thebookreporter
    Member
    Posted 1 year ago #

    Thanks for your response. The site is here: http://newbooksinbrief.com/

    The content I'm trying to center is just beneath the main header.

  4. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    I can help you with that, but looks like you don't have a child theme - which means that any changes you've made to theme files are going to be overwritten when WP is updated. Have you been modifying files?

  5. thebookreporter
    Member
    Posted 1 year ago #

    Well, the only modification I've made was to add this code for the ad space. I didn't think I would need to create a child theme unless I was modifying the structure of the theme itself. Am I wrong about this?

  6. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    Yes, any changes you make to any theme files will generally be overwritten, so it's really best to use a Child Theme. You can, of course, keep a copy of your files and then redo the changes, but that's less than ideal. For CSS changes, you can also use a custom CSS plugin such as JetPack instead of a Child Theme, but for the ad, yes, a child theme would be the best approach.

  7. thebookreporter
    Member
    Posted 1 year ago #

    O.k., good to know. Thank you. I'm now running a twenty eleven child theme. Now, how can I center that ad?

  8. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    Excellent - Child Themes make us so happy around here :). So see if adding this to the new style.css file does it:

    div#adspot_935376471.adspot {
       margin: 0 auto;
    }
  9. thebookreporter
    Member
    Posted 1 year ago #

    It worked! And looks great!! Thank you so much, you're a life-saver.

    Cheers,
    Aaron

Topic Closed

This topic has been closed to new replies.

About this Topic