【问题标题】:How to put button next to Image in CSS?如何在 CSS 中将按钮放在图像旁边?
【发布时间】:2014-05-20 00:00:09
【问题描述】:

在我的 asp.net 页面上,我有一些 Update Pannel。为了避免异步回发的问题,我必须将我的Print Button 放在面板外,但我的按钮的所有其他标签和图像仍在此面板内,所以我想控制 CSS 中的页面样式以放置我的 btnPrint就在image1 旁边。

这是我的页面布局:

<div id="Toolbar">
    <asp:UpdatePanel ID="UpdateToolbar" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Label ID="Label3" runat="server" Text="   Months: "></asp:Label>&nbsp;
            <asp:DropDownList ID="ddlMonth" runat="server"></asp:DropDownList>

            <asp:Label ID="Label2" runat="server" Text="   Year: "></asp:Label>&nbsp;
            <asp:DropDownList ID="ddlYear" runat="server"></asp:DropDownList>
            <b id="buttonWrap">>
                <asp:Image ID="Image2" runat="server" ImageUrl="Images/DefRefreshBtn.png" Width="15"
                    Height="20" />&nbsp;
                <asp:LinkButton ID="btnRefresh" runat="server" OnClick="btnRefresh_Click1">Refresh</asp:LinkButton>&nbsp;&nbsp;&nbsp;
                <asp:Image ID="Image1" runat="server" ImageUrl="Images/DefPrintBtn.png" Width="27"
                    Height="20" />
            </b>                   
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:LinkButton ID="btnPrint" runat="server" onclick="btnPrint_Click" CssClass="printBtn">Print</asp:LinkButton>&nbsp;&nbsp;&nbsp;
</div>

目前,我正在使用这个CssClass="printBtn"

.printBtn
{
    position: relative;
    top: -23px;
    right: -700px;
    font-weight: bold;
}

但这种硬编码可能会导致不同浏览器出现问题。有什么方法可以在 CSS 中将我的按钮指定在 image1 旁边吗?

【问题讨论】:

  • 需要实际输出的 HTML。
  • 向我们展示 html 的实际渲染,请不要使用asp 代码作为设计人员想要回答您的问题

标签: html css asp.net position css-position


【解决方案1】:

您需要使用绝对定位。更好的解决方案是将其保留在 UpdatePanel 中,但让打印按钮执行完整的回发。您可以使用 PostBackTrigger 来做到这一点

这里是如何做一个完整的回帖的例子 Force certain controls to do a full postback?

【讨论】:

  • 这应该是评论而不是答案。
  • 我不同意....这是一个建议。您对实际的 HTML 一无所知,因此绝对位置可能不合适。
  • 我同意这是建议,但这很有帮助。我找到了一个如何解决我的问题的例子。我会编辑并接受它。对不起 HTML 人=)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-02-15
  • 1970-01-01
  • 1970-01-01
  • 2016-01-06
  • 2019-01-13
  • 2019-01-02
  • 2022-08-18
相关资源
最近更新 更多