简体   繁体   English

HTML / CSS:如何为不同类型的文章制作一个“文章”的多个“版本”

[英]HTML/CSS: How to make multiple 'versions' of an 'article' for different types of articles

I made a chat application in Java, and am using javascript, HTML, and CSS for the front end. 我用Java开发了一个聊天应用程序,并且前端使用javascript,HTML和CSS。 For the app you can send a public or a private message. 对于该应用程序,您可以发送公开消息或私人消息。 The javascript grabs the message from a text box and sends it to the server, which then makes an HTML message out of it and returns it as a rendered article. javascript从文本框中获取消息并将其发送到服务器,然后服务器从中提取HTML消息并将其作为渲染的文章返回。

I want to have public and private messages be displayed in different colors so it's easy to distinguish between them. 我希望公共和私人消息以不同的颜色显示,因此很容易区分它们。

This is the function that gets called to render a public message: 这是调用以呈现公共消息的函数:

   private static String createHtmlMessageFromSender(String sender, String message) {
        return article(
                b(sender + " says:"),
                span(attrs(".timestamp"), new SimpleDateFormat("HH:mm:ss").format(new Date())),
                p(message)
        ).render();
    }

This one gets called to render a private message: 调用此命令以呈现私人消息:

private static String createHtmlMessageFromSenderPrivate(String sender, String message) {
    return article(
            b(sender + " says to you:"),
            span(attrs(".timestamp"), new SimpleDateFormat("HH:mm:ss").format(new Date())),
            p(message)
    ).render();
}

I'm pretty new to HTML and CSS. 我对HTML和CSS很陌生。 Both private and public messages are being rendered as 'article's and put in a div object called 'chat.' 私人消息和公共消息都被渲染为“文章”,并放入称为“聊天”的div对象中。 I don't know if it's possible to make two different 'versions' of '#chat article' in my CSS file so that it can have one type of styling for private messages and one type for public messages. 我不知道是否可以在我的CSS文件中对“ #chat article”进行两个不同的“版本”处理,以使其对于私人消息具有一种样式,对于公共消息具有一种样式。 This seems like it would be a common thing to do but I can't find information about it. 这似乎很常见,但是我找不到有关它的信息。 Thanks. 谢谢。

Not a Java guy, but it sounds like you want to give each new node you're rendering a class, and style it in CSS like so: 不是Java的家伙,但是听起来您想给要渲染的每个新节点一个类,并在CSS中对其进行样式设置,如下所示:

.firstClassName {
    color: red;
}

.secondClassName {
    color: blue;
}

I would use one of these options: 我将使用以下选项之一:

1) Using 2 different ids (like #chat and #privatechat) where you could set a different color for one or another in css. 1)使用2个不同的ID(例如#chat和#privatechat),您可以在CSS中为一个或另一个设置不同的颜色。

2) Set a style attribute for each case eg 2)为每种情况设置样式属性,例如

<div id="chat" style="background-color:#ababab">private</div>

or 要么

<div id="chat" style="background-color:#cecece">public</div>

3) Use Sass ( https://sass-lang.com/ ) to control your stylesheets. 3)使用Sass( https://sass-lang.com/ )控制样式表。 Sass allow you to use conditional statements in your stylesheet. Sass允许您在样式表中使用条件语句。

Please let me know if you need more HTML help. 如果您需要更多HTML帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使文章的搜索栏工作 HTML/CSS - How to make the search bar for articles work HTML/CSS Webpack-捆绑多个/不同版本的.css文件 - Webpack - Bundle multiple/different versions of .css files select 篇文章 + 一次查询中每篇文章的多条评论 - select articles + multiple comments for each article in one query 如何在 HTML/CSS/JS 中重叠时使文本具有不同的颜色 - How to make text a different color on overlap in HTML/CSS/JS 如何将joomla表单(在文章中)重定向到不同的joomla文章? - How to redirect a joomla form (in article) to differents joomla articles? Nuxt/content - 如何在文章页面(_slug)上显示文章列表 - Nuxt/content - How to display a list of articles on the article page (_slug) 如何使用Facebook api和帖子中的文章缩略图共享Facebook上的文章? - How to share articles on Facebook using Facebook api with article thumbnail in the post? 如何使用 HTML、CSS 和 Js 使 div 位于所有屏幕类型中的特定元素旁边? - How can i make a div stay next to a specifc element in all Screens types with HTML, CSS and Js? 按下一篇文章对文章列表进行排序 - Sort a list of articles by next article 物品的高度根据其他物品调整 - Height of article adjusts with other articles
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM