2016-12-15 25 views
-1

的CSS:風格如果文本只有一行在CSS?的

<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been 
the industry's standard dummy text ever since the 1500s, when an unknown</p> 

風格會比較不同的文字只有一個行:

<p>Lorem Ipsum is simply dummy text</p> 

這可能嗎? 非常感謝你:)

+0

你是什麼意思? –

回答

0

簡短的回答是沒有。段落中實際文本的長度不影響它的風格。

但是,如果您在類或ID的內部分配段落標記,那麼您可以將每個單獨的類或ID設置爲CSS樣式表中的獨特樣式。

0

您是否希望段落中的行具有不同的樣式,如果是這樣,您可以使用不同的樣式將區段添加到您想要的區域。

#line{ 
 
    font-weight: bold; 
 
}
<p><span id="line">Lorem Ipsum is simply dummy text</span> of the printing and typesetting industry. Lorem Ipsum has been 
 
the industry's standard dummy text ever since the 1500s, when an unknown</p>

0

如果您正在尋找針對單一VS多一句CSS,這是不可能的。

如果你想限制你的<p>只有一行使用white-space: nowrap;

0

你將不得不用JavaScript來編程。

查找段落元素,檢查內容的長度,然後應用基於該段落的樣式。

這裏有一個jsfiddle來說明(用jQuery)。

HTML

<p>A short line.</p> 
<p>A longer line with more words in it.</p> 

JS

$("document").ready(function() { 
    $("p").each(function() { 
    if($(this).text().length > 15) { 
     $(this).css("color", "red"); 
    } 
    }); 
});