WordPress.org

Ready to get started?Download WordPress

Forums

Limiting the scope of unknown/dynamic CSS to a specific (2 posts)

  1. hunterhogan
    Member
    Posted 2 months ago #

    This issue is really about CSS, but I have this issue because of a complex interaction of WordPress components, so I'll post here first.

    The example page is here.

    Locating the code I want to affect
    Find the area <h1>Email message</h1>. On some pages, I use custom fields created with the awesome plugin, Advanced Custom Fields. (I'm also using the add-on, Advanced Custom Fields: Date and Time Picker, but that doesn't affect my issue.) For pages that use these custom fields, the "Email message" is an email from someone and it might be formatted using HTML.

    I want to:

    1. preserve the HTML of the original email, and
    2. not change the HTML of the rest of the page, and
    3. not use iframe or embed or anything that requires me to create an extra file or is not search-engine friendly

    For now, I have enclosed the original email message in a <div> container. You can see the container is <div id="email_post_is_an_email">.

    The CSS for the Email message is in <head>
    Using Advanced Custom Fields, I created a Text Area field named email_internal_style_sheet. The field has a conditional check: it only appears if the Advanced Custom Fields's field email_html_formatted is checked.

    In header.php, I put the following code after wp_head(). (I did it on purpose. I would prefer to hook into wp_head, but I have limited time. One issue at a time, OK?)

    <?php if( get_field( 'email_html_formatted' ) ) { echo '<style>' . get_field( 'email_internal_style_sheet' ) . '</style>'; } ?>

    If you look at the example page, you will see in <head>

    <!-- For email_posts, special styling, move to a hook for wp_head -->
    <style> P {
    font-family : Arial, Helvetica, sans-serif;
    font-size : 12pt;
    text-align : justify;
    }
    TR {
    font-family : Arial, Helvetica, sans-serif;
    font-size : 11pt;
    text-align : left;
    }</style>

    The problem: it overrides my stylesheets
    This is the heart of the problem. The Email message uses <P>, and it overrides all of my other <P> definitions. If this were the only post like this, then I could easily fix it using dozens of methods. I could, for example create a style called p.email_post_is_an_email and modify things.

    I have thousands of emails, however, that I will bulk import, and I do not want to modify every email's stylesheet. (If you care, I have been using WP Ultimate CSV Importer. I haven't looked at other options.)

    The solution? An easy method to limit the style of Email message to only the Email message
    The first solution I thought of was CSS selectors. Using the current page as an example, it would be great if I could somehow define
    #email_post_is_an_email P {[style definition]}
    because that would limit the style to <P> elements that were inside <div id="email_post_is_an_email">.

    But the content of $email_internal_style_sheet is dynamic. It might have two elements or it might have hundreds of elements. I don't know of a CSS selector that does what I want to do. I knew it wasn't valid, but I still tried:

    <style>
    #email_post_is_an_email {
    P {
    font-family : Arial, Helvetica, sans-serif;
    font-size : 12pt;
    text-align : justify;
    }
    TR {
    font-family : Arial, Helvetica, sans-serif;
    font-size : 11pt;
    text-align : left;
    }}
    </style>

    http://jigsaw.w3.org/css-validator gave a parse error, of course.

    Ideas?
    I'm not strong at scripting. I started hand coding HTML and then CSS in 1996, but I switched careers in 2005. I've regained my HTML and CSS skills, but this is my first experience with WordPress or PHP, so my learning curve has been steep.

    I've learned enough to expanded my website from ~750 pages by adding ~3800 posts and ~4500 attachments, but I still have 7,000-15,000 more posts to add. I've had to learn many new skills and technologies, and I am trying to limit the number of new languages I learn, you know?

    I want to get this crap published and move on with my life.

    Suggestions? Other information that would help you to help me?

  2. hunterhogan
    Member
    Posted 2 months ago #

    A step in the right direction?

    I embed PDFs using a dynamic method with a strange set of selection rules. My intuition tells me that something like this might work, but my brain is fried right now.

    On this page, I use

    <section class="embed-make-fluid embed-size-pdf [irrelevant class]">
    <embed src=[path]>
    </section>

    The external stylesheet has the relevant CSS

    .embed-make-fluid{border-radius:0;
    height:0;
    padding:0;
    position:relative;}
    .embed-make-fluid>*{height:100%;
    left:0;
    position:absolute;
    top:0;
    width:100%;}
    .embed-size-pdf{height:200%;
    padding-bottom:66.667%;}

    Argh! I feel that the answer is in there somewhere.

    What if I did something lame like
    #email_post_is_an_email>* for the CSS in $email_internal_style_sheet? But it has to be the inverse of that right? *sigh* I need coffee, a nap, or both. There has to be something here.

Reply

You must log in to post.

About this Topic