[英]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.