Let me know if this is what you are looking for. It also supports breaking the box across multiple pages.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[skins,hooks,xparse,breakable]{tcolorbox}
\usepackage{xcolor}
\usepackage{chngcntr}
\usepackage{blindtext}
\usepackage{tikz}
\newcounter{examplecounter}
\counterwithin{examplecounter}{section}
\usetikzlibrary{calc}
\definecolor{greentitle}{RGB}{61,170,61}
\definecolor{greentitleback}{RGB}{216,233,213}
\definecolor{drakgreentitle}{RGB}{24,131,80}
\DeclareTColorBox{bookexample}{O{}}{
enhanced,
breakable,
arc=0pt,
boxrule=0pt,
colback=white,
before skip={2em}, % increase spacing before the env
overlay unbroken and first={
% draw box on the left
\node[fill=greentitleback,
font=\color{greentitle}\sffamily\bfseries\large,
anchor=south west,
xshift=2mm
] (titlebox) at (frame.north west)
{Exercise \refstepcounter{examplecounter}\theexamplecounter};
% write title on the right
\node[font=\color{drakgreentitle}\sffamily\large,
anchor=west
] at ($(titlebox.east)+(2mm,0mm)$) {#1};
% draw the vertical line on the left
\draw[draw=greentitleback, line width=2pt]
(titlebox.north west-|frame.north west)--(frame.south west);
},
overlay middle and last={
\draw[draw=greentitleback, line width=2pt]
(frame.north west)--(frame.south west);
}
fonttitle=\color{greentitle}\sffamily\bfseries,
}
\DeclareTColorBox{genericbox}{m}{
enhanced,
breakable,
arc=0pt,
boxrule=0pt,
colback=white,
attach boxed title to top left,
boxed title style={
colback=white,
colframe=white,
},
title={#1},
fonttitle=\color{greentitle}\sffamily\bfseries\large
}
\begin{document}
\section{First Section}
\null
\begin{bookexample}[My Title]
\Blindtext[4]
\end{bookexample}
\begin{genericbox}{Solution}
\Blindtext[2]
\end{genericbox}
\section{Second Section}
\null
\begin{bookexample}[Another Title]
\Blindtext[4]
\end{bookexample}
\begin{genericbox}{Solution}
\Blindtext[2]
\end{genericbox}
% No title
\begin{bookexample}
\Blindtext[1]
\end{bookexample}
\end{document}
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[skins,hooks,xparse,breakable]{tcolorbox}
\usepackage{xcolor}
\usepackage{chngcntr}
\usepackage{blindtext}
\usepackage{tikz}
% comment this line during integration because kaocounter would have been declared
\newcounter{kaocounter}
% you may not need the line below as well if it has already been configured using other approaches
\counterwithin{kaocounter}{section}
\usetikzlibrary{calc}
\definecolor{greentitle}{RGB}{61,170,61}
\definecolor{greentitleback}{RGB}{216,233,213}
\definecolor{drakgreentitle}{RGB}{24,131,80}
\DeclareTColorBox{bookexample}{O{}o}{
enhanced,
breakable,
arc=0pt,
boxrule=0pt,
colback=white,
top=3em, % you can change the top spacing
overlay unbroken and first={
% draw box on the left
\node[fill=greentitleback,
font=\color{greentitle}\sffamily\bfseries\large,
anchor=south west,
xshift=2mm,
yshift=-2em, % you can change xshift and yshift to adjust the title placement
] (titlebox) at (frame.north west)
% notice the difference here, kaocounter is used instead
{Exercise \refstepcounter{kaocounter}\thekaocounter
% add cross-referencing support
\IfValueT{#2}{\label{#2}}
};
% write title on the right
\node[font=\color{drakgreentitle}\sffamily\large,
anchor=west
] at ($(titlebox.east)+(2mm,0mm)$) {#1};
% draw the vertical line on the left
\draw[draw=greentitleback, line width=2pt]
(titlebox.north west-|frame.north west)--(frame.south west);
},
overlay middle and last={
\draw[draw=greentitleback, line width=2pt]
(frame.north west)--(frame.south west);
}
fonttitle=\color{greentitle}\sffamily\bfseries,
}
\DeclareTColorBox{genericbox}{m}{
enhanced,
breakable,
arc=0pt,
boxrule=0pt,
colback=white,
attach boxed title to top left,
boxed title style={
colback=white,
colframe=white,
},
title={#1},
fonttitle=\color{greentitle}\sffamily\bfseries\large
}
\begin{document}
\section{First Section}
\begin{bookexample}[My Title]
\Blindtext[4]
\end{bookexample}
\begin{genericbox}{Solution}
\Blindtext[2]
\end{genericbox}
\section{Second Section}
% an example with label
\begin{bookexample}[Another Title][ex:one]
\Blindtext[4]
\end{bookexample}
\begin{genericbox}{Solution}
\Blindtext[2]
\end{genericbox}
\textbf{I want to refer to Exercise \ref{ex:one}}.
% No title
\begin{bookexample}
\Blindtext[1]
\end{bookexample}
% No title, but has label
\begin{bookexample}[][ex:two]
\Blindtext[1]
\end{bookexample}
\textbf{I want to refer to Exercise \ref{ex:two}}.
\end{document}
\newcounter{examplecounter}\counterwithin{examplecounter}{section}to\numberwithin{kaocounter}{section}but this didn't work. Also wondering if this can support labeling & referencing? I tried\label{example2}and\ref{example2}but it only printed "1.1" instead of "1.1.2". Also it needs a tiny bit more padding at the top. updated the original question with a new screenshot -- notice how the example box is touching the yellow theorem box above it.) Thanks again! – EthanAlvaree Jul 11 '21 at 20:06bookexample, therefore changing to\numberwithin{kaocounter}{section}would not work. In the new example, I have assumed that the counter you are working with iskaocounter. I added a second optional argument for cross-referencing support. I also changed the layout of the box so that the top spacing is more controllable. You can changetopandyshiftto adjust the header position (see more in code comments). – Alan Xiang Jul 12 '21 at 01:35styles/mdftheorems.sty, now theorem, definition and example share the same counter. – Alan Xiang Jul 12 '21 at 14:23