Display hexadecimal color with php coming MySQL

-2

I would like to display on a page that I am developing a hexadecimal value that is stored in my database. I did some testing but no success.

I tried to do something like this:

<?php echo "background-color:".$ProdCor->Cor;.""; ?>

The value in the bank field looks like this:

#ffff00

I'm trying to show the color in a page field.

The CSS that is related to the field is this:

.tovar_color_select {padding-bottom:19px;}
.tovar_color_select p {
    margin-bottom:13px;
    text-transform:uppercase;
    font-weight:900;
    font-size:12px;
    color:#333;
}
.tovar_color_select a {
    position:relative;
    display:inline-block;
    margin-right:10px;
    width:32px;
    height:22px;
}

.tovar_color_select a:before { content:''; position:absolute; left:-4px; top:-4px; right:-4px; bottom:-4px; border:1px solid #e9e9e9; transition: all 0.1s ease-in-out; -webkit-transition: all 0.1s ease-in-out; } .tovar_color_select a:hover:before, .tovar_color_select a.active:before { border:2px solid #333; }

A tag completa é essa:

<div class="tovar_color_select"> <p>SELECIONE A COR</p> <?php foreach($ResCor as $ProdCor ) { ?> <a href="javascript:void(0);" ><?php echo "background-color:".$ProdCor->Cor; ?></a> <?php } ?>

    
asked by anonymous 14.08.2018 / 23:19

1 answer

1

Try this:

<?php foreach($ResCor as $ProdCor ) { ?>
    <a href="javascript:void(0);">
      <div style="background-color: <?= $ProdCor->Cor ?>; width: 100px; height: 100px;"></div>
    </a>
<?php } ?>

I created a div by adding the css inline , where I set the color of the background that comes with PHP and fixed its dimensions. It is important to remember to define the dimensions because if you do not put any characters inside, div will not have a width nor a height , so there will be no space for background to fill with the desired color. / p>     

15.08.2018 / 13:23