Css 想把一个div放在中间吗
嗨,我的问题是,我实际上无法将我的div居中! 它总是卡在左边。我已经试过左边的边距:自动;右边距:自动;,但它似乎不起作用 以下是HTML:Css 想把一个div放在中间吗,css,html,margin,center,Css,Html,Margin,Center,嗨,我的问题是,我实际上无法将我的div居中! 它总是卡在左边。我已经试过左边的边距:自动;右边距:自动;,但它似乎不起作用 以下是HTML: <ul class="menu"> <li><a href="#" class="home">Acceuil</a></li> <li><a href="#" class="LoL">LoL</a>
<ul class="menu">
<li><a href="#" class="home">Acceuil</a></li>
<li><a href="#" class="LoL">LoL</a>
<ul>
<li><a><span class="headlist">League of Legends</a></li>
<li><a href="#">Funny games</a></li>
<li><a href="#">Favorite builds</a></li>
<li><a href="#">...</a></li>
</ul>
</li>
<li><a href="#" class="ssf2">SSF2</a>
<ul>
<li><a><span class="headlist">Super Smash Flash 2</a>
<li><a href="#">Intro</a></li>
<li><a href="#">Events</a></li>
<li><a href="#">Challenges</a></li>
</ul>
</li>
<li><a href="#">RotMG</a></li>
<li><a href="#">GMod</a></li>
<li><a href="#" class="contact">Contact</a></li>
</ul>
<div>
<p>
HUEHUEHUEHUEHUEHUEHUE
</p>
</div>
我已经搜索了两个小时了,请帮忙O
页边距:0自动代码>不适用于绝对定位。尝试从div中删除position:absolute
,然后它就可以工作了
这是页边距:0自动代码>不适用于绝对定位。尝试从div中删除position:absolute
,然后它就可以工作了
这是页边距:0自动代码>不适用于绝对定位。尝试从div中删除position:absolute
,然后它就可以工作了
这是页边距:0自动代码>不适用于绝对定位。尝试从div中删除position:absolute
,然后它就可以工作了
这里是如果它必须绝对定位(因此意味着边距:auto
不起作用),那么您可以将CSS更改为左:50%
并添加左边距:-295px代码>
这将从左边移动<代码> <代码> 50%,然后将它的宽度负一半地返回,这就把它放在中间。
如果它必须绝对定位(因此意味着页边距:auto
不起作用),那么您可以将CSS更改为左:50%
并添加页边距-295px代码>
这将从左边移动<代码> <代码> 50%,然后将它的宽度负一半地返回,这就把它放在中间。
如果它必须绝对定位(因此意味着页边距:auto
不起作用),那么您可以将CSS更改为左:50%
并添加页边距-295px代码>
这将从左边移动<代码> <代码> 50%,然后将它的宽度负一半地返回,这就把它放在中间。
如果它必须绝对定位(因此意味着页边距:auto
不起作用),那么您可以将CSS更改为左:50%
并添加页边距-295px代码>
这将从左边移动<代码> <代码> 50%,然后将它的宽度负一半地返回,这就把它放在中间。
1+top
/left
也应该被删除,因为他们不再做任何事情了。。同样的z-index
。哇,当我自己找不到我的错误时,你们发现我的错误真是太好了:D你们在那里给了我很大的帮助:3它节省了我很多时间,所以非常感谢!1+顶部
/左侧
也应删除,因为他们不再做任何事情。。同样的z-index
。哇,当我自己找不到我的错误时,你们发现我的错误真是太好了:D你们在那里给了我很大的帮助:3它节省了我很多时间,所以非常感谢!1+顶部
/左侧
也应删除,因为他们不再做任何事情。。同样的z-index
。哇,当我自己找不到我的错误时,你们发现我的错误真是太好了:D你们在那里给了我很大的帮助:3它节省了我很多时间,所以非常感谢!1+顶部
/左侧
也应删除,因为他们不再做任何事情。。同样的z-index
。哇,当我自己找不到我的错误时,你们发现我的错误真是太好了:D你们在那里给了我很大的帮助:3它节省了我很多时间,所以非常感谢!
html {
background: url(bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
/* div */
div
{
text-align: center;
border-radius: 0 0 5px 5px;
width: 590px;
padding-left: 5px;
padding-right: 5px;
padding-top: 5px;
padding-bottom: 5px;
background-color: rgba(140,0,0,0.7);
margin-left: auto;
margin-right: auto;
text-shadow: 1px 1px 1px rgba(0,0,0,.5);
color: #f3f3f3;
font-family: Helvetica, Arial, sans-serif;
display: block;
position: absolute;
top: 38px;
left: 25%;
z-index: -50;
margin-left: auto;
margin-right: auto;
}
/* Reset de la liste (aucun style, etc.) */
.menu,
.menu ul,
.menu li,
.menu a,
.menu p
{
margin: 0;
padding: 0;
border: none;
outline: none;
}
/* Menu */
.menu
{
height: 40px;
width: 610px; /* Longueur du menu */
background: #760101; /* couleur du gradient */
background: -moz-linear-gradient(#D20202, #760101);
background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #760101),color-stop(1, #D20202));
background: -webkit-linear-gradient(#D20202, #760101);
background: -o-linear-gradient(#D20202, #760101);
background: -ms-linear-gradient(#D20202, #760101);
background: linear-gradient(#D20202, #760101);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 13px;
display: block;
margin-left: auto;
margin-right: auto;
}
.menu li {
position: relative;
list-style: none;
float: left;
display: block;
height: 40px;
}
.menu li a {
display: block;
padding: 0 7px 0 40px;
margin: 6px 0;
line-height: 28px;
text-decoration: none;
border-left: 1px solid #4B0101;
border-right: 1px solid #5C0101;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 13px;
color: #f3f3f3;
text-shadow: 1px 1px 1px rgba(0,0,0,.6);
-webkit-transition: color .2s ease-in-out;
-moz-transition: color .2s ease-in-out;
-o-transition: color .2s ease-in-out;
-ms-transition: color .2s ease-in-out;
transition: color .2s ease-in-out;
}
.menu li:first-child a { border-left: none; }
.menu li:last-child a{ border-right: none; }
.menu li:hover > a { color: #FF9900; }
/* Sub-menu */
.menu ul {
position: absolute;
top: 40px;
left: 0;
opacity: 0;
background: #D20202;
background: -moz-linear-gradient(#760101, #D20202);
background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #D20202),color-stop(1, #760101));
background: -webkit-linear-gradient(#760101, #D20202);
background: -o-linear-gradient(#760101, #D20202);
background: -ms-linear-gradient(#760101, #D20202);
background: linear-gradient(#760101, #D20202);
-webkit-border-radius: 0 0 5px 5px;
-moz-border-radius: 0 0 5px 5px;
border-radius: 0 0 5px 5px;
-webkit-transition: opacity .25s ease .1s;
-moz-transition: opacity .25s ease .1s;
-o-transition: opacity .25s ease .1s;
-ms-transition: opacity .25s ease .1s;
transition: opacity .25s ease .1s;
}
.menu li:hover > ul { opacity: 1; }
.menu ul li {
height: 0;
overflow: hidden;
padding: 0;
-webkit-transition: height .25s ease .1s;
-moz-transition: height .25s ease .1s;
-o-transition: height .25s ease .1s;
-ms-transition: height .25s ease .1s;
transition: height .25s ease .1s;
}
.menu li:hover > ul li {
height: 36px;
overflow: visible;
padding: 0;
}
.menu ul li a {
width: 145px;
padding: 4px 0 4px 10px;
margin: 0;
border: none;
border-bottom: 1px solid #4B0101;
}
.menu ul li:last-child a {
border: none;
}
.LoL
{
background: url(LoLicon.png) no-repeat 6px center;
}
.home
{
background: url(home.png) no-repeat 6px center;
}
.ssf2
{
background: url(SSF2.png) no-repeat 6px center;
}
.contact
{
background: url(contact.png) no-repeat 6px center;
}
.headlist
{
color:#ff9900;
}
.menu ul li:first-child a {
border-bottom: 3px solid #4B0101;
}