Support

Account

Home Forums General Issues Field Styling

Solving

Field Styling

  • Ok first off i am using Headway Theme.

    I am wondering if there is any way possible to remove the css styling of a field if no content has been entered. i am using individual content blocks that included the php to pull up the field content if there is any but the styling still remains. i included a link as an example. you can see the field is empty but the background styling is still there. I am by all means not an expert as i am learning. I have been rattling my brain on this for sometime now. Thanks in advance!

    http://harbormediatest.com/review/boodles-test/

  • Hi @shamr0ck79

    I’m not entirely understanding how your code is setup but my guess is that you just need an if statement around each block.

    if you do something like

    
    if( get_field('fieldname') ){
    	
    	//Place the entire blocks html structure etc. in here. 	
    }
    
    

    Nothing will appear unless there’s an actual value.

  • This is the code i have in each block:

    <?php

    if(get_field(‘style’))
    {
    echo ‘<h2>Style</h2>’ . ‘<p>’ . get_field(‘style’) . ‘</p>’;
    }

    ?>

    Again, if no text is entered into the field nothing shows up, but the CSS styling still remains. I no NOTHING about PHP maybe i need to style each field through PHP?

  • … and this is the CSS Styling…

    custom-code {
    background-color: rgba(212,212,212,0.72);
    border-top-left-radius: 0px;
    border-top-right-radius: 25px;
    }

  • Hi,

    Ah okay. Well your CSS is then targetting an outer element outside of that if statement. This is really not something related to ACF but I’ll try to help you anyway.

    Make sure that your if statement is truly outside of all HTML related to each field. So in your case it should be outside of “custom-code”.

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

The topic ‘Field Styling’ is closed to new replies.