GVKun编程网logo

html – 显示替代图像(html图片替代文字)

10

在本文中,我们将带你了解html–显示替代图像在这篇文章中,我们将为您详细介绍html–显示替代图像的方方面面,并解答html图片替代文字常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的c#

在本文中,我们将带你了解html – 显示替代图像在这篇文章中,我们将为您详细介绍html – 显示替代图像的方方面面,并解答html图片替代文字常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的c# – 使用WKHTMLTOPDF以HTML格式显示图像,但不以PDF格式显示、html – SVG中的图像图像标签未显示在Chrome中,但在本地显示?、html – 使用css显示为带圆圈的图像的图像、html – 使用css显示图像裁剪图像的顶部和底部

本文目录一览:

html – 显示替代图像(html图片替代文字)

html – 显示替代图像(html图片替代文字)

如果找不到原始源文件,是否可以显示备用图像?
我想用css和html,没有 javascript(或jQuery和类似的)来实现这一点.
我们的想法是仍然显示图像,而不是IE的“alt”测试或默认(丑陋)交叉.
如果没有javascript就不可能,那么我会用PHP和一个基本的if-then-else检查img src.

解决方法

你可以使用img元素的CSS background-image属性来做到这一点,即
img
{
background-image:url('default.png');
}

但是,您必须为此工作提供宽度或高度(当找不到img-src时):

img
{
background-image:url('default.png');
width:400px;
}

c# – 使用WKHTMLTOPDF以HTML格式显示图像,但不以PDF格式显示

c# – 使用WKHTMLTOPDF以HTML格式显示图像,但不以PDF格式显示

您正在使用Wkhtmltopdf使用c#,Asp.net从Html页面创建PDF.
PDF创建顺利,但是当我将图像添加到HTML时,它不会显示在PDF上.
public static string HtmlToPdf(string pdfOutputLocation,string outputFilenamePrefix,string[] urls,string[] options = null,// string pdfHtmlToPdfExePath = "C:\\Program Files (x86)\\wkhtmltopdf\\wkhtmltopdf.exe")

       string pdfHtmlToPdfExePath = "C:\\Program Files\\wkhtmltopdf\\wkhtmltopdf.exe")
    {
        string urlsSeparatedBySpaces = string.Empty;
        try
        {
            //Determine inputs
            if ((urls == null) || (urls.Length == 0))
                throw new Exception("No input URLs provided for HtmlToPdf");
            else
                urlsSeparatedBySpaces = String.Join(" ",urls); //Concatenate URLs

            string outputFolder = pdfOutputLocation;
            string outputFilename = outputFilenamePrefix + "_" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss-fff") + ".PDF"; // assemble destination PDF file name

            var p = new System.Diagnostics.Process()
            {
                StartInfo =
                {
                    FileName = pdfHtmlToPdfExePath,Arguments = ((options == null) ? "" : String.Join(" ",options)) + " " + urlsSeparatedBySpaces + " " + outputFilename,UseShellExecute = false,// needs to be false in order to redirect output
                    RedirectStandardOutput = true,RedirectStandardError = true,RedirectStandardInput = true,// redirect all 3,as it should be all 3 or none
                    WorkingDirectory = HttpContext.Current.Server.MapPath(outputFolder),CreateNowindow = true
                }
            };

            p.Start();

            // read the output here...
            var output = p.StandardOutput.ReadToEnd();
            var errorOutput = p.StandardError.ReadToEnd();

            // ...then wait n milliseconds for exit (as after exit,it can't read the output)
            p.WaitForExit(60000);

            // read the exit code,close process
            int returnCode = p.ExitCode;
            p.Close();

            // if 0 or 2,it worked so return path of pdf
            if ((returnCode == 0) || (returnCode == 2))
                return outputFolder + outputFilename;
            else
                throw new Exception(errorOutput);
        }
        catch (Exception exc)
        {
            throw new Exception("Problem generating PDF from HTML,URLs: " + urlsSeparatedBySpaces + ",outputFilename: " + outputFilenamePrefix,exc);
        }
    }

这是我显示图片的HTML代码区域..

<div id="Image">

  <img id="logoImage" runat="server" width="100%" height="100%" src="../Templogo/chafa.jpg" />

解决方法

尝试为图像src添加完整路径.这通常是由于“../Templogo/chafa.jpg”实际上并不是wkhtmltopdf工作目录的正确相对URL.

所以,而不是“../Templogo/chafa.jpg”尝试“C:/yourpath/Templogo/chafa.jpg”或“file:/// C:/yourpath/Templogo/chafa.jpg”,看看是否有帮助.如果是这样,你的相对路径就是问题所在.

html – SVG中的图像图像标签未显示在Chrome中,但在本地显示?

html – SVG中的图像图像标签未显示在Chrome中,但在本地显示?

出于某种原因,Chrome正在显示SVG而图像标签中没有图像.

以下是我的SVG示例:

<image xlink:href="blocker.png" height="312.666661" width="85.693825" y="16.479997" x="459.946664"/>

blocker.png是一个本地文件,但我也尝试将其上传到imgur,但这也无效.

这是svg标签:

<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

这是本地的样子:

http://i.imgur.com/BDP8KpG.png

这是在实际网页上的样子:

http://i.imgur.com/KVuxLI1.png

如你所见,这两名球员失踪了.当我在线上传SVG时不会发生这种情况,但是当我尝试将该URL链接到我的页面时,会发生同样的事情

不确定它是否相关,但这里是页面的HTML代码:

<!DOCTYPE HTML>
<html>
<head>
<title>SVG</title> 
<style>
img{
    width: 100%;
    height:auto;
    max-width: 800px;
}
</style>
</head>

<body>

<div>
    <img src="svg.svg"/>
</div>

</body>
</html>

解决方法

PaulLeBeau的回答是对的.但另一种解决方案是使用embed标签而不是图片的img标签.
<embed src="svg.svg">

Here是在HTML中嵌入svg图像的一些方法.

html – 使用css显示为带圆圈的图像的图像

html – 使用css显示为带圆圈的图像的图像

这是我的代码 – 这适用于chrome,firefox和safari ..我在 Windows 7上测试过它
但是在IE 8和Opera浏览器中,以下代码无效,而不是显示带圆圈的图像,而是以方形形式获取图像
<div id="hotspot-img1-0">
  <ul>
    <imgsrc="http://profile.ak.fbcdn.net/hprofile-ak-snc4/276311_100002617687873_1118195351_n.jpg" title="web">
  </ul>
</div>

CSS

#hotspot-img1-0{
top: 570px; 
left: 67px; 
height: 104px; 
width: 104px; 
border-top-left-radius: 52px; 
border-top-right-radius: 52px; 
border-bottom-right-radius: 52px; 
border-bottom-left-radius: 52px; 
Box-shadow: 0px 2px 5px 0px; 
border-top-color: rgb(255,255,255); 
border-left-color: rgb(255,255); 
border-right-color: rgb(255,255); 
border-bottom-color: rgb(255,255); 
border-top-width: 2px; 
border-left-width: 2px; 
border-right-width: 2px; 
border-bottom-width: 2px; 
border-top-style: solid; 
border-left-style: solid; 
border-right-style: solid; 
border-bottom-style: solid
}

解决方法

@Sandhurst;坏标记写的第一件事就像这样:
<div>
  <ul>
    <li>
       <imgsrc="http://profile.ak.fbcdn.net/hprofile-ak-snc4/276311_100002617687873_1118195351_n.jpg" title="web">
    </li>
  </ul>
</div>

&安培;回答问题使用background-image而不是img:

li{
 background:url(image.jpg) no-repeat;
 -moz-border-radius:52px;
 -webkit-border-radius:52px;
 border-radius:52px;
width:200px;
height:200px;
}

html – 使用css显示图像裁剪图像的顶部和底部

html – 使用css显示图像裁剪图像的顶部和底部

我试图从youtube显示图像显示内容大小的视频

height:180px
width :270px

从youtube图像的顶部和底部都有一些黑色的图片

例如:

enter image description here

我想要显示这样的图像

enter image description here

在互联网上搜索答案

发现这些链接是有帮助的,但没有解决方案我想如何显示图像

How to automatically crop and center an image

这个最有帮助,但我不能使用background-image标签.我希望它在标签中

CSS Display an Image Resized and Cropped

任何人帮我解决这个问题.谢谢

解决方法

更新

我已经更新了答案,但我不确定你想要什么,你只是说了你不想要的.所以我假设你想要:

>保持纵横比
>避免种植
>没有黑条,只是图像边缘到边缘

我们知道这是一张纵横比为16:9的宽屏海报,所以如果您想要宽度为270像素,请执行以下操作:

将宽度除以16

270/16 = 16.875

取该商并乘以9

16.875 * 9 = 151.875

向上或向下舍入

Round up to 152px

使用结果更改高度,然后应用object-fit:cover

152px is the height of an image that's 270px wide and has an aspect ratio of 16:9.

请查看Fiddle和更新的代码段

编辑

为了反映更新并更好地理解OP的目标,编辑了此代码段.

object-fit是一个简单的CSS属性.请参阅此article下面的代码段已注释.顺便说一句,这个代码片段中你需要的唯一代码就是对象:cover,其余的样式和标记仅用于演示.

片段

/* We kNow this is a widescreen poster with the aspect ratio of 16:9,so if you want a width of 270px,do the following:

    270/16 = 16.875
    16.875 * 9 = 151.875
    Round up to 152px
    
152px is the height of an image that's 270px wide and has an aspect ratio of 16:9 */
.bg1 {
  width: 270px;
  height: 152px;
  object-fit: cover;
  outline: 2px dashed blue;
}
.bg2 {
  width: 270px;
  height: 152px;
  object-fit: contain;
  outline: 2px dashed blue;
}
.bg3 {
  width: 270px;
  height: 152px;
  outline: 2px dashed blue;
}
aside {
  height: 100%;
  width: 40%;
  display: inline-block;
  position: absolute;
  right: 0;
  top: 0;
}
figure {
  height: 180px;
  width: 270px;
  max-width: 50%;
}
.pointer {
  position: absolute;
}
.pointer b {
  font-size: 32px;
}
#a.pointer {
  top: 43%;
  left: 52%;
}
#b.pointer {
  bottom: 5%;
  left: 52%;
}
.Box {
  width: 600px;
  height: 450px;
  position: relative;
}
.spacer {
  position: relative;
  padding: .1% 0;
  width: 2px;
}
code {
  font-family: Consolas;
  color: red;
}
<sectionhttps://www.jb51.cc/tag/Box/" target="_blank">Box">
  <figure>
    <figcaption>object-fit: cover</figcaption>
    <imgsrc="http://img.youtube.com/vi/MzMqjG9om18/hqdefault.jpg" />
  </figure>
  <!--<divid="a"><b>⬅</b>
    <br/>Space</div>-->
  <figure>
    <figcaption>object-fit: contain</figcaption>
    <imgsrc="http://img.youtube.com/vi/MzMqjG9om18/hqdefault.jpg" />
  </figure>


  <figure>
    <figcaption>Without anything but the height property</figcaption>
    <imgsrc="http://img.youtube.com/vi/MzMqjG9om18/hqdefault.jpg" />
  </figure>

  <aside>
    <p><code>object-fit: cover</code> will stretch an image to the edges of it's container (parent element) while keeping aspect ratio and cropping.</p>
    <p>But when given the correct dimensions,<code>object-fit: cover</code> will result in a perfect fit edge to edge. No cropping either.</p>
    <div>&nbsp;</div>
    <p><code>object-fit: contain</code> will stretch an image to the edges of it's container while keeping aspect ratio but will not crop at the edges,so as you can see,this image has space left and right. At wider dimentions,the space will manifest below and above.</p>
  
    <div>&nbsp;</div>
    <p>This is the image when set to it's aspect ratio at 270 x 152px and as you can see,without <code>object-fit:cover</code>,math alone will not resolve the problem.</p>
  </aside>
  <!--<divid="b"><b>⬅</b>
    <br/>Space</div>-->
</section>

今天关于html – 显示替代图像html图片替代文字的讲解已经结束,谢谢您的阅读,如果想了解更多关于c# – 使用WKHTMLTOPDF以HTML格式显示图像,但不以PDF格式显示、html – SVG中的图像图像标签未显示在Chrome中,但在本地显示?、html – 使用css显示为带圆圈的图像的图像、html – 使用css显示图像裁剪图像的顶部和底部的相关知识,请在本站搜索。

本文标签: