哪个元素阻止我的宽度属性应用于我的选项卡?

发布于 2024-12-31 22:57:46 字数 1564 浏览 0 评论 0原文

我对 HTML、CSS 和 Javascript 完全陌生,但利用以前对 Java 和 C 典型编程的了解以及大量教程和谷歌搜索,我已经拼凑出这一切如何工作的非常粗略的图像。

现在让我抓狂的是,我最近在我的网站中添加了一个选项卡式内容框,它位于主页上,允许您通过单击相应的选项卡来选择 4 个不同段落之一。我把它从教程中拉出来,并对它的工作原理有了基本的了解。但由于某种原因,我无法让它让我调整每个选项卡的宽度。

这是 html对于选项卡:

<div id="feature-tabs">
    <ul id="tabs">
        <li><a href="#What We Do">What We Do</a></li>
        <li><a href="#What Makes Us Different">What Makes Us Different</a></li>
        <li><a href="#Our Background">Our Background</a></li>
        <li><a href="#Why We Do It">Why We Do It</a></li>
    </ul>
</div>`

这是关联的 CSS 样式。

#feature-tabs {
    height: 16px;
    width: 150px;
}

ul#tabs {
     list-style-type: none; 
     margin: 0 0 2 0; 
}
    ul#tabs li {
        float: left;
    }
        ul#tabs li a {
            color: #42454a; 
            background-color: #dedbde; 
            border: 1px solid #c9c3ba; 
            border-bottom: none; 
            text-decoration: none;
            width: 150px;
        }
            ul#tabs li a:hover {
                background-color: #f1f0ee;
            }
            ul#tabs li a.selected {
                color: #000; 
                background-color: #f1f0ee; 
                font-weight: bold;
            }

我非常需要这个,所以为了我想要的外观,但我根本不明白为什么无论我把 width: ___px; 放在哪里,它都不适用。

我想知道我正在做的事情是否会阻止宽度成为适用的特征,或者您有什么。

提前致谢。

I'm completely new to HTML, CSS and Javascript but drawing on previous knowledge of typical programming from Java and C along with numerous tutorials and google searches I've been piecing together a very rough image of how this all works.

Now something that is driving me crazy is I recently added a tabbed content box into my website, one that is on the main page that allows you to select one of 4 different paragraphs by clicking on the appropriate tab. I pulled it off of a tutorial and have a basic understanding of how its working.. but for some reason I cannon get it to let me adjust the width of each of these tabs..

Here is the html for the tabs:

<div id="feature-tabs">
    <ul id="tabs">
        <li><a href="#What We Do">What We Do</a></li>
        <li><a href="#What Makes Us Different">What Makes Us Different</a></li>
        <li><a href="#Our Background">Our Background</a></li>
        <li><a href="#Why We Do It">Why We Do It</a></li>
    </ul>
</div>`

And here is the associated CSS that styles it.

#feature-tabs {
    height: 16px;
    width: 150px;
}

ul#tabs {
     list-style-type: none; 
     margin: 0 0 2 0; 
}
    ul#tabs li {
        float: left;
    }
        ul#tabs li a {
            color: #42454a; 
            background-color: #dedbde; 
            border: 1px solid #c9c3ba; 
            border-bottom: none; 
            text-decoration: none;
            width: 150px;
        }
            ul#tabs li a:hover {
                background-color: #f1f0ee;
            }
            ul#tabs li a.selected {
                color: #000; 
                background-color: #f1f0ee; 
                font-weight: bold;
            }

I need this very much so for the look I'm going for but I simply cannot find out why no matter where I put width: ___px; it just won't apply.

I am wondering if there is something I'm doing which prevents width from being an applicable trait or what have you.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抚你发端 2025-01-07 22:57:46

尝试添加此样式:

ul#tabs li a {
    // ..
    display: block;
}

发生这种情况是因为 a 默认情况下是内联元素。内联元素不会对高度/宽度做出反应。

Try adding this style:

ul#tabs li a {
    // ..
    display: block;
}

This happens because a is an inline element by default. Inline elements don't react to height/width.

夕色琉璃 2025-01-07 22:57:46

将以下规则添加到您的链接:

ul#tabs li a { display: inline-block; }

Add the following rule to your link :

ul#tabs li a { display: inline-block; }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文