以 HTML 格式显示文本文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25535125/
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 02:34:50  来源:igfitidea点击:

Display text file in HTML

htmlcsstext

提问by kilian

I'm trying to display the content of a text file in html without using ajax, javascript ecc. but possibly css and html. I have a slideshow of images and depending on the image you select, the content of the text file should appear under the photo. I know how to associate the text file with the photo and it should work, but how can I can display the content of the txt file in the web page? Thanks :-)

我试图在不使用 ajax、javascript ecc 的情况下以 html 显示文本文件的内容。但可能是 css 和 html。我有一个图像幻灯片,根据您选择的图像,文本文件的内容应显示在照片下方。我知道如何将文本文件与照片相关联,它应该可以工作,但是如何在网页中显示 txt 文件的内容?谢谢 :-)

回答by Jacob Gray

You can just use an <iframe>:

你可以只使用一个<iframe>

<iframe src="http://stackoverflow.com/reputation"></iframe>

Edit:Stack Overflow no longer allows <iframe>'s to a different domain, so I switched to using //stackoverflow.com/reputationsfor the demos

编辑:Stack Overflow 不再允许<iframe>'s 到不同的域,所以我改用//stackoverflow.com/reputations用于演示

This is probably more what you are looking for(Image with text below it):

这可能更符合您的要求(图片下方有文字):

iframe{
    border:none;
    width:400px;
    display:block;
}
<img src="http://lorempixel.com/400/400">
<iframe src="http://stackoverflow.com/reputation"></iframe>