存在替换<details>
元素的展开宏的可能性,这在例如Can I replace The expand icon中进行了描述(▶)<详细信息>要素以及答案https://stackoverflow.com/a/10813665/1657886
通常,<details>
元素中会有一个<summary>
,并且一切都很好,但当<summary>
元素丢失时,浏览器将返回到默认文本";细节";和默认图标。
CSS代码在存在<summary>
元素的情况下工作:
details>summary {
list-style-type: none;
}
details > summary::-webkit-details-marker {
display: none;
}
details>summary::before {
content: "25ba";
padding-right:4px;
font-size: 80%;
}
details[open]>summary::before {
content: "25bc";
padding-right:4px;
font-size: 80%;
}
问题是,如果<summary>
元素丢失,如何设置图标?
编辑完整示例(文件名:aa.html(:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<title>My Project</title>
<style>
details>summary {
list-style-type: none;
}
details > summary::-webkit-details-marker {
display: none;
}
details>summary::before {
content: "25ba";
padding-right:4px;
font-size: 80%;
}
details[open]>summary::before {
content: "25bc";
padding-right:4px;
font-size: 80%;
}
</style>
</head>
<body>
<details >
<summary> The summary 1</summary> The details 1
</details>
<details >
The details no own summary
</details>
</body>
</html>
details {
position: relative;
}
/* details>summary {
list-style-type: none;
}
details > summary::-webkit-details-marker {
display: none;
} */
details::before,
details[open]::before {
display: inline-block;
transform: translate(2px, 1px);
position: absolute;
z-index: 1;
top: 0;
left: 0;
font-weight: 900;
}
details::after,
details[open]::after {
display: inline-block;
transform: translate(-3px, -2px);
position: absolute;
content: "";
width: 15px;
height: 22px;
background: #fff;
top: 0;
left: 0;
}
details::before {
content: " 02b";
}
details[open]::before {
content: " 02d";
}
<details>
<!-- <summary>Click to expand</summary> -->
With some example text shown when expanded.
</details>
由于一旦删除summary
元素(或者至少我找不到(,就无法获取公开小部件,因此解决方案必须有点麻烦。