Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [CSS]Wyrównanie elementu
Forum PHP.pl > Forum > Przedszkole
Mlodycompany
Witam. Mam diva ze stylem
  1. background: black; position: fixed; width: 480px; height: 335px; display: none; margin-left: auto; margin-right: auto; z-index: 9999;
który wyskakuje kiedy user na coś tam kliknie. Powinien pokazać się po środku ekranu w poziomie, a jednak w operze jest troszke bardziej na prawo a w firefox-ie jest jeszcze bardziej na prawo. Ma ktoś na to jakieś lepsze rozwiązanie?
muk4
zrobiłem sobie taki div:
  1. <div style="position:fixed;left:50%;top:50%;border: 1px solid black;width: 100px;height:100px;text-align:center;">test</div>

i mam na środku w obu przeglądarkach.

  1. position:fixed;left:50%;top:50%;
Mlodycompany
o jeszcze gorzej smile.gif kompletnie do prawego dolnego rogu zjechało
erix
CSS ma w nazwie KASKADOWE.

Wyrwanego z kontekstu się nie da ocenić.
Mlodycompany
to w takim razie co mam wstawić abyś mógł mi pomóc?
muk4
Cały kod html + plik styli .css
Mlodycompany
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl" dir="ltr">
  4. <title>Żużel</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <link rel="stylesheet" type="text/css" href="/css/master.css" />
  7. <script src="script.js"></script>
  8. </head>
  9. <body onload="window.setTimeout(getSecs('class/load.php?load=shoutbox&id_dru=1', 'shoutbox-chat'),1)"><div id="page"><div id="logo">logo</div><div id="left"><div id="menu"><div id="menu-head">Menu</div><div id="menu-links"><ul><li><a href="home/" >Home</a></li><li><a href="gallery/" >Galeria</a></li></ul></div></div><div id="userpanel"><div id="userpanel-header">Panel usera</div><div id="userpanel-links"><ul><li><a href="admin/index.php">Panel admina</a></li><a href="?logout">Wyloguj</a><li></li></ul></div></div></div><div id="center"><div class="news"><div class="news-title">asdasdads</div><div class="news-date">Dzisiaj o 10:55</div><div class="news-mini" style="float:left; clear:left;"><img src="thumbes/read.png" width="100"></div><div class="news-str" style="float:right; clear:right"><div align="left" style="background-image: url('http://i2.ytimg.com/vi/6oUL9POtEeU/default.jpg'); float: left; margin: 10px; width: 120px; height: 90px"><a href="#yt6oUL9POtEeU" onclick="display('yt6oUL9POtEeU', 1)"><img src="images/yt.gif" style="float-left" align="left"></a></div>
  10. <div id="yt6oUL9POtEeU" class="window" style="background: black; position: fixed; width: 480px; height: 335px; display: none; left: 50%; top: 50%; z-index: 9999;">
  11. <div id="close"><a href="java script:display('yt6oUL9POtEeU', 0)"><img src="images/del.png" border="0" width="25"></a></div>
  12. <div><object width="480" height="335"><param name="movie" value="http://www.youtube.com/v/6oUL9POtEeU&hl=pl_PL&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/6oUL9POtEeU&hl=pl_PL&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="335"></embed></object></div>
  13. </div></div></div><div id="coments" style="border-width: 1px; float: left; width:96%; margin-left: 2%;"><div id="com_1" style="border-width: 1px;">asdasdadda</div></div></div><div id="right"></div></div></body></html>

  1. body {
  2. background: grey;
  3. font: 12px arial, helvetica, sans-serif;
  4. width: 900px;
  5. margin-left: auto;
  6. margin-right: auto;
  7. }
  8. td, th{
  9. font: 12px arial, helvetica, sans-serif;
  10. }
  11. #page{
  12. width: 900px;
  13. height: auto;
  14. margin-left: auto;
  15. margin-right: auto;
  16. background: white;
  17. position: absolute;
  18. z-index: 0;
  19. left: auto;
  20. right: auto;
  21. }
  22. #logo{
  23. width: 900px;
  24. height: 150px;
  25. //position: relative;
  26. }
  27. #mask{
  28. width: 100%;
  29. height: 100%;
  30. background-image: url('mask.gif');
  31. z-index: 9990;
  32. position: fixed;
  33. display: none;
  34. top: 0px;
  35. left: 0px;
  36. opacity:0.8;
  37. filter:alpha(opacity=40);
  38. }
  39. div{
  40. border-style: solid;
  41. border-color: red;
  42. border-width: 0px;
  43. }
  44. #news{
  45. width: 550px;
  46. //position: relative;
  47. float: left;
  48. clear: left;
  49. }
  50. .news{
  51. background-image: url('news3.png');
  52. width: 550px;
  53. height: 130px;
  54. margin-bottom: 5px;
  55. }
  56. .news-title{
  57. width: 400px;
  58. height: 30px;
  59. clear: left;
  60. float: left;
  61. //position: relative;
  62. }
  63. .news-date{
  64. width: 150px;
  65. height: 30px;
  66. clear: right;
  67. float: right;
  68. //position: relative;
  69. }
  70. .news-str{
  71. width: 440px;
  72. height: 75;
  73. //position: relative;
  74. }.news-mini{
  75. width: 110px;
  76. height: 75;
  77. //position: relative;
  78. overflow: visible;
  79. }
  80. .table{
  81. width: 300px;
  82. height: 250px;
  83. float: right;
  84. clear: right;
  85. //position: relative;
  86. background-image: url('tlotabela.png');
  87. margin-bottom: 5px;
  88. }
  89.  
  90. .table > .header{
  91. background-image: url('header.png');
  92. width: 100%;
  93. height: 25px;
  94. text-align: center;
  95. color: white;
  96. vertical-align: middle;
  97. font-weight: bold;
  98. padding-top: 5px;
  99. }
  100. .komentarze-pasek{
  101. width: 100%;
  102. height: 30px;
  103. background-image: url('pasek.png');
  104. clear: both;
  105. }
  106. .komentarze-pasek > ul, ul li {
  107. display: block;
  108. list-style: none;
  109. margin: 0;
  110. padding: 0;
  111.  
  112. width: 60px;
  113. }
  114.  
  115. .komentarze-pasek > ul > li{
  116. display: inline;
  117. width: 60px;
  118. position: relative;
  119.  
  120. }
  121. .komentarze-pasek > ul > li > a{
  122. display: inline;
  123. width: 60px;
  124. height: 30px;
  125. margin-right: 10px;
  126. margin-left: 10px;
  127. color: white;
  128. text-decoration: none;
  129. }
  130. #komentarze-form{
  131. display: none;
  132. text-align: center;
  133. }
  134. #komentarze{
  135. display: none;
  136. }
  137. .komentarz{
  138. width: 100%;
  139. }
  140. .komentarz-mini{
  141. width: 100px;
  142. height: 75px;
  143. float: left;
  144. overflow: visible;
  145. }
  146. .komentarz-user{
  147. width: 100px;
  148. float: left;
  149. clear: left;
  150. }
  151. .komentarz-data{
  152. width: 440px;
  153. height: 30px;
  154. float: right;
  155. }
  156. .komentarz-tresc{
  157. width: 440px;
  158. float: right;
  159. clear: both;
  160. }
  161. #user-panel{
  162. width: 35px;
  163. background: green;
  164. z-index: 999;
  165. top: 35px;
  166. bottom: auto;
  167. right: 0px;
  168. position: fixed;
  169. background-image: url('img/pasek2.gif');
  170. }
  171. #user-panel > ul, ul li{
  172. list-style: none;
  173. margin: 0;
  174. padding: 0;
  175. }
  176. #panel-logowanie{
  177. display: none;
  178. width: 200px;
  179. height: 50px;
  180. top:35px;
  181. right:35px;
  182. z-index:999;
  183. position:fixed;
  184. background-image: url('img/pasek1.gif');
  185. }
  186. #panel-konfiguracja{
  187. display: none;
  188. width: 200px;
  189. height: 50px;
  190. top:70px;
  191. right:35px;
  192. z-index:999;
  193. position:fixed;
  194. background-image: url('img/pasek1.gif');
  195. }
  196. #panel-pomoc{
  197. display: none;
  198. width: 200px;
  199. height: 50px;
  200. top:105px;
  201. right:35px;
  202. z-index:999;
  203. position:fixed;
  204. background-image: url('img/pasek1.gif');
  205. }
  206. #panel-znajomi{
  207. display: none;
  208. width: 200px;
  209. height: 50px;
  210. top:140px;
  211. right:35px;
  212. z-index:999;
  213. position:fixed;
  214. background-image: url('img/pasek1.gif');
  215. }
  216. #panel-ulubione{
  217. display: none;
  218. width: 200px;
  219. height: 50px;
  220. top:175px;
  221. right:35px;
  222. z-index:999;
  223. position:fixed;
  224. background-image: url('img/pasek1.gif');
  225. }
  226. #panel-rejestracja{
  227. display: none;
  228. width: 200px;
  229. height: 50px;
  230. top:70px;
  231. right:35px;
  232. z-index:999;
  233. position:fixed;
  234. background-image: url('img/pasek1.gif');
  235. text-align: center;
  236. padding-top: 5px;
  237. padding-bottom:5px;
  238. }
  239. input{
  240. margin-top: 5px;
  241. }
  242. #submit_rej{
  243. display: none;
  244. }
  245. #acceptbut{
  246. background-image: url('img/acceptbutton.gif');
  247. width: 100px;
  248. height: 35px;
  249. border-width: 0px;
  250. font: 13px arial, helvetica, sans-serif;
  251. color: white;
  252. font-weight: bold;
  253. }
  254. #cancelbut{
  255. background-image: url('img/cancelbutton.gif');
  256. width: 100px;
  257. height: 35px;
  258. border-width: 0px;
  259. font: 13px arial, helvetica, sans-serif;
  260. color: white;
  261. font-weight: bold;
  262. }
  263. #buttons{
  264. border-width: 0px;
  265. position: relative;
  266. height: 40px;
  267. text-align: right;
  268. overflow: hidden;
  269. padding-top: 0px;
  270. margin-top: 0px;
  271. }
  272. #buttons > ul{
  273. display: block;
  274. list-style: none;
  275. }
  276. #buttons > ul > li{
  277. display: inline;
  278. margin: 0px;
  279. padding: 0px;
  280. margin-right: 5px;
  281. }
  282. #buttons > ul, ul li{
  283. list-style: none;
  284. margin: 0;
  285. padding: 0;
  286. }
  287. #actiontrue{
  288. border-width:1px;
  289. border-color: green;
  290. border-style: solid;
  291. margin: 5px;
  292. width: 95%;
  293. height: auto;
  294. padding:5px;
  295. text-align: center;
  296. color: green;
  297. font-weight: bold;
  298. background: #CDEBA7;
  299. opacity: 0.7;
  300. }
  301. #actionfalse{
  302. border-width:1px;
  303. border-color: red;
  304. border-style: solid;
  305. margin: 5px;
  306. width: 95%;
  307. height: auto;
  308. padding:5px;
  309. text-align: center;
  310. color: red;
  311. font-weight: bold;
  312. background:#FF2400;
  313. opacity: 0.7;
  314. }
  315. #stopka{
  316. width: 100%;
  317. height: 30px;
  318. float: left;
  319. clear: both;
  320. border-width: 1px;
  321. }
  322. #edit_user{
  323. display: none;
  324. width: 850px;
  325. background: green;
  326. z-index: 9999;
  327. top: 300px;
  328. bottom: auto;
  329. left: 0px;
  330. margin-right: auto;
  331. margin-left: auto;
  332. position: fixed;
  333. }

Proszę smile.gif
Barcelona
  1. <div id="yt6oUL9POtEeU" class="window" style="background: black; position: fixed; width: 480px; height: 335px; display: none; left: 50%; top: 50%; z-index: 9999;">


Podałeś class="window" a w css nie widze tej clasy, po drugie wszelkie style wrzucaj do css, zaoszczędzisz dużo linijek kodu.

Ja proponuje coś takiego:

  1. <div id="okienko">gggg</div>


a css
  1. div#okienko {
  2. width: 480px;
  3. height: 335px;
  4. margin-left: -100px;
  5. margin-top: -35px;
  6. position: absolute;
  7. left: 50%;
  8. top: 50%;
  9. }


P.S. Albo poczytaj to: http://www.wpdfd.com/editorial/thebox/deadcentre4.html
Mlodycompany
nadal nie jest po środku sad.gif
Barcelona
W css wywal ten kawałek

  1. margin-left: -100px;
  2. margin-top: -35px;


I będzie git
Mlodycompany
nie pomogło sad.gif
gigzorr
spróbuj
  1. display: inline-block;text-align:center;

a jak to samo to dodaj margin: auto .
Barcelona
Ale to centruje tylko tekst.

Pokaż screena jak Ci to wychodzi.
Mlodycompany
nadal nie jest na środku.

gdy ustawie wszystkie szerokości itp w procentach to wtedy jest na środku, ale to mnie nie urządza.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.