2013-07-13 24 views
-1

我是新來的CSS,這是我的第一個按鈕,我無法將文本放入按鈕。那麼,它在按鈕中,但它沒有正確對齊。我不知道如何解決這個問題,但這是我的代碼文本將不會在DIV

 body { 
    font-family: 'Open Sans', sans-serif; 
    background-color: #DB1F1F; 
    } 

    .navbar-menu { 
    margin: auto; 
    height: 100px; 
    width: 95px; 
    background-color: green; 
    padding: 10px 40px; 
    font-size: 25px; 
} 

    .navbar-menu:hover { 
    opacity: 0.5; 
} 

我不知道它有什麼問題,所以有人可以幫忙嗎?

哦和:HTML

<!DOCTYPE html> 
<html> 
<head> 
    <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'> 
    <link type="text/css" rel="stylesheet" href="stylesheet.css" /> 
    <title>Button</title> 
    </head> 
<body> 
    <center> 
    <div class="navbar-menu">HTML/CSS</div> 
    </center> 
</body> 
</html> 
+0

你可以給我們一個例子,你在做什麼你的HTML以及? – Enigmadan

+0

請發佈JS小提琴。 –

+0

http://jsfiddle.net/PkDKA/ –

回答

0

取決於你所使用的爲您按鈕元素(div的,跨度,LIS),你可以使用:

//use for any element type 
text-align: center; 

//use only for inline element types e.g. span 
vertical-align: middle; 

//use for any block element type e.g. div 
//(replace 90 with height of block element) 
line-height: 90px; 
0

請試試這個代碼

<!DOCTYPE html> 
<html> 
<head> 
<style type="text/css"> 
body { 
    font-family: 'Open Sans', sans-serif; 
    background-color: #DB1F1F; 
} 
.navbar-menu { 
background-color: green; 
    font-size: 25px; 
    height: 100px; 
    margin: 0 auto; 
    padding: 10px 43px; 
    width: 150px; 
} 
.navbar-menu:hover { 
    opacity: 0.5; 
} 
</style> 
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'> 
<link type="text/css" rel="stylesheet" href="stylesheet.css" /> 
<title>Button</title> 
</head> 
<body> 
<div class="navbar-menu"><center> 
HTML/CSS 
</center></div> 
</body> 
</html> 
+0

將其對齊到左邊,文本需要位於按鈕的中心,儘管 –

+0

這樣的工作,但現在它漂浮在右邊。 –

+0

請立即檢查。 – Ravi