Grow your CSS skills. Land your dream job.

How Target Specific H2 Within Specific DIV? – Thanks!

  • # February 11, 2013 at 11:14 pm

    I’m trying to target a specific H2 tag that’s within a DIV, how do I do it?

    is this correct?

    .divname h2 { }

    # February 11, 2013 at 11:21 pm

    @hendrix940, that targets all h2′s within `.divname`, if you need specificity, let me see the code in use and I might be able to help. http://codepen.io

    # February 11, 2013 at 11:25 pm

    I don’t know how to embed the CODEPEN … here’s the link

    http://cdpn.io/Bzktu

    # February 11, 2013 at 11:29 pm

    no that didn’t work.

    # February 11, 2013 at 11:32 pm
    <div class="column-center-outer">
    <div class="column-center-inner">
    <div id="main" class="main section">
    <div id="Blog1" class="widget Blog">
    <div class="blog-posts hfeed">
    <div class="date-outer">
    <h2 class="date-header">
    <span>Monday, February 4, 2013</span>
    Check out this Pen!

    # February 11, 2013 at 11:32 pm

    @hendrix940, in that case that you provided the selector would be `h2.date-header span`

    If you’re trying to target a specific h2 _within_ a div, and the h2 doesn’t have a specific class like the `.date-header` in your example, you could pick it with the `:nth-child` selector.. http://codepen.io/ChrisPlz/pen/psfdD

    # February 11, 2013 at 11:34 pm

    Okay, there it is @chrisp thank you very much for your help. I’m trying to get the date ‘MONDAY, FEB 4, 2013′ to align LEFT. … AND i’ve already targeted the H2 tag to align RIGHT … so I need to specifically target the H2 within class ‘DATE-HEADER’

    # February 11, 2013 at 11:35 pm

    AH okay, great thank you very much sir!

    # February 11, 2013 at 11:41 pm

    @chrisp … what am I doing wrong sir?

    h2.date-header span {
    text-align: right;
    }
    Check out this Pen!

    # February 11, 2013 at 11:44 pm

    @hendrix940, you gotta put the css in that comment in to the pen, also, `span` is an inline element, so you’re better off leaving the span out.

    http://codepen.io/ChrisPlz/pen/gvKeE

    # February 11, 2013 at 11:49 pm

    Okay I understand. I’m test now. Thank you very much.

    # February 11, 2013 at 11:58 pm

    Excellent. Got it! Thanks!

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".