If you’re calling a dynamic css inline style does that div have to be in the loop?

The way i formatted this question is wrong, i was trying to embed a dynamic CSS property value inline within a div referencing a color value from a custom field. In this particular case yes i did have to include the div, with the inline style that was calling the value of the property, within the loop otherwise it wouldn’t retrieve the data(color value) dynamically.

 <?php

  $args = array(
    'post_type' => 'neighborhood',
    'posts_per_page' => 1,
    );

  $the_query = new WP_Query( $args );

  ?>


  <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

    <div class="container-hdr" style="background-color: <?php the_field( 'bg_clr' ); ?>"> <!--the_field(); is a specific function to the ACF Advanced Custom Fields plugin that is referencing the post type 'neighborhood'-->

This still doesn’t solve another problem that i’ll be posting soon, that is how do i make the background color dynamic based on different posts that may have custom colors entered by a color picker. This option here will allow you to change the background color from the admin but make a global change based on any number of header templates that you create.