簡體   English   中英

同時定位div左右

[英]positioning a div right and left simultaneously

我正在嘗試使用絕對定位使div具有寬度,並且它在谷歌瀏覽器中可以正常工作,但在fierfox中卻不能。 為什么會有沖突? 我在瀏覽器和fierfox上嘗試了完全相同的代碼,但並沒有對其進行調整。

   <!DOCTYPE HTML>
<html >
    <head>
        <meta charset="utf-8"/>
        <title>Kelma</title>
        <link rel="stylesheet" href="style.css" />
    </head>
    <body>

            <input type="text" id="center" />
    </body>
</html>

這是css文件

#center{
    position: absolute;
    left:50px;
    right: 50px;
}

看看這個:

<!DOCTYPE HTML>
<html >
    <head>
        <meta charset="utf-8"/>
        <title>Kelma</title>
        <link rel="stylesheet" href="style.css" />
        <style>
            #wrapper
            {
               position: absolute;
               left:50px;
               right: 50px;
            }
            #center
            {
               width:100%;
            }
        </style>
    </head>
    <body>
        <div id="wrapper">
               <input type="text" id="center" value="test" />
        </div>
    </body>
</html>

我用div包裝輸入,然后將樣式應用於div,將100%寬度應用於輸入。

嘗試這個:

#center{
  position: absolute;
  left:0px;
  width: 100%;
}

我已經將其與內聯CSS一起使用

這是我個人網站上的一個例子

<div style="position:absolute; top:60px; bottom:5%; left:5%; right:5%; width:90%; text-align:center;"> SOME TEXT </div>

我個人喜歡使用百分比,因為它在某些網站上看起來更好。 讓我知道這是否適合您! 現場觀看: http : //cbogausch.com/portal它既可以在Firefox中使用,也可以在chrome中使用

這不是你的意思嗎?

body{padding: 0 50px;}
input{width:100%;

在您的CSS上使用它:

#center {
   margin: 0 auto;
   width: 90%;
}

Hgs,Vinicius =)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM