通常在诸如食谱之类的网站上,人们会看到大量文本(例如食谱方法),其中并非所有文本都显示有“更多...”超链接,您可以单击该超链接来显示所有内容.
我正在尝试做类似的事情,但正如我目前所做的那样,我将 height 属性应用于相关的 div 元素,这会减少文本的数量。
topicGenerator.InnerHtml += "<div class='productList summaryContainer'>";
topicGenerator.InnerHtml += "<div class='productListTumbnail'>";
topicGenerator.InnerHtml += "<img src ='Images/ScreenShots/" + productCode + ".jpg' alt='Health and Safety'>";
topicGenerator.InnerHtml += "</div>";
topicGenerator.InnerHtml += "<div class='productListContent'>";
topicGenerator.InnerHtml += "<h3>" + productName + "</h3>";
topicGenerator.InnerHtml += summary;
topicGenerator.InnerHtml += "</div>";
topicGenerator.InnerHtml += "</div>";
.summaryContainer
{
height:120px;
overflow:hidden;
}
这远非理想。 我是否可以在单击相关超链接(例如更多...)时帮助扩展摘要文本数量,或者可能只是减少一定数量文本(html)然后在单击时重定向到不同页面的好方法相关超链接。
最佳答案
为什么不使用 Substring Method :
summary.Substring(0, 200) //Prints 200 first chars.
关于c# - 减少摘要中的文本量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16582416/