<h1>An example of CSS Paint Containment <br><br>Box A and B have an <code>img</code> child element <br>Box B also has <code>contain:paint</code></h1>
<section>
	<div class="box">
		<p>Box A</p>
		<img src="https://images.unsplash.com/photo-1614121181207-4b6c334d353d?q=100&w=400"/>
	</div>
	<div class="box">
		<p>Box B</p>
		<img src="https://images.unsplash.com/photo-1614121181207-4b6c334d353d?q=100&w=400"/>
	</div>
</section>
<small>Credit: Photo by NASA, via Unsplash</small>
.box {
	width: 100px;
	border: 2px grey dashed;
	img {
		border-radius: 4px;
		margin-left: 20px;
		width: 200%;
	}
	&:nth-of-type(1) { 
		float: left; 
	}
	&:nth-of-type(2) { 
		float: right; 
		contain: paint; 
	}
	p {
		text-indent: 10px;
	}
}
h1 {
	--fsz: 18px;
	font-size: var(--fsz);
	font-weight: normal;
	text-align: center;
	code {
		font-size: calc(var(--fsz) - 2px);
		font-weight: bold;
	}
}
section {
	width: 400px;
}
body {
	font-family: 'crimson text';
	height: 100vh;
	display: grid;
	row-gap: 30px;
	place-content: center;
	place-items: center;
	margin: 0;
	user-select: none;
	-moz-user-select: none;
	-webkit-user-select: none;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.