Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [HTML] Poprawne wyśrodkowanie DIV'ów
in5ane
post
Post #1





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

Ostrzeżenie: (10%)
X----


Elo, chciałbym się poprawnie używać xHTML'a i zaczynam od kompletnych podstaw. Jak mam prawidłowo coś takiego wyśrodkować?

  1. <?xml version="1.1" encoding="utf-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <link rel="stylesheet" type="text/css" href="style.css" />
  6. <?xml-stylesheet type="text/css" href="style.css" ?>
  7. <title>Test</title>
  8. </head>
  9. <body xml:lang="pl">
  10.  
  11. <div id="header">
  12. GÓRA
  13. </div>
  14.  
  15. <div id="left">
  16. LEWA
  17. </div>
  18.  
  19. <div id="content">
  20. ŚRODEK
  21. </div>
  22.  
  23. <div id="footer">
  24. DÓŁ
  25. </div>
  26.  
  27. </body>
  28. </html>


  1. body {
  2. text-align: center;
  3. }
  4.  
  5. div {
  6. border: 1px solid;
  7. width: 50%;
  8. text-align: left;
  9. margin: 0 auto 0 auto;
  10. }
  11.  
  12. div#header {
  13. height: 100px;
  14. width: 600px;
  15. background-color: #000000;
  16. }
  17.  
  18. div#left {
  19. height: 400px;
  20. width: 100px;
  21. background-color: #ff0000;
  22. float: left;
  23. }
  24.  
  25. div#content {
  26. height: 400px;
  27. width: 600px;
  28. background-color: #ffde00;
  29. }
  30.  
  31. div#footer {
  32. height: 50px;
  33. width: 600px;
  34. background-color: #00c6ff;
  35. }


Ja już tutaj zastosowałem wyśrodkowanie, ale jest problem, że div o nazwie left jest do lewej, a on ma być też na środku, ale do lewej części środka.
Go to the top of the page
+Quote Post
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Nie dam ci gotowca
Polecam goraco
kurs.browsehappy.pl
Go to the top of the page
+Quote Post
Maxik
post
Post #3





Grupa: Zarejestrowani
Postów: 726
Pomógł: 129
Dołączył: 10.01.2008
Skąd: Gdańsk

Ostrzeżenie: (0%)
-----


Jeśli chcesz wyśrodkować całą stronę w poziomie to obejmij to wszystko jeszcze jednym divem i nadaj mu margin-left:auto; i margin-right:auto;
Go to the top of the page
+Quote Post
in5ane
post
Post #4





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

Ostrzeżenie: (10%)
X----


  1. <div id="all">
  2.  
  3. <div id="header">
  4. GÓRA
  5. </div>
  6.  
  7. <div id="left">
  8. LEWA
  9. </div>
  10.  
  11. <div id="content">
  12. ŚRODEK
  13. </div>
  14.  
  15. <div id="footer">
  16. Ł
  17. </div>
  18.  
  19. </div>
  20.  
  21. -----------
  22.  
  23. div#all {
  24. margin-left: auto;
  25. margin-right: auto;
  26. }



I jest do lewej.

Ten post edytował in5ane 15.10.2008, 20:48:14
Go to the top of the page
+Quote Post
wookieb
post
Post #5





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Cytat(in5ane @ 15.10.2008, 21:46:36 ) *
  1. <div id="all">
  2.  
  3. <div id="header">
  4. GÓRA
  5. </div>
  6.  
  7. <div id="left">
  8. LEWA
  9. </div>
  10.  
  11. <div id="content">
  12. ŚRODEK
  13. </div>
  14.  
  15. <div id="footer">
  16. DÓŁ
  17. </div>
  18.  
  19. </div>
  20.  
  21.  
  22. div#all {
  23. margin-left: auto;
  24. margin-right: auto;
  25. }



I jest do lewej.

Bo patrzysz w ie. Dla ie dla rodzica elementu srodkowanego musi byc text-align: center;
Go to the top of the page
+Quote Post
in5ane
post
Post #6





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

Ostrzeżenie: (10%)
X----


Patrzę w FF.
Go to the top of the page
+Quote Post
MajareQ
post
Post #7





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

Ostrzeżenie: (0%)
-----


dla ff:
Kod
body {
margin-left: auto;
margin-right: auto;
}

