I know this is very basic CSS. How do I keep the span contained within the div? At the moment, the span extends outside the top and bottom of the div.
div {
width: 200px;
margin: 10px;
background-color: #ff0;
}
span {
margin: 5px;
padding: 5px;
background-color: #fc0;
}
<body>
<div>
<span>span</span>
</div>
</body>
To answer your question, this isn’t just an issue with
paddingormargin, but also withwidth,display, and the box model.jsFiddle
This will honor any padding, margins, or widths you apply to the span.