I'm trying to center a <div>
element containing both text and image using <center>
tags, but for some reason it only applies on the text and not the image.
HTML:
<body>
<h1 align="center">Search For a Member</h1>
<br>
<br>
<form action="SearchController" method="get">
Enter the member's first name: <input type="text" style="width: 18em;" name="searchBox">
<input style="width:6em;" type="submit" value="Search">
<input style="width:6em;padding-left:7px;" type="submit" value="Back">
</form>
<center>
<div class="profile">
<img style="float:left;" src="default.jpg"height=100 width=100>
First Name
<br>
Last Name
<br>
</div>
</center>
</body>
CSS:
<style>
body {
background-color: #BCD2EE;
margin-left: 20%;
margin-right: 20%;
border: 1px outset #4876FF;
border-width: 5px;
padding: 10px 10px 30px 10px;
}
.profile {
overflow: hidden;
padding-top: 30px;
}
</style>
But if you'll try it, you'll see that only the text "First Name" and "Last Name" gets centered but not the picture. (I know you won't be able to see the picture default.jpg
, but it will show you where the image would be).
Why won't the picture get centered? is it because of the float:left;
property, which excludes the picture from the <center>
tag?
If so, how can it be fixed?