背景
我已经将一个带有折叠文本对象的简单表放在一起,当单击它时,会展开以显示与标题/标题相关的更多详细信息。
代码: JSFiddle
问题
当行元素展开时,它会强制内容与其标题相同的列,而不是占据整行的宽度以显示所有三列下面的文本。与此类似:
Normal State / Collapsed:
-----------------------------------------
| > Title to expand | x | ✓ |
-----------------------------------------
Intended State / Expanded:
-----------------------------------------
| ⌄ Title to expand | x | ✓ |
| Item explanation - spans entire width |
-----------------------------------------
Not intended when expanded (problem):
-----------------------------------------
| ⌄ Title to expand | x | ✓ |
| Item explanation - |
| spans entire width |
-----------------------------------------
or
-------------------------------------------------------------
| ⌄ Title to expand | x | ✓ |
| Item explanation - spans entire width |
-------------------------------------------------------------
预期结果
上面(中间)图显示了最终结果应该是什么样子。我知道使用display: none;
来隐藏行,但是,我不希望内容在一个单独的行中,而是“扩展”它所在的那个。
问题
如何以解释填充3列下方整行的宽度的方式展开项目?这里有任何帮助,我相信那里有一些CSS专家。我希望这些例子能说清楚,如果您需要更多信息,请告诉我。我总是非常乐意详细说明。欢呼声。
答案 0 :(得分:1)
将图标放在同一个td
中,然后使用一些margin-right
将它们向右浮动:
@import url("https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300italic,400,600");
@import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css");
/* Reset */
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
display: block;
}
body {
line-height: 1;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
body {
font-family: 'Source Sans Pro', sans-serif;
font-size: 18pt;
line-height: 1.75em;
font-weight: 300;
letter-spacing: 1px;
color: #3a3939;
text-shadow: 0 0 0.5px rgba(58, 57, 57, 0.25);
-webkit-text-stroke: 0.25px;
}
p,
ul,
ol,
dl,
table {
margin-bottom: 1em;
}
.table-wrapper {
width: 100%;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
}
th,
td {
text-align: center;
padding: 16px;
}
th:first-child,
td:first-child {
text-align: left;
}
tr:nth-child(even) {
background-color: #f2f2f2
}
.fa-check {
color: green;
}
.fa-remove {
color: red;
}
.icon {
text-decoration: none;
}
.icon:before {
display: inline-block;
font-family: FontAwesome;
font-size: 1.25em;
text-decoration: none;
font-style: normal;
font-weight: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon>.label {
display: none;
}
.tooltipz {
position: relative;
display: inline-block;
}
.tooltipz .tooltiptext {
visibility: hidden;
width: 200px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 10px;
position: absolute;
z-index: 1;
bottom: 150%;
left: 50%;
margin-left: -100px;
font-size: 15px;
line-height: normal;
}
.tooltipz .tooltiptext::after {
content: " ";
position: absolute;
top: 100%;
/* At the bottom of the tooltip */
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: black transparent transparent transparent;
}
.tooltipz:hover .tooltiptext {
visibility: visible;
}
summary::-webkit-details-marker {
color: #00ACF3;
margin-right: 2px;
}
summary:focus {
outline-style: none;
}
article>details>summary {
margin-top: 16px;
}
details>p {
margin-left: 24px;
text-align: justify;
}
details details {
margin-left: 36px;
}
td .fa {
float: right;
margin-right: 10%;
margin-top: 2%;
}
<div class="table-wrapper default">
<table>
<tr>
<td>First row
<i class="fa fa-check"></i>
<i class="fa fa-check"></i>
</td>
</tr>
<tr>
<td>
<i class="fa fa-check"></i>
<i class="fa fa-remove"></i>
<details>
<summary>Expanded Row</summary>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in metus a nisl molestie mattis a in mauris. Vestibulum orci metus, tincidunt quis commodo nec, pellentesque quis erat.</p>
</details>
</td>
</tr>
<tr>
<td>
Last Row
<i class="fa fa-check"></i>
<i class="fa fa-remove"></i>
</td>
</tr>
</table>
</div>