login  Naam:   Wachtwoord: 
Registreer je!
 Forum
Zoeken  Regels  Help
Categorieën > HTML & CSS

afbeelding centreren (Opgelost)

chth – 12/11/2011 17:33
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

  1. #afb {
  2. margin: auto;
  3. display: block;
  4.  
  5. }


8 antwoorden

Gesponsorde links
Daisycon - Verdien geld met uw website

pijke – 12/11/2011 19:59
zou je de gehele broncode kunnen posten?

chth – 12/11/2011 20:34
geen probleem.

dit is de html code
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <link rel="stylesheet" type="text/css" href="layout.css" />
  6. <title></title>
  7. </head>
  8.  
  9. <body>
  10. <div id="afb"><img src="under-construction.jpg" alt="under construction" width="347" height="346" /></div>
  11. </body>
  12. </html>



met volgende css-code

  1. html {
  2. height: 100%;
  3. width:100%;
  4. }
  5. body {
  6. height: 100%;
  7. width:100%;
  8. padding: 0;
  9. margin: 0;
  10. }
  11. img {
  12. padding: 0;
  13. margin: 10px;
  14. }
  15.  
  16. #afb {
  17. margin-top:auto;
  18. border:dotted;
  19. border-color:red;
  20. margin-left:auto;
  21. margin-right:auto;
  22. /*display: block;*/
  23. padding:0px;
  24. width: 367px;
  25. height: 366px;
  26. position:relative;
  27. }


larssy1 – 12/11/2011 21:54 (Laatst gewijzigd op 12/11/2011 21:59)
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
inderdaad, horizontaal centreren is geen probleem. het is echter bij het verticaal centreren dat het niet lukt 

icemar – 13/11/2011 09:31
Met dit werkt het wel suc6 er mee

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <style type="text/css">
  5. html {
  6. height: 100%;
  7. width:100%;
  8. }
  9. body {
  10. height: 100%;
  11. width:100%;
  12. padding: 0;
  13. margin: 0;
  14. }
  15. img {
  16. padding: 0;
  17. margin: 10px;
  18. }
  19.  
  20. #afb {
  21. border:dotted;
  22. border-color:red;
  23. /*display: block;*/
  24. width: 368px;
  25. height: 366px;
  26. position:absolute;
  27. top:50%;
  28. margin-top:-183px;
  29. left:50%;
  30. margin-left:-184px;
  31. }
  32.  
  33.  
  34. </head>
  35.  
  36. <div id="afb">
  37. <img src="http://www.aandeknoppen.org/blog/wp-content/uploads/2011/03/Under-Construction.gif" alt="under construction" width="347" height="346" />
  38. </div>
  39. </body>
  40. </html>


chth – 13/11/2011 09:41
zeer tof, maar waarom die -183px en -184px?

icemar – 13/11/2011 09:56
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
owke, thanks ;)

Gesponsorde links

Je moet ingelogd zijn om een reactie te kunnen posten.
Actieve forumberichten:

© 2002-2012 Sitemasters.be - Regels - Gehost door: Vircon - Laadtijd: 0.118s