My images keep overlapping the borders of my div boxes. I have found that float:none
causes the image to be constrained within the div nicely but then the divs will no longer sit side by side. If I set back to float:left
they snap up fine. Has anybody got another method to get the image to stay entirely within the div that doesn't involve float
?
try:
img {
max-width: 100%;
}
Try this:
HMTL:
<div>
<img src="something.jpg" alt="" />
</div>
CSS:
div{
width: 100px;
height: 100px;
}
div img {
width: 100%;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.