gpt4 book ai didi

javascript - 右对齐表格标题中图标的下拉菜单

转载 作者:行者123 更新时间:2023-11-28 16:27:06 24 4
gpt4 key购买 nike

我想打开一个下拉菜单,该菜单与图标下方的对齐,该图标出现在表格标题的span 中。

这是我得到的:

This is what I get

它在图标下方自然地对齐,但我找不到将其与对齐的好方法。

这就是我真正想要的:

This is what I want

Some suggestions建议使用 right:0; 并将过滤器容器定位为 absolute。这对我来说并不好,因为我希望表格标题单元格中的图标与单元格的右侧对齐。将容器设置为 absolute 会使表格标题中的图标难以对齐。

如果可能,我正在寻找纯 CSS 解决方案。表格单元格的宽度和下拉菜单的宽度是固定的,所以我无法通过指定“像素”来对齐内容。

table {
font-family:Arial, Helvetica, sans-serif;
color:#666;
font-size:12px;
text-shadow: 1px 1px 0px #fff;
background:#eaebec;
margin:20px;
border:black 1px solid;
border-radius:3px;
border-collapse: collapse;
box-shadow: 0 1px 2px #d1d1d1;
}

table, th, td {
border: 1px solid black;
}


table th {
width:150px;
}

.context-icon {
float:right;
cursor:default;
color: green;
padding-right: 10px;
padding-left: 10px;

//position: absolute;
}

.filter {
visibility: hidden;
display: block;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 2px 6px;
max-height: 0px;
z-index: 1000;
height:auto;
transition: visibility 200ms, max-height 200ms ease-in-out;

//right:0;
}

.filter-open {
display: block;
max-height: 300px;
visibility: visible;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />

<body>

<table>
<thead>
<tr>
<th>first</th>
<th>
second
<span>
<i class="context-icon fa fa-lg fa-filter">
<select multiple class="filter filter-open">
<option >option1</option>
<option >option2</option>
<option >option3</option>
</select>
</i>
</span>
</th>
<th>third</th>
</tr>
</thead>

<tbody>
<tr>
<td>xxx</td>
<td>xxx</td>
<td>xxx</td>
</tr>
<tr>
<td>xxx</td>
<td>xxx</td>
<td>xxx</td>
</tr>
</tbody>
</table>

</body>

最佳答案

我已经添加了相对于 i 的位置,并向选择右侧添加了 0px :

i {
position: relative;
}
i select {
right: 0px;
}

table {
font-family:Arial, Helvetica, sans-serif;
color:#666;
font-size:12px;
text-shadow: 1px 1px 0px #fff;
background:#eaebec;
margin:20px;
border:black 1px solid;
border-radius:3px;
border-collapse: collapse;
box-shadow: 0 1px 2px #d1d1d1;
}

table, th, td {
border: 1px solid black;
}


table th {
width:150px;
}

.context-icon {
float:right;
cursor:default;
color: green;
padding-right: 10px;
padding-left: 10px;

//position: absolute;
}

.filter {
visibility: hidden;
display: block;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 2px 6px;
max-height: 0px;
z-index: 1000;
height:auto;
transition: visibility 200ms, max-height 200ms ease-in-out;

//right:0;
}

.filter-open {
display: block;
max-height: 300px;
visibility: visible;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />

<body>

<table>
<thead>
<tr>
<th>first</th>
<th>
second
<span>
<i class="context-icon fa fa-lg fa-filter">
<select multiple class="filter filter-open">
<option >option1</option>
<option >option2</option>
<option >option3</option>
</select>
</i>
</span>
</th>
<th>third</th>
</tr>
</thead>
</table>

</body>

关于javascript - 右对齐表格标题中图标的下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35911485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com