Created
August 16, 2019 11:24
-
-
Save FreshLondon/0dfc39609edb3671ef2d5d675645d4c2 to your computer and use it in GitHub Desktop.
Convert hexdec color string to rgb(a) string > USAGE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// Here's a usage example how to use this function for dynamicaly created CSS | |
$color = '#ffa226'; | |
$rgb = hex2rgba($color); | |
$rgba = hex2rgba($color, 0.7); | |
// CSS output | |
echo ' | |
div.example{ | |
background: '.$rgb.'; | |
color: '.$rgba.'; | |
} | |
'; | |
// Online ACF style outputs: | |
$navigation_background_colour = get_field('navigation_background_colour', 'options-header'); | |
$navigation_background_opacity = get_field('navigation_background_opacity', 'options-header'); | |
if ($navigation_background_opacity): | |
$nav_bg_color = hex2rgba($navigation_background_colour, $navigation_background_opacity / 100); | |
else : | |
$nav_bg_color = hex2rgba($navigation_background_colour); | |
endif; | |
?> | |
<nav style="background-color: <?= $nav_bg_color; ?>;"></nav> | |
<? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment