我有div欄設置爲不滾動,所以它會始終顯示在網站的頂部。在這個酒吧裏面我有另外一個div box,裏面有兩個按鈕,它們都是右邊的,所以它們總是在右上角。試圖居中頂部DIV酒吧
問題是我想要按鈕居中右上方不是頁面右上角。相反,如果主體元素居中,則按鈕將位於居中元素的右上角。
這裏是代碼:
<DIV class="fixedtop">
<div class="language2">
<div class="english"> <font id="buttontxt">ENGLISH</font></div>
<div class="spanish"> <font id="buttontxt">SPANISH</font></div>
</div>
</DIV>
這裏是最上面一欄的CSS:
.fixedtop
{
position: fixed;
margin-left: 0 auto;
margin-right: 0 auto;
top: 0px;
width:600px;
height: 30px;
}
.language2
{
margin-left: auto;
margin-right: auto;
top: 0px;
width: 600px;
height: 30px;
margin-right: 0px;
}
.spanish
{
background-color:00ADEF;
float: right;
margin-right: 4px;
padding-top: 10px;
display: inline-block;
width: 100px;
height:30px;
color:black;
text-align: center;
vertical-align: middle;
-webkit-border-bottom-right-radius: 10px;
-webkit-border-bottom-left-radius: 10px;
-moz-border-radius-bottomright: 10px;
-moz-border-radius-bottomleft: 10px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
-webkit-box-shadow: 2px 3px 2px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 2px 3px 2px rgba(50, 50, 50, 0.75);
box-shadow: 2px 3px 2px rgba(50, 50, 50, 0.75);
}
.english
{
background-color:00ADEF;
float: right;
margin-right: 15px;
display: inline-block;
padding-top: 10px;
width: 100px;
height:30px;
color:black;
text-align: center;
vertical-align: middle;
-webkit-border-bottom-right-radius: 10px;
-webkit-border-bottom-left-radius: 10px;
-moz-border-radius-bottomright: 10px;
-moz-border-radius-bottomleft: 10px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
-webkit-box-shadow: 2px 3px 2px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 2px 3px 2px rgba(50, 50, 50, 0.75);
box-shadow: 2px 3px 2px rgba(50, 50, 50, 0.75);
}
?我剛把它放在那裏看。有沒有辦法做到這一點沒有固定的寬度? – user1744733
不,不幸的是,沒有簡單的方法只使用CSS來設置沒有明確寬度的'div'元素。不過,您可以簡單地使用jQuery來製作解決方案。 – BenM