dla ie:
Kod
html {
margin-left: auto;
margin-right: auto;
}


Ten post edytował MajareQ 15.10.2008, 20:51:03
Go to the top of the page
+Quote Post
in5ane
post
Post #8





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

Ostrzeżenie: (10%)
X----


To nic nie dało. Kurcze, takie małe, a tyle problemu.
Go to the top of the page
+Quote Post
MajareQ
post
Post #9





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

Ostrzeżenie: (0%)
-----


Jak nie dało ja musi dać? dziwnym trafem u mnie działa.
Go to the top of the page
+Quote Post
in5ane
post
Post #10





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

Ostrzeżenie: (10%)
X----


Naprawdę nie działa.

  1. <?xml version="1.1" encoding="utf-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <link rel="stylesheet" type="text/css" href="style.css" />
  6. <?xml-stylesheet type="text/css" href="style.css" ?>
  7. <title>Test</title>
  8. </head>
  9. <body xml:lang="pl">
  10.  
  11.  
  12. <div id="header">
  13. GÓRA
  14. </div>
  15.  
  16. <div id="left">
  17. LEWA
  18. </div>
  19.  
  20. <div id="content">
  21. ŚRODEK
  22. </div>
  23.  
  24. <div id="footer">
  25. DÓŁ
  26. </div>
  27.  
  28.  
  29. </body>
  30. </html>


  1. body {
  2. background-color: #bd2d2d;
  3. margin-left: auto;
  4. margin-right: auto;
  5. }
  6.  
  7. html {
  8. margin-left: auto;
  9. margin-right: auto;
  10. }
  11.  
  12. div#header {
  13. height: 100px;
  14. width: 600px;
  15. background-color: #e6d7c8;
  16. }
  17.  
  18. div#left {
  19. height: 400px;
  20. width: 100px;
  21. background-color: #a67c53;
  22. float: left;
  23. }
  24.  
  25. div#content {
  26. height: 400px;
  27. width: 600px;
  28. background-color: #171616;
  29. }
  30.  
  31. div#footer {
  32. height: 50px;
  33. width: 600px;
  34. background-color: #e6d7c8;
  35. }


Do tego mam jeszcze jedno pytanie, dlaczego jak łączna szerokość to 600px i ustawię menu na 100px a środek na 500px to środek jest jakby o 100px za mały (to jest tak w FF, a w IE jest dobrze), a jak zrobię 100px menu i 600px środek (w FF jest dobrze, a w IE jest za duże o 100px). Proszę o pomoc.
Go to the top of the page
+Quote Post
MajareQ
post
Post #11





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

Ostrzeżenie: (0%)
-----


zrób samo:

Kod
body {
    font-family:Tahoma;
    font-size:11px;
    color:black;
    background: #bd2d2d;
    margin-left: auto;
    margin-right: auto;
    margin-top: 0px;
    margin-bottom: auto;
}


co do pytania - nie idzie cię zrozumiec, pokaż stronę.
Go to the top of the page
+Quote Post
in5ane
post
Post #12





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

Ostrzeżenie: (10%)
X----


Nie idzie z tym wyśrodkowaniem.




Do tego pytania screenshot: http://img378.imageshack.us/my.php?image=screennv4.jpg

Ten post edytował in5ane 15.10.2008, 21:11:50
Go to the top of the page
+Quote Post
l1em1on1
post
Post #13





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.10.2008

Ostrzeżenie: (0%)
-----


no dziwne ze nic nie dalo skoro masz kilka divow luzno w body (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

daj na to jakis kontener o stalej szerokosci i wtedy margin: 0 auto; w body i powinno chulac
Go to the top of the page
+Quote Post
MajareQ
post
Post #14





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

Ostrzeżenie: (0%)
-----


No patrz... byłem przekonany że on robi w kontenerze...


  1. <?xml version="1.1" encoding="utf-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <link rel="stylesheet" type="text/css" href="style.css" />
  6. <?xml-stylesheet type="text/css" href="style.css" ?>
  7. <title>Test</title>
  8. </head>
  9. <body xml:lang="pl">
  10.  
  11. <div id="kontener">
  12. <div id="header">
  13. GÓRA
  14. </div>
  15.  
  16. <div id="left">
  17. LEWA
  18. </div>
  19.  
  20. <div id="content">
  21. ŚRODEK
  22. </div>
  23.  
  24. <div id="footer">
  25. DÓŁ
  26. </div>
  27. </div>
  28.  
  29. </body>
  30. </html>


Kod
body {
background-color: #bd2d2d;
margin-left: auto;
margin-right: auto;
}

#contener {
margin-left: auto;
margin-right: auto;
height: auto;
width: auto;
}

#header {
height: 100px;
width: 600px;
background-color: #e6d7c8;
}

#left {
height: 400px;
width: 100px;
background-color: #a67c53;
float: left;
}

#content {
height: 400px;
width: 600px;
background-color: #171616;
}

#footer {
height: 50px;
width: 600px;
background-color: #e6d7c8;
}
Go to the top of the page
+Quote Post
in5ane
post
Post #15





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

Ostrzeżenie: (10%)
X----


Dzięki za pomoc. Teraz już wiem o co chodzi (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)

A teraz proszę o odpowiedź na to: http://img378.imageshack.us/my.php?image=screennv4.jpg

Do tego doszedł problem, że w IE jak mam left na float: left; to jest w ogóle kaszanka, screen: <a href="http://xs.to/xs.php?h=xs132&d=08424&f=asd205.jpg" target="_blank">http://xs.to/xs.php?h=xs132&d=08424&f=asd205.jpg</a>
Co do tego, to jak dopisałem float: right; dla content to śmiga. Aha i ten problem wyżej też się przy tym rozwiązał. Teraz tylko problem to, że na IE nadal jest do lewej.


Taki kod mam teraz:
  1. <?xml version="1.1" encoding="utf-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <link rel="stylesheet" type="text/css" href="style.css" />
  6. <?xml-stylesheet type="text/css" href="style.css" ?>
  7. <title>Test</title>
  8. </head>
  9. <body xml:lang="pl">
  10.  
  11. <div id="contener">
  12.  
  13. <div id="header">
  14. GÓRA
  15. </div>
  16.  
  17. <div id="center">
  18.  
  19. <div id="left">
  20. LEWA
  21. </div>
  22.  
  23. <div id="content">
  24. ŚRODEK
  25. </div>
  26.  
  27. </div>
  28.  
  29. <div id="footer">
  30. Ł
  31. </div>
  32.  
  33. </div>
  34.  
  35. </body>
  36. </html>


  1. body {
  2. background-color: #bd2d2d;
  3. margin-left: auto;
  4. margin-right: auto;
  5. }
  6.  
  7. #contener {
  8. margin-left: auto;
  9. margin-right: auto;
  10. width: 600px;
  11. }
  12.  
  13. #header {
  14. height: 100px;
  15. width: 600px;
  16. background-color: #e6d7c8;
  17. }
  18.  
  19. #center {
  20. height: 400px;
  21. width: 600px;
  22. }
  23.  
  24. #left {
  25. height: 400px;
  26. width: 100px;
  27. background-color: #a67c53;
  28. float: left;
  29. }
  30.  
  31. #content {
  32. height: 400px;
  33. width: 500px;
  34. background-color: #171616;
  35. float: right;
  36. }
  37.  
  38. #footer {
  39. height: 50px;
  40. width: 600px;
  41. background-color: #e6d7c8;
  42. }


Ten post edytował in5ane 16.10.2008, 14:18:04
Go to the top of the page
+Quote Post
Maxik
post
Post #16





Grupa: Zarejestrowani
Postów: 726
Pomógł: 129
Dołączył: 10.01.2008
Skąd: Gdańsk

Ostrzeżenie: (0%)
-----


1. Wywal pierwszą linijkę bo wprowadzasz IE w Quirks Mode
2. Zmień doctype na xhtml 1.1 transitional(znajdziesz je na www.w3.org )
Go to the top of the page
+Quote Post
in5ane
post
Post #17





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

Ostrzeżenie: (10%)
X----


Śmiga, dzięki za pomoc. Teraz dalej będę brnął w poprawną naukę xhtmla.

Ten post edytował in5ane 16.10.2008, 14:50:45
Go to the top of the page
+Quote Post
MajareQ
post
Post #18





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

Ostrzeżenie: (0%)
-----


Wydaje mi się że mi mi Maxikowi należą się punkty pewne... ;p
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 16.09.2025 - 14:07