|
Categorieën >
HTML & CSS
afbeelding centreren (Opgelost)
|
|
|
offline
|
Lid
|
hallo,
graag zou ik een afbeelding in het midden van een pagina hebben, maar dit wringt een beetje. de afbeelding heb ik in een div gezet en ik gebruik volgende css-code
#afb {
margin: auto;
display: block;
}
#afb { margin: auto; display: block; }
|
8 antwoorden
|
|
|
offline
|

Lid
|
zou je de gehele broncode kunnen posten?
|
chth – 12/11/2011 20:34
|
|
offline
|
Lid
|
geen probleem.
dit is de html code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="layout.css" />
<title></title>
</head>
<body>
<div id="afb"><img src="under-construction.jpg" alt="under construction" width="347" height="346" /></div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="layout.css" /> <title></title> </head> <body> <div id="afb"><img src="under-construction.jpg" alt="under construction" width="347" height="346" /></div> </body> </html>
met volgende css-code
html {
height: 100%;
width:100%;
}
body {
height: 100%;
width:100%;
padding: 0;
margin: 0;
}
img {
padding: 0;
margin: 10px;
}
#afb {
margin-top:auto;
border:dotted;
border-color:red;
margin-left:auto;
margin-right:auto;
/*display: block;*/
padding:0px;
width: 367px;
height: 366px;
position:relative;
}
html { height: 100%; width:100%; } body { height: 100%; width:100%; padding: 0; margin: 0; } img { padding: 0; margin: 10px; } #afb { margin-top:auto; border:dotted; border-color:red; margin-left:auto; margin-right:auto; /*display: block;*/ padding:0px; width: 367px; height: 366px; position:relative; }
|
larssy1 – 12/11/2011 21:54 (Laatst gewijzigd op 12/11/2011 21:59)
|
|
offline
|
MySQL beginner
|
werkt normaal in Internet Explorer en Google Chrome.
http://www.unrealxs.com/beta/test
---
Voor zekerheid in Dreamweaver even gekeken, beide kanten hebben exact 632px ruimte bij mij
|
chth – 13/11/2011 08:50
|
|
offline
|
Lid
|
inderdaad, horizontaal centreren is geen probleem. het is echter bij het verticaal centreren dat het niet lukt
|
|
|
|
offline
|
Lid
|
Met dit werkt het wel suc6 er mee
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
html {
height: 100%;
width:100%;
}
body {
height: 100%;
width:100%;
padding: 0;
margin: 0;
}
img {
padding: 0;
margin: 10px;
}
#afb {
border:dotted;
border-color:red;
/*display: block;*/
width: 368px;
height: 366px;
position:absolute;
top:50%;
margin-top:-183px;
left:50%;
margin-left:-184px;
}
</style>
<title></title>
</head>
<body>
<div id="afb">
<img src="http://www.aandeknoppen.org/blog/wp-content/uploads/2011/03/Under-Construction.gif" alt="under construction" width="347" height="346" />
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> html { height: 100%; width:100%; } body { height: 100%; width:100%; padding: 0; margin: 0; } img { padding: 0; margin: 10px; } #afb { border:dotted; border-color:red; /*display: block;*/ width: 368px; height: 366px; position:absolute; top:50%; margin-top:-183px; left:50%; margin-left:-184px; } <img src="http://www.aandeknoppen.org/blog/wp-content/uploads/2011/03/Under-Construction.gif" alt="under construction" width="347" height="346" />
|
chth – 13/11/2011 09:41
|
|
offline
|
Lid
|
zeer tof, maar waarom die -183px en -184px?
|
|
|
|
offline
|
Lid
|
dat is de helft afmeting van de afbeelding door deze negatief te zetten komt deze op de juiste plaats.
Anders zal dat niet mogelijk zijn zonder javascript te gebruiken.
|
chth – 13/11/2011 11:35
|
|
offline
|
Lid
|
owke, thanks ;)
|
Je moet ingelogd zijn om een reactie te kunnen posten.
|
|
|