doumor942473
doumor942473
2017-04-18 10:08

我的跨度有什么区别?

已采纳

I have two spans inside my echo:

echo '<div class="elementsDiv" id="'.$row['objekt_nr']."_".$row['element_nr'].'" data-weight="'.$row['vikt'].'"  data-nr="'.$row['element_nr'].'" style="width: '.$langd.'px; height: '.$bredd.'px;><span class="elementDivNr">'.$row['element_nr'].'</span><span class="elementDivWeight">'.round($viktT, 2).' t</span></div>';

Span with class: "elementDivNr" & span with class: "elementDivWeight".

I try to set a background color for the spans with CSS:

span.elementDivNr{
  background-color: red !important;
}
span.elementDivWeight{
  background-color: red !important;
}

Now... why is only one of them getting the red color background? How can I search for "overrides"?

enter image description here

My code is pretty big in both CSS and JS as this is a "DnD" application.

UPDATE
It is strange is that I cannot access this span at all with CSS.

span.elementDivNr{
  background-color: red !important;
  font-size: 14px;
}

Changing font size has no effect either.

UPPDATE

https://jsfiddle.net/1u8evdr8/

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • dongyinting3179 dongyinting3179 4年前

    You are missing a closing " on your style tag of your DIV.

    So this:

    echo '<div class="elementsDiv" id="'.$row['objekt_nr']."_".$row['element_nr'].'" data-weight="'.$row['vikt'].'"  data-nr="'.$row['element_nr'].'" style="width: '.$langd.'px; height: '.$bredd.'px;><span class="elementDivNr">'.$row['element_nr'].'</span><span class="elementDivWeight">'.round($viktT, 2).' t</span></div>';
    

    Should be this:

    echo '<div class="elementsDiv" id="'.$row['objekt_nr']."_".$row['element_nr'].'" data-weight="'.$row['vikt'].'"  data-nr="'.$row['element_nr'].'" style="width: '.$langd.'px; height: '.$bredd.'px;"><span class="elementDivNr">'.$row['element_nr'].'</span><span class="elementDivWeight">'.round($viktT, 2).' t</span></div>';
    
    点赞 评论 复制链接分享
  • doulanyan6455 doulanyan6455 4年前

    If you observe style attr is not closed with " in the code please close it

     echo '<div class="elementsDiv" id="'.$row['objekt_nr']."_".$row['element_nr'].'" 
    data-weight="'.$row['vikt'].'"  
    data-nr="'.$row['element_nr'].'" 
    style="width: '.$langd.'px; height: '.$bredd.'px;"><span class="elementDivNr">'.$row['element_nr'].'</span><span class="elementDivWeight">'.round($viktT, 2).' t</span></div>';
    
    点赞 评论 复制链接分享
  • dougu2036 dougu2036 4年前

    Found it..

    I was missing a closure " in the style prop.

    点赞 评论 复制链接分享

相关推荐