简体   繁体   English

如何更改 thymeleaf 中链接(href 文本)的颜色?

[英]How to change color for links (href text) in thymeleaf?

I have the below link(href) in Thymeleaf page.我在 Thymeleaf 页面中有以下链接(href)。

<div class="product-preview-container"
    th:each="prodInfo : ${products}">
    <ul>
        <li>Product Code:  <span th:utext="${prodInfo.productCode}"></span></li>
        <li>Product Name:  <span th:utext="${prodInfo.productName}"></span></li>
        <li>Product Price: Rs <span th:utext="${prodInfo.productPrice}"></span></li>
        <li><a th:href="@{|/shopping/buyProduct?code=${prodInfo.productCode}|}" th:color="white">Add to Cart</a></li>
    </ul>
</div>

CSS CSS

.product-preview-container {
    border: 1px solid #ccc;
    padding: 5px;
    width: 250px;
    margin: 10px ;
    display: inline-block;
    text-align:left;
    color: white;
}
  
.product-preview-container input {
    width: 50px;
}

Output: Output:

在此处输入图像描述

Product Code, Product Name and product Price all are coming in white. Product Code, Product Name and product Price 都是白色的。 Except the Add to Cart potion. Add to Cart药水除外。 My background has an image of blue color.我的背景有蓝色图像。 I want to make the link Add to Cart to be displayed in white.我想让Add to Cart的链接以白色显示。 How to do that?怎么做?

Simply,简单地,

You can add a color to <a> tag.您可以向<a>标签添加颜色

.product-preview-container a{
  color: white;
} 

 .product-preview-container { border: 1px solid #ccc; padding: 5px; width: 250px; margin: 10px; display: inline-block; text-align:left; color: white; }.product-preview-container input { width: 250px; }.bgblue{ background:#034d89; width: 282px; /* inner div width+margin+padding+border = 250+1*10+2*5+2*1=282px */ }.product-preview-container a{ color: white; }
 <div class="bgblue"> <div class="product-preview-container" th:each="prodInfo: ${products}"> <ul> <li>Product Code: <span th:utext="${prodInfo.productCode}"></span></li> <li>Product Name: <span th:utext="${prodInfo.productName}"></span></li> <li>Product Price: Rs <span th:utext="${prodInfo.productPrice}"></span></li> <li><a th:href="@{|/shopping/buyProduct?code=${prodInfo.productCode}|}" th:color="white">Add to Cart</a></li> </ul> </div> </div>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM