Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center image using CSS without white border

Tags:

html

css

Here is my CSS and HTML code. I want to put a single image in the center and this works except there is a weird white border around the image. I have tried border:none; and border:0;

HTML:

<!DOCTYPE html>
<html>

<head>
<title>Food.</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="icon" type="image/png" href="favicon.ico">

</head>


<body>
<img border="0" id="image" class="centered" />

</body>

</html>

CSS:

.centered {
  position: fixed;
  top: 50%;
  left: 50%;
  margin-top: -182px;
  margin-left: -153px;

}

img#image{
   /*I think this is where the issue is caused*/
    width:337px;
    height:219px;
    background-image: url('soon_comp.png');
    background-color: transparent;
}


body {
    outline: none;
    background-color: rgb(15,15,30);
    border-color:transparent;
    border:0px;
}
like image 513
Sammy Guergachi Avatar asked Oct 17 '12 01:10

Sammy Guergachi


1 Answers

I don't know why you're setting a background image for an img tag, I would rather to use a div or span tag instead. But, if you really want to do this, try to add to your img#image CSS rule:

img#image{
  content: '';
  ...
}
like image 200
Alcides Queiroz Avatar answered Oct 04 '22 00:10

Alcides Queiroz