在 C# ASP.NET 中全屏显示浏览器中的图像

发布于 2024-12-13 23:34:52 字数 502 浏览 4 评论 0原文

我想在浏览器页面中显示图像并拉伸它,以便它填充整个浏览器页面。

我尝试过:

<asp:Image ID="myimage" runat="server" ImageUrl="/Images/mypic.jpg" Width="100%" Height="100%"></asp:Image>

并且还尝试使用css:

<asp:Image ID="myimage" runat="server" ImageUrl="/Images/mypic.jpg"  CssClass="myimage1"></asp:Image>

并在CSS中:

.myimage1 {height:100%; width:100%;}

在这两种情况下,浏览器(IE9)都会以比浏览器大得多的高度拉伸图像高度并显示右侧滚动条。

如何将图像拉伸到当前页面尺寸的精确尺寸?

i want to show an image in the browser page and to stretch it so it would fill the whole browser page.

i tried:

<asp:Image ID="myimage" runat="server" ImageUrl="/Images/mypic.jpg" Width="100%" Height="100%"></asp:Image>

and also tried using css:

<asp:Image ID="myimage" runat="server" ImageUrl="/Images/mypic.jpg"  CssClass="myimage1"></asp:Image>

and in the CSS:

.myimage1{height:100%;width:100%;}

in both cases the browser (IE9), stretches the image with a height that is much bigger then the broswer hight and a right scroll bar is shown.

How can i stretch an image to the exact size of the current page size?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叶落知秋 2024-12-20 23:34:52

它拉伸到父容器的 100%,这可能太宽了。尝试设置 body 和 html 元素的宽度值。

尝试设置

html, body { width: 100%; height: 100%; }

或者您可以使用 jQuery 首先找出父元素的宽度,然后将图像设置为该宽度。不需要使用 ASP 控件,只需 CSS 和 jquery。

$newheight = $('#yourimageid').parent().height();
$('#yourimageid').css('height', $newheight);

这将获取父元素的高度,然后将该值附加到 css 高度值

Its stretching to 100% of the parent container, which might be too wide. Try setting the width value of the body and html elements.

Try setting

html, body { width: 100%; height: 100%; }

Or you could use jQuery to find out the width of the parent element first and then set your image to that. No need to use ASP controls with this, just CSS and jquery.

$newheight = $('#yourimageid').parent().height();
$('#yourimageid').css('height', $newheight);

This will grab the parent elements height, and then append the value to the css height value

述情 2024-12-20 23:34:52

我找到了使用 img html 标签并使用 CSS 的解决方案:
http://bytes.com/topic/ asp-net/answers/850635-how-stretch-background-image-fill

将其添加到 body 标记内的 aspx 页面内:

<img src="Styles/mypic.jpg" alt="" />

在 css 中:

html,body 
{
    margin: 0; 
    padding: 0;
}

img
{
    position:absolute; 
    z-index:-1; 
    width:100%; 
    height:100%;
}

i found the solution using an img html tag and using CSS:
http://bytes.com/topic/asp-net/answers/850635-how-stretch-background-image-fill

add this inside the aspx page inside the body tag:

<img src="Styles/mypic.jpg" alt="" />

in the css:

html,body 
{
    margin: 0; 
    padding: 0;
}

img
{
    position:absolute; 
    z-index:-1; 
    width:100%; 
    height:100%;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文