HTML + CSS:'a'宽度不起作用 [英] HTML+CSS: 'a' width doesn't work

查看:131
本文介绍了HTML + CSS:'a'宽度不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:



CSS部分:

 < style type =text / css> 
.menu
{
width:200px;
}

.menu ul
{
list-style-image:none;
list-style-type:none;
}

.menu li
{
margin:2px;
}

.menu A
{
height:25px;
width:170px;
background:url(./ images / button-51.png);
padding:2px 5px;
}

.menu A:link
{
height:25px;
width:170px
background:url(./ images / button-51.png);
padding:2px 5px;
}
< / style>

HTML部分:



,但是当我在HTML文档的开头添加DOCTYPE元素时:

 <!DOCTYPE html PUBLIC  - / W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> 

不考虑'a'元素的宽度。



问题1:为什么?



问题2: / p>

非常感谢!

解决方案


问题1:为什么?


因为它默认不是封锁元素


问题2:如何解决这个问题?


使用 display:block; 将其作为块元素,或通过 display:inline-block;


I have the following code:

CSS part:

<style type="text/css">
    .menu
    {
        width:200px;
    }

    .menu ul
    {
        list-style-image:none;
        list-style-type:none;
    }

    .menu li
    {
        margin:2px;
    }

    .menu A
    {
        height:25px;
        width:170px;
        background:url(./images/button-51.png);
        padding:2px 5px ;
    }

    .menu A:link
    {
        height:25px;
        width:170px;
        background:url(./images/button-51.png);
        padding:2px 5px ;
    }
</style>

HTML part:

Everything work fine, but when I add 'DOCTYPE' element in the beginning of the HTML document:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

the width of 'a' element is not taken into account.

Question 1: Why?

Question 2: How to fix that?

Thanks a lot!

解决方案

Question 1: Why?

Because it's by default not a block element.

Question 2: How to fix that?

Make it a block element using display: block;, or an inline block by display: inline-block;.

这篇关于HTML + CSS:'a'宽度不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