javascript - 如何更改百里香中链接(href 文本)的颜色?
问题描述
我在 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;
}
输出 :
产品代码、产品名称和产品价格都是白色的。除了Add to Cart
药水。我的背景有一个蓝色的图像。我想让链接Add to Cart
显示为白色。怎么做 ?
解决方案
简单地,
您可以为标签添加颜色。<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>
推荐阅读
- java - 如何在spring boot中区分名称相同但查询参数不同的edpoints
- html - Chart.js 时间序列
- oracle - Oracle Apex 5.1 显式调整卡片大小并将卡片限制为每行一张
- speech-recognition - 使用 Kaldi-ASR 识别语音命令?
- javascript - panTo() 方法干扰 Google Maps Javascript API 中的弹跳动画
- php - 将字符串拆分为 3 个随机长度的部分
- flutter - 在 Flutter 中实现 Blockly 小部件
- intellij-idea - 无法从 InteliJ UI 提交和推送恢复的提交到 bitbucket
- swiftui - 具有复杂视图模型的 SwiftUI 导航(延迟创建直到实际需要)
- javascript - 如何在其操作回调中禁用自定义 DataTables 按钮?