Html 如何在 ASP.NET MVC 5 RAZOR 中将图像添加到导航栏品牌

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24088955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:59:16  来源:igfitidea点击:

How to add image to navbar-brand in ASP.NET MVC 5 RAZOR

csshtmltwitter-bootstraprazorasp.net-mvc-5

提问by Robin

i am trying asp.net mvc these days but stuck in beginning phase. I want to place image in place of application name with title and alt tag. please help me.

这些天我正在尝试asp.net mvc,但停留在开始阶段。我想用标题和 alt 标签将图像代替应用程序名称。请帮我。

Thank you

谢谢

<div class="navbar-header pull-left">
    <a class="navbar-brand" href="index.html"><img src="img/accomodator-mini.png" title="title" alt="additional title" /></a>
</div>

how to do above in this way:

如何以这种方式执行上述操作:

 @Html.ActionLink("Application name", "Index", "Home", null, new { @class = "navbar-brand" })

i am confused how to show image in the place of Application name

我很困惑如何在应用程序名称的位置显示图像

回答by Nicolai

1 option:You can do everything in css:

1 个选项:您可以在 css 中完成所有操作:

.navbar-brand{
    background: url(http://placehold.it/350x150) no-repeat;
    background-size: 40px 40px;
    height:40px;
    margin:5px;
    width:40px;
}

JsFiddle example- in this example image is 350x150 px. And using background-sizeproperty you can adjust the image size.

JsFiddle 示例- 在此示例中,图像为 350x150 像素。并使用background-size属性可以调整图像大小。

2 option:

2选项:

<a href="@Url.Action("Index", "Home")" class="navbar-brand">
    <img src="img/accomodator-mini.png" title="title" alt="additional title" />
</a>

3 option:Define your own helper.

3 选项:定义你自己的 helper

回答by digitalman

Its simple. In MVC-5, this works.

这很简单。在 MVC-5 中,这有效。

<a href="@Url.Action("Index", "Home")" class="navbar-brand">
  <img src="~/Images/logo.png" title="title" alt="additional title" />
</a>

And make sure your logo is placed in the correct folder.

并确保您的徽标放置在正确的文件夹中。

回答by TheBokiya

You can do this:

你可以这样做:

@Html.ActionLink("Application name", "Index", "Home", null, new { @class = "navbar-brand" })

Then in the css, have this:

然后在css中,有这个:

.navbar-brand {
    background-image: url(img/accomodator-mini.png);
}

回答by user3051028

Open your MVC application folder, create a folder called 'images' next to all other folders (Model, View, Controller,...) put your logo.jpg inside the folder images. Then open View/Home/index.cshtml in your Visual Studio editor and place the following line of html code inside the top <div>:

打开您的 MVC 应用程序文件夹,在所有其他文件夹(模型、视图、控制器等)旁边创建一个名为“图像”的文件夹,将您的 logo.jpg 放入文件夹中images。然后在 Visual Studio 编辑器中打开 View/Home/index.cshtml 并将以下 html 代码行放在 top 中<div>

<div class="jumbotron">
    <img src="images/logo.jpg" alt="Games Logo" ALIGN="right" />
    <h1>Computer Games Library</h1>
    <p class="lead">Programmer: Marzieh Farahani</p>
</div>

回答by PiggyMacPigPig

Robin requested help with replacing the text " I want to place image in place of application name with title and alt tag." with an image.

Robin 请求帮助替换文本“我想用标题和 alt 标签将图像代替应用程序名称”。带有图像。