Css 在html代码中加载图像

Css 在html代码中加载图像,css,html,Css,Html,我找到了要修改的html代码,以便将图像加载到html代码中: <section class="bg-img well-top"> <div class="container"> <div class="row"> <div class="col-xs-12 col-sm-offset-2 col-sm-8"> <form class="search-form"

我找到了要修改的html代码,以便将图像加载到html代码中:

<section class="bg-img well-top">
    <div class="container">
        <div class="row">
            <div class="col-xs-12 col-sm-offset-2 col-sm-8">
                <form class="search-form" action="http://static.livedemo00.template-help.com/wt_57621/search.php" method="GET" accept-charset="utf-8">
                    <label class="search-form_label">
                        <input class="search-form_input" type="text" name="s" autocomplete="off" placeholder="Search Scripts"/>
                        <span class="search-form_liveout"></span>
                    </label>
                    <button class="search-form_submit fa-search" type="submit"></button>
                </form>
            </div>
        </div>
    </div>
</section>

我想将图像文件加载到html代码中。

请指定您的视图,以便我可以为此安排一个完美的解决方案, 好的,我们有两种方法:

使用css的背景图像 对于任何类、id或特定元素,您都可以通过如下背景图像进行操作:

.image-class, #image-id{
background:url(some_url);
height: it depends on container content otherwise write it here in px
}
另一个使用img标记和特定id或类的方法使用js,如:

document.getElementbyID("image-id").innerHTML="<img src="image-url">";
如果innerHTML给您带来问题,您可以使用jquery中的某些其他方法,如append等


如果您还有其他问题,请告诉我使用img src=filename.png width=900 height=1200 style=border radius:20px;此外,您还可以根据需要设置宽度、高度和样式。在此之前,将要加载的图像设置为png或jpg格式。要使图像居中,请使用命令

我的第一个问题是为什么?您是否只希望在HTML中加载图像代码,并计划保持CSS的其余部分不变,还是希望替换/删除所有CSS代码

如果你想替换所有的CSS代码,并且有一个纯HTML的解决方案,那么很难获得与你找到的代码相同的视觉效果,因为CSS中有很多样式

最简单的答案是使用style属性将背景图像移动到HTML文件中:

<section class="bg-img well-top" style="background-image: url(../images/bg-img.jpg);">
<div class="container">
    <div class="row">
        <div class="col-xs-12 col-sm-offset-2 col-sm-8">
            <form class="search-form" action="http://static.livedemo00.template-help.com/wt_57621/search.php" method="GET" accept-charset="utf-8">
                <label class="search-form_label">
                    <input class="search-form_input" type="text" name="s" autocomplete="off" placeholder="Search Scripts"/>
                    <span class="search-form_liveout"></span>
                </label>
                <button class="search-form_submit fa-search" type="submit"></button>
            </form>
        </div>
    </div>
</div>

有一个相对较新的css属性,可以做你想做的事。它有相当好的除了微软-

将图像放入html是相当容易的,只需绝对地在容器中放置一个img,.bg img,以占用相同的空间并应用对象匹配:cover。只要确保调整图像的z索引,使其不覆盖您的表单,就可以了。bg img在技术上不再是一个很好的类名,它有position:relative,以便您的图像使用它进行定位

img{ 显示:块; 位置:绝对位置; 排名:0; 身高:100%; 宽度:100%; 对象匹配:覆盖; z指数:-1; } .bg img{ 位置:相对位置; 填充顶部:90px; 填充底部:133px; 文本对齐:居中; 溢出:隐藏; } @介质最大宽度:767px{ .bg img{ 填充顶部:70px; 填充底部:80px; } } 你试过这个吗

<section class="bg-img well-top" style="background: no-repeat url(../images/bg-img.jpg); background-size: cover;">
(...)
使用,您可以将图像存储为html代码中的base64编码字符串。但URI会使图像大小增加约30%

背景中的Base64图像内容:url属性示例:

<section class="bg-img well-top" style="background: no-repeat url(data:image/jpeg;base64,/9j/4AAQSk....base64.img.content...//2Q==); background-size: cover;">
(...)

您可以使用画布和javascript将图像加载到html5中。示例显示我可以使用html标记吗?你的意思是…?我想获得相同的视觉效果,但要使用html代码加载图像。@CBroe是的,但如何获得相同的视觉效果?
<section class="bg-img well-top" style="background: no-repeat url(../images/bg-img.jpg); background-size: cover;">
(...)
<section class="bg-img well-top" style="background: no-repeat url(data:image/jpeg;base64,/9j/4AAQSk....base64.img.content...//2Q==); background-size: cover;">
(...)