簡體   English   中英

ASP.NET 背景圖像

[英]ASP.NET Background image

我正在使用 VS2005 C#。

我有一個.aspx登錄頁面,我想為它實現一個背景圖像。 下面是我當前的頁面截圖:

在此處輸入圖片說明

以下是我的背景代碼:

    <div align="center" style="background-color: transparent; background-image: url(Images/blue.jpg);">
<asp:login id="Login1" runat="server" font-size="Large" BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#333333" DestinationPageUrl="~/Common/Default.aspx" DisplayRememberMe="False" FailureText="Login failed" RememberMeSet="False" Height="224px" Width="384px">
    <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em" ForeColor="White" />
    <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
   <TextBoxStyle Font-Size="0.8em" />
    <LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px"
    Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775" />
</asp:login>
</div>

我試圖將<div>標簽放在外面,但背景圖像似乎與登錄控件的寬度高度卡住了。

我可以知道如何擴展圖像以覆蓋整個背景嗎?

謝謝

1) 使用 CSS 樣式表 - 添加<link rel="stylesheet" type="text/css" href="styles.css" />以包含它。

2)將背景應用到身體:

body {
    background-image:url('images/background.png');
    background-repeat:no-repeat;
    background-attachment:fixed;
}

看:

http://www.w3schools.com/css/css_howto.asp

http://www.w3schools.com/cssref/pr_background-position.asp

像這樣在 body 標簽中編寫代碼

<body style="background-image: url('Image URL');" >
</body>

在后面的代碼中使用此代碼

Div_Card.Style["background-image"] = Page.ResolveUrl(Session["Img_Path"].ToString());

如果要將圖像設置為整個頁面的背景,請使用以下命令:

body
{
    background-image: url('Image URL');
}

在圖像編輯器中將背景圖像調整為與登錄框相關的所需大小,這應該有助於頁面加載並保持圖像質量...

相對於您的圖像硬調整您的 DIV

將您的 asp:login 控件放置在需要的位置...

只是提醒一下,雖然這里發布的一些答案是正確的(從某種意義上說),您可能需要做的一件事是返回根文件夾,深入研究包含要設置為背景的圖像的文件夾. 換句話說,此代碼在實現您的目標方面是正確的:

body {
    background-image:url('images/background.png');
    background-repeat:no-repeat;
    background-attachment:fixed;
}

但您可能還需要在代碼中添加更多內容,如下所示:

body {
    background-image:url('../images/background.png');
    background-repeat:no-repeat;
    background-attachment:fixed;
}

正如您所看到的,不同之處在於您可能需要在“images/background.png”調用前添加“../”。 同樣的規則也適用於 HTML5 網頁。 因此,如果您正在嘗試此處列出的第一個示例代碼,但仍然沒有獲得背景圖像,請嘗試在“圖像”前添加“../”。 希望這可以幫助 。

如果要在后端分配背景圖像,可以使用它:

divContent.Attributes.Add("style"," background-image:
url('images/icon_stock.gif');");
body {
    background-image: url('../images/background.jpg');
    background-repeat: no-repeat;
    background-size: cover; /* will auto resize to fill the screen */
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM