2016-04-17 48 views
0

我怎样才能改变一个div的位置时,第二个是不可用的,例如:我怎样才能让一个两个div敏感,当第一个不可

enter image description here

所以当Div2的无法使用我需要Div1代替div2,如右图所示。

下面是代码

.fu-article-img { 
 
       img { 
 
       position: relative; 
 
       z-index: -1; 
 

 
       width: 100%; 
 
       max-width: 100%; 
 
       } 
 
       .label { 
 
       font-family: $font-open-sans; 
 
       font-size: 12px; 
 
       font-weight: bold; 
 

 
       position: absolute; 
 
       right: 15px; 
 

 
       display: table; 
 

 
       padding: 5px 10px; 
 

 
       border-radius: 0; 
 
       
 
       &.fu-category { 
 
        margin-top: -55px; 
 
       } 
 
       
 
       &.fu-category-tag { 
 
        margin-top: -33px; 
 

 
        color: #324358; 
 
        background-color: white; 
 
        
 
       } 
 
       } 
 
    }
<div class="fu-article-img"> 
 
<a href="#" itemprop="url"> 
 
    <img  src="http://animals.sandiegozoo.org/sites/default/files/juicebox_slides/koala_ecalypt.jpg" title="A Different C.L.A.S.S. of Sustainability" alt="A Different C.L.A.S.S. of Sustainability" class="img-responsive" /> 
 
</a> 
 
    <a href="#"> 
 
    <div class="label label-primary fu-category"> 
 
     div1blablala 
 
    </div> 
 
    </a> 
 
    <a href="#1"> 
 
    <div class="label label-primary fu-category-tag"> 
 
     div2blablala 
 
    </div> 
 
    </a> 
 
</div>

+0

它总是1或2,或者你想让它适用于任何数量的div? –

回答

1

作为一种理念,我提议两个标签,包装成一个街区,它们对齐底部。

.fu-summary { 
 
    border: 1px solid black; 
 
    position: absolute; 
 
    right: 30px; 
 
    bottom: 30px; 
 
    background: white; 
 
    padding: 5px; 
 
} 
 

 

 
.fu-article-img { 
 
    border: 1px solid black; 
 
    float: left; 
 
    position: relative; 
 
} 
 

 
.fu-article-img { 
 
       img { 
 
       position: relative; 
 
       z-index: -1; 
 

 
       width: 100%; 
 
       max-width: 100%; 
 
       } 
 
       .label { 
 
       font-family: $font-open-sans; 
 
       font-size: 12px; 
 
       font-weight: bold; 
 

 
       position: absolute; 
 
       right: 15px; 
 

 
       display: table; 
 

 
       padding: 5px 10px; 
 

 
       border-radius: 0; 
 
       
 
       &.fu-category { 
 
        margin-top: -55px; 
 
       } 
 
       
 
       &.fu-category-tag { 
 
        margin-top: -33px; 
 

 
        color: #324358; 
 
        background-color: white; 
 
        
 
       } 
 
       } 
 
    }
<div class="fu-article-img"> 
 
<a href="#" itemprop="url"> 
 
    <img  src="http://animals.sandiegozoo.org/sites/default/files/juicebox_slides/koala_ecalypt.jpg" title="A Different C.L.A.S.S. of Sustainability" alt="A Different C.L.A.S.S. of Sustainability" class="img-responsive" /> 
 
</a> 
 
    <div class="fu-summary"> 
 
    <a href="#"> 
 
     <div class="label label-primary fu-category"> 
 
     div1blablala 
 
     </div> 
 
    </a> 
 
    <a href="#1"> 
 
     <div class="label label-primary fu-category-tag"> 
 
     div2blablala 
 
     </div> 
 
    </a> 
 
    </div> 
 
</div>

如果你愿意,你可以做这样的JavaScript DOM变化。这里只是一个概念验证:

var fuArticleImg = document.querySelector(".fu-article-img"); 
// Find anchors without first one. 
var anchors = document.querySelectorAll(".fu-article-img a:not([itemprop])"); 
// Create new container 
var newContainer = document.createElement("div"); 
newContainer.addAttribute("class", "fu-summary"); 
// Add anchors to container. 
for (var i = 0; i < anchors.length; i++) { 
    newContainer.append(anchors[i]); 
} 
// Remove anchors. 
for (var i = 0; i < anchors.length; i++) { 
    fuArticleImg.removeChild(anchors[i]); 
} 
// Add container with anchors. 
fuArticleImg.append(newContainer); 
+0

是啊!这将有所帮助,但现在我无法将另一个包装添加到标签。这实际上是为不同项目复制了至少20次的模板的一部分,希望有另外的选择。 –

+0

你有JavaScript吗?您可以在运行时更改DOM。 –

+0

是啊!任何想法与JS? –

相关问题