Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [CSS] Centrowanie elementów menu
misterious
post 26.05.2013, 15:52:48
Post #1





Grupa: Zarejestrowani
Postów: 52
Pomógł: 2
Dołączył: 7.10.2012

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


Witam!
Posiadam na stronie menu, gdzie postanowiłem ukryć kilka jego elementów (m.in. panel usera, moda i admina)
Długość jest przystosowana, aby się wszystkie pokazywały.
Chciałbym, aby elementy były wyśrodkowane, niezależnie od ich ilości.
Oto mój kod:
  1. <div id="cssmenu" style="margin-top: 5px; width: 865px; margin: 0 auto;">
  2. <ul>
  3. <li><a href="index.php"><span>Nowości</span></a></li>
  4. <li><a href="index.php"><span>Poczekalnia</span></a></li>
  5. <?php
  6. if($_SESSION['logged'])
  7. {
  8. echo '
  9. <li class="has-sub"><a href="#"><span>Panel użytkownika</span></a>
  10. <ul>
  11. <li><a href="#"><span>Moje obrazki</span></a></li>
  12. <li class="last"><a href="#"><span>a</span></a></li>
  13. </ul>
  14. </li>';
  15.  
  16. echo '
  17. <li class="has-sub"><a href="#"><span>Panel moderatora [999+]</span></a>
  18. <ul>
  19. <li><a href="#"><span>Do zaakceptowania []</span></a></li>
  20. <li class="last"><a href="#"><span>Zgłoszone []</span></a></li>
  21. </ul>
  22. </li>';
  23.  
  24. echo '
  25. <li class="has-sub"><a href="#"><span>Panel administratora</span></a>
  26. <ul>
  27. <li class="last"><a href="#"><span>Archiwum</span></a></li>
  28. </ul>
  29. </li>';
  30. }
  31. ?>
  32. <li class="last"><a href="#"><span>Kontakt</span></a></li>
  33. </ul>
  34. </div>


CSS:
  1. #cssmenu ul {margin: 0; padding: 7px 6px 0; background: #7d7d7d url(images/overlay.png) repeat-x 0 -110px; line-height: 100%; border-radius: 1em; font: normal .8em/1.5em Arial, Helvetica, sans-serif; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: 0 1px 3px rgba(0,0,0, .4); -moz-box-shadow: 0 1px 3px rgba(0,0,0, .4); }
  2. #cssmenu li {margin: 0 5px; padding: 0 0 8px; float: left; position: relative; list-style: none; }
  3. #cssmenu a,
  4. #cssmenu a:link {font-weight: bold; color: #e7e5e5; text-decoration: none; display: block; padding: 8px 20px; margin: 0; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; text-shadow: 0 1px 1px rgba(0,0,0, .3); }
  5. #cssmenu a:hover {background: #000; color: #fff;}
  6. #cssmenu .active a,
  7. #cssmenu li:hover > a {background: #666 url(images/overlay.png) repeat-x 0 -40px; color: #444; border-top: solid 1px #f8f8f8; -webkit-box-shadow: 0 1px 1px rgba(0,0,0, .2); -moz-box-shadow: 0 1px 1px rgba(0,0,0, .2); box-shadow: 0 1px 1px rgba(0,0,0, .2); text-shadow: 0 1px 0 rgba(255,255,255, 1); }
  8. #cssmenu ul ul li:hover a,
  9. #cssmenu li:hover li a {background: none; border: none; color: #666; -webkit-box-shadow: none; -moz-box-shadow: none;}
  10. #cssmenu ul ul a:hover {background: #8f8f8f url(images/overlay.png) repeat-x 0 -100px !important; color: #fff !important; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; text-shadow: 0 1px 1px rgba(0,0,0, .1);}
  11. #cssmenu li:hover > ul {display: block;}
  12. #cssmenu ul ul {display: none; margin: 0; padding: 0; width: 185px; position: absolute; top: 40px; left: 0; background: #ddd url(images/overlay.png) repeat-x 0 0; border: solid 1px #b4b4b4; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: 0 1px 3px rgba(0,0,0, .3); -moz-box-shadow: 0 1px 3px rgba(0,0,0, .3); box-shadow: 0 1px 3px rgba(0,0,0, .3);}
  13. #cssmenu ul ul li {float: none; margin: 0; padding: 3px; }
  14. #cssmenu ul ul a {font-weight: normal; text-shadow: 0 1px 0 #fff; }
  15. #cssmenu ul:after {content: '.'; display: block; clear: both; visibility: hidden; line-height: 0; height: 0;}
  16. * html #cssmenu ul {height: 1%;}
Go to the top of the page
+Quote Post
fate
post 26.05.2013, 19:12:52
Post #2





Grupa: Zarejestrowani
Postów: 824
Pomógł: 106
Dołączył: 14.03.2012
Skąd: Warszawa

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


#cssmenu, #cssmenu ul, #cssmenu ul li, ul li a {margin:0 auto!important; text-align: center!important;}
nad wyraz ale powinno zadziałać


--------------------
Go to the top of the page
+Quote Post
Arcioch
post 26.05.2013, 20:18:49
Post #3





Grupa: Zarejestrowani
Postów: 324
Pomógł: 110
Dołączył: 18.09.2012

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


Polecam wpis na blogu Pana Piotra Nalepy smile.gif

http://blog.piotrnalepa.pl/2010/07/06/css-...-za-pomoca-css/
Go to the top of the page
+Quote Post
lobopol
post 26.05.2013, 20:31:25
Post #4





Grupa: Zarejestrowani
Postów: 1 729
Pomógł: 346
Dołączył: 4.04.2009

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


Zaklinam na wszystko nie rób jak na tym blogu o.O

Najprostsze menu http://jsfiddle.net/eDMBn/


--------------------
Go to the top of the page
+Quote Post
Arcioch
post 26.05.2013, 20:36:19
Post #5





Grupa: Zarejestrowani
Postów: 324
Pomógł: 110
Dołączył: 18.09.2012

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


Masz rację smile.gif trochę już nieaktualny sposób centrowania smile.gif Twój przykład jest dużo lepszy smile.gif
Go to the top of the page
+Quote Post
misterious
post 28.05.2013, 09:07:14
Post #6





Grupa: Zarejestrowani
Postów: 52
Pomógł: 2
Dołączył: 7.10.2012

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


@fate
nie działa ohno-smiley.gif
@lobopol
Wiem że takie najprostsze wink.gif Ale mnie interesuje takie jakie mam wink.gif
Go to the top of the page
+Quote Post
Hyth
post 28.05.2013, 10:23:25
Post #7





Grupa: Zarejestrowani
Postów: 23
Pomógł: 2
Dołączył: 21.05.2013

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


#cssmenu ul {margin: 0; padding: 7px 6px 0; background: #7d7d7d url(images/overlay.png) repeat-x 0 -110px; line-height: 100%; border-radius: 1em; font: normal .8em/1.5em Arial, Helvetica, sans-serif; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: 0 1px 3px rgba(0,0,0, .4); -moz-box-shadow: 0 1px 3px rgba(0,0,0, .4); text-align: center;}
#cssmenu li {margin: 0 5px; padding: 0 0 8px; position: relative; list-style: none; display: inline;}
#cssmenu a, #cssmenu a:link {font-weight: bold; color: #e7e5e5; text-decoration: none; display: inline-block; padding: 8px 20px; margin: 0; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; text-shadow: 0 1px 1px rgba(0,0,0, .3); }

Pogrubiona część to ta zmieniona/dodana.
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 18.07.2025 - 01:33