css - 如何在 ListView 中轻松创建固定标题 asp.net

标签 css asp.net listview

我试图在滚动时保持标题固定,但我无法弄清楚。

这是我的 ListView 代码:

    <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="FormSectionSubSectionItemRelID" OnSelectedIndexChanged="ListView1_SelectedIndexChanged">

这是我的 sites.css 表的 CSS 代码:

table {
border-collapse: collapse;
border-spacing: 0;
margin-top: 0.75em;
border: 0 none;
}

th {
font-size: 1.2em;
text-align: left;
border: none 0px;
padding-left: 0;
}

th a {
    display: block;
    position: relative;

}

th a:link, th a:visited, th a:active, th a:hover {
    color: #333;
    font-weight: 600;
    text-decoration: none;
    padding: 0;
}

th a:hover {
    color: #000;
}

th.asc a, th.desc a {
    margin-right: .75em;
}

th.asc a:after, th.desc a:after {
    display: block;
    position: absolute;
    right: 0em;
    top: 0;
    font-size: 0.75em;
}

th.asc a:after {
    content: '▲';
}

th.desc a:after {
    content: '▼';
}

td {
padding: 0.25em 2em 0.25em 0em;
border: 0 none;
}

tr.pager td {
padding: 0 0.25em 0 0;
}

如果有一个属性我可以更改或更改我的 css 代码,那就太好了。

最佳答案

如果您也可以从服务器端获取您的代码并创建您的代码演示,这将非常有助于为您解决这个问题。

然而,只是浏览你的代码,看看你是如何询问试图在你的页面顶部固定一些东西的,我在你的 css 代码中看到一个绝对定位的元素在页面顶部我假设你希望这个元素在滚动时固定吗?

如果是这种情况,那么您需要将此代码从绝对更改为固定。

th.asc a:after, th.desc a:after {
  display: block;
  position: fixed; //fixed will not scroll with the page, where absolute will.
  right: 0em;
  top: 0;
  font-size: 0.75em;
}

关于css - 如何在 ListView 中轻松创建固定标题 asp.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24310220/

相关文章:

javascript - 鼠标悬停时的上下文菜单

html - 字体不适用于 IE8 ??获取@font-face 遇到未知错误。 ?

javascript - 居中不是div中的所有内容

c# - 什么时候清除 ViewState session ?

database - Listview - 用数据库中的相应项目填充第二列

css - 覆盖 :visited overrides :link :hover :active

asp.net - 使用 jQuery 和参数在 MVC 中调用操作方法不起作用

c# - 项目停止构建并将 '.1' 附加到项目 .dll

android - Activity 中的 QuickReturn ListView? Activity 中的 2 个 View 有困难

android - 为什么我会在这一行收到 NullPointerException?