如何在Thymeleaf中为链接(href文本)更改颜色?

huangapple go评论85阅读模式
英文:

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

问题

我在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

.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;
}

输出 :

如何在Thymeleaf中为链接(href文本)更改颜色?

产品编号、产品名称和产品价格都显示为白色。只有“Add to Cart”链接部分不是白色。我的背景图像是蓝色的。我希望将“Add to Cart”链接显示为白色。怎么做呢?

英文:

I have the below link(href) in Thymeleaf page.

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

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 :

如何在Thymeleaf中为链接(href文本)更改颜色?

Product Code, Product Name and product Price all are coming in white. Except the Add to Cart potion.
My background has an image of blue color. I want to make the link Add to Cart to be displayed in white. How to do that ?

答案1

得分: 2

以下是翻译好的内容:

简而言之,

您可以为 &lt;a&gt; 标签添加一个颜色

.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;
    /* 内部 div 宽度+外边距+内边距+边框 = 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>产品代码:<span th:utext="${prodInfo.productCode}"></span></li>
          <li>产品名称:<span th:utext="${prodInfo.productName}"></span></li>
          <li>产品价格:Rs <span th:utext="${prodInfo.productPrice}"></span></li>
          <li><a th:href="@{|/shopping/buyProduct?code=${prodInfo.productCode}|}" th:color="white">加入购物车</a></li>
      </ul>
  </div>
</div>
英文:

Simply,

You can add a color to &lt;a&gt; tag.

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

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-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: 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;
}

<!-- language: lang-html -->

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

<!-- end snippet -->

huangapple
  • 本文由 发表于 2020年9月22日 15:34:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/64005049.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定