[Tex/LaTex] How to customize color in tcolorbox having counter

macrostcolorbox

I am new to the LaTeX. I want to customize tcolorbox for custom title with auto counter and background colour as per my choice say light red.
Also I want to change the font colour of title and inside text contents also as per my choice to say dark red/blue. How can I do this. Please help.

The basic MWE is as provided by feculededentier in the below link page

I have found this page Example numbers with respect to chapters in tcolorbox title

Best Answer

To very first approximation I would just take the answer you refer to, remove the chapter stuff and add the colors.

\documentclass{article}
\usepackage{etoolbox}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable}
\usepackage{lipsum}

\tcbset{mytitle/.style={title={Example~\thetcbcounter\ifstrempty{#1}{}{: #1}}}}
\newtcolorbox[auto counter, number within=chapter, 
number freestyle={\noexpand\arabic{\tcbcounter}}]{myexample}[1][]{%
    enhanced,
    breakable,
    fonttitle=\bfseries,
    mytitle={},
    #1
}

\begin{document}


\begin{myexample}[colback=red!5!white,colframe=red!75!black,mytitle={First example}, label=exfirst]
  \lipsum[4]
\end{myexample}

\begin{myexample}[colback=red!5!white,colframe=blue!75!black]
  \lipsum[4]
\end{myexample}

\begin{myexample}[colback=red!5!white,colframe=red!75!black,mytitle={Third example}, label=exthird]
  \lipsum[4]
\end{myexample}

I can now refer to example~\ref{exfirst} and example~\ref{exthird}.
\end{document}

enter image description here

EDIT: One way to deal with the color issue is to introduce new macros.

\documentclass{article}
\usepackage{etoolbox}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable}
\usepackage{lipsum}

\tcbset{mytitle/.style={title={Example~\thetcbcounter\ifstrempty{#1}{}{: #1}}}}
\newtcolorbox[auto counter, number within=chapter, 
number freestyle={\noexpand\arabic{\tcbcounter}}]{myexample}[1][]{%
    enhanced,
    breakable,
    fonttitle=\bfseries,
    mytitle={},
    #1
}

\newcommand{\BlueBox}[3][]{
\begin{myexample}[colback=blue!5!white,colframe=blue!75!black,mytitle={#2},#1]
 #3
\end{myexample}
}

\newcommand{\RedBox}[3][]{
\begin{myexample}[colback=blue!5!white,colframe=red!75!black,mytitle={#2},#1]
 #3
\end{myexample}
}


\begin{document}


\RedBox[label=exfirst]{First Example}{\lipsum[1]}

\BlueBox[label=exsecond]{}{\lipsum[2]}

\RedBox[label=exthird]{Third Example}{\lipsum[3]}


I can now refer to example~\ref{exfirst} and example~\ref{exthird}.
\end{document}