Javascript 网页-图像上的文本-与显示分辨率无关的相对位置
我喜欢在图像的特定位置显示文本。我现在正在使用像素,我体验了基于显示屏分辨率的文本位置移动 有没有办法使位置相对于显示分辨率?要使用哪种类型的图像 我尝试了相对和绝对,文本的移动是基于我的笔记本电脑和桌面的显示分辨率的,它有高清显示 我试过的例子Javascript 网页-图像上的文本-与显示分辨率无关的相对位置,javascript,html,image,css,Javascript,Html,Image,Css,我喜欢在图像的特定位置显示文本。我现在正在使用像素,我体验了基于显示屏分辨率的文本位置移动 有没有办法使位置相对于显示分辨率?要使用哪种类型的图像 我尝试了相对和绝对,文本的移动是基于我的笔记本电脑和桌面的显示分辨率的,它有高清显示 我试过的例子 <!DOCTYPE HTML> <html> <head> <style> body { margin: 0px; padding: 0px;
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
img {
width: 100%;
height: auto;
}
#rcorners2 {
border-radius: 25px;
border-width: 2px;
border-style: solid;
padding: 20px;
width: 500px;
height: 350px;
text-align: center;
}
.w3-theme-border {
border-color: #4CAF50 !important;
border-top-color: #4CAF50;
border-right-color: #4CAF50;
border-bottom-color: #4CAF50;
border-left-color: #4CAF50;
}
.test1 {
position: absolute;
top: 135px;
left: 220px;
width: 120px;
padding: 4px;
font-size: 18px;
color: red;
border: 1px solid green;
}
</style>
</head>
<body>
<div id="rcorners2" class="w3-theme-border">
<div style="position: relative; width: 100px; height: 100px;">
<img src = "Test.gif" alt = "image" style="width: 430px; height: 350px;">
<div class="test1"><b> 12 V : testing </b></div>
</div>
</div>
</div>
</body>
</html>
身体{
边际:0px;
填充:0px;
}
img{
宽度:100%;
高度:自动;
}
#rcorners2{
边界半径:25px;
边框宽度:2倍;
边框样式:实心;
填充:20px;
宽度:500px;
高度:350px;
文本对齐:居中;
}
.w3主题边框{
边框颜色:#4CAF50!重要;
边框顶部颜色:#4CAF50;
右边框颜色:#4CAF50;
边框底色:#4CAF50;
左边框颜色:#4CAF50;
}
.test1{
位置:绝对位置;
顶部:135px;
左:220px;
宽度:120px;
填充:4px;
字号:18px;
颜色:红色;
边框:1px纯绿色;
}
12 V:测试
输出
假设图像尺寸不变,您应该能够将图像放置在
位置:相对div,然后在同一div中放置一些绝对文本。但是,如果没有示例代码,很难知道您正试图做什么。听起来很简单,但是我可以很快猜出你的年龄和体重,而不是在没有实际问题示例的情况下解决这个问题。对不起,我添加了示例程序