css - 使用 CSS 变量 Firefox

标签 css firefox css-variables

我正在开发一个完整的 CSS 选项卡导航。 这就是我想要做的:http://jsfiddle.net/7fZnn/1/

但我不想使用内联 CSS 来放置我的标签。所以我研究了用什么来替代这个内联 CSS。我找到那些:

  • attr() 函数,仅在选择元素时支持 content 属性 :before of :after
  • CSS 计数器。那太好了,但是作为 attr() 函数,这只适用于内容属性
  • CSS 变量,这应该在 Firefox 29 中工作,实际上我使用 30。但它没有,我不知道为什么...

这是我的带有 CSS 变量(和注释中的计数器)的代码:http://jsfiddle.net/j8wxQ/2/

HTML

<div class="container">
    <div class="tabs">
        <div class="tab" id="foo">
            <a href="#foo">Foo</a>
            <div class="content">
                <h1>Onglet 1</h1>
                <p>Lorem Ipsum...</p>
            </div>
        </div>
        <div class="tab" id="bar">
            <a href="#bar">Bar</a>
            <div class="content">
                <h1>Onglet 2</h1>
                <p>Lorem Ipsum...</p>
            </div>
        </div>
        <div class="tab" id="toto">
            <a href="#toto">Toto</a>
            <div class="content">
                <h1>Onglet 3</h1>
                <p>Lorem Ipsum...</p>
            </div>
       </div>
       <div class="tab" id="tata">
           <a href="#tata">Tata</a>
           <div class="content">
               <h1>Onglet 4</h1>
               <p>Lorem Ipsum...</p>
           </div>
       </div>
       <div class="tab default" id="titi">
           <a href="#titi">Titi</a>
           <div class="content">
               <h1>Onglet 5</h1>
               <p>Lorem Ipsum...</p>
           </div>
       </div>
    </div>
</div>

CSS

:root {
    var-tab: 0px;
}

@media screen and (min-width: 1025px) {
    .container {
        width: 1000px;
        margin: auto;
    }
}

@media screen and (max-width: 1024px) and (min-width: 641px) {
    .container {
        width: 99%;
        margin: auto;
    }
}

@media screen and (max-width: 640px) {
    .container {
        width: 100%;
        margin: 0;
        padding: 0;
    }

    body, html {
        margin: 0;
        padding: 0;
    }
}

.tabs {
    position: relative;
    width: 100%;
    /*counter-reset: tab 0;*/
}

.tab {
    /*counter-increment: tab;*/
    var-tab: calc(var(tab) + 75px);
}

.tab .content {
    display: none;
    position: absolute;
    top: 50px;
    margin-top: -5px;
    border: solid 5px rgba(0,0,255, 0.1);
    padding: 10px 10px 10px 10px;
}

.tab:target .content {
    display: block;
    position: absolute;
    top: 50px;
}

.tab.default .content{
    display: block;
    position: absolute;
    top: 50px;
}

.tab:target ~ .tab.default .content {
    display: none;
}

.tabs .tab a {
    position: absolute;
    top: 0;
    left: var(tab);
    /*left: calc(75px * counter(tab));*/
    display: inline-block;
    height: 45px;
    line-height: 45px;
    min-width: 75px;
    margin: 0;
    padding: 0;
    text-decoration: none;
    color: #000;
    vertical-align: middle;
    border-bottom: solid 5px rgba(0,0,255, 0.1);
    text-align: center;
}

.tabs .tab a:hover {
    border-bottom: solid 5px rgba(0,0,255,0.5);
}

.tabs .tab:target a {
    border-bottom: solid 5px rgba(0,0,255,1);
}

p {
    text-align: justify;
}

那么,我错过了什么?您认为我可以使用其他方法来实现我的目标吗?

感谢您的帮助!

最佳答案

你可以尝试改变这些:

.tab {
    /*counter-increment: tab;*/
    /*var-tab: calc(var(tab) + 75px);*/
    width: 75px; //fixed width, like you did on your example
    display: inline-block;
}

.tab .content {
    display: none;
    position: absolute;
    top: 50px;
    left: 0; //push all content to the left edge of tab
    margin-top: -5px;
    border: solid 5px rgba(0,0,255, 0.1);
    padding: 10px 10px 10px 10px;
}

我已经给你更新了fiddle ,看看这是否适合您。

观察:选项卡之间的小间距可能是 html 标记,隐藏在 .tabs div 之间的空格字符。

关于css - 使用 CSS 变量 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23221463/

相关文章:

HTML CSS : Make Google Icon into Button without Rectangle around it

css - 一些浏览器不加载 CSS 和组件布局[Joomla]

javascript - JQuery 动画在 Firefox 中不起作用

javascript - "Http channel implementation doesn' t 支持 nsIUploadChannel2。一个扩展提供了一个非功能性的 http 协议(protocol)处理程序”

css - 如何在计算函数中使用CSS变量

html - 通过 <img> 在 SVG 中使用 CSS 变量

html - 顶部和子导航之间的空间

html - Div 宽度/高度 另一个 div 内可用空间的 100%

firefox - Firefox 的浏览器模式/仿真设置

css - Ionic 4 改变输入颜色