首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >除图像外的按钮位置

除图像外的按钮位置
EN

Stack Overflow用户
提问于 2017-08-21 12:16:09
回答 4查看 61关注 0票数 1

我有一个图像和5个按钮,我想定位在的右上角边的图像,按钮应该是一个高于另一个。当前,按钮位于图像的右下角,并放置在一行中。

代码语言:javascript
复制
function pictureChange(imgId, path) {
  document.getElementById(imgId).src = path;
}
代码语言:javascript
复制
p {
  display: inline-block;
}
代码语言:javascript
复制
<img id="scene1" src="images/scene1/scene1-4dof.png">

<p>
  <input type="button" value="4DOF" onclick="pictureChange('scene1','images/scene1/scene1-4dof.png')">
</p>
<p>
  <input type="button" value="6DOF" onclick="pictureChange('scene1','images/scene1/scene1-6dof.png')">
</p>
<p>
  <input type="button" value="6DOF-PCA" onclick="pictureChange('scene1','images/scene1/scene1-6dof-pca.png')">
</p>
<p>
  <input type="button" value="7DOF" onclick="pictureChange('scene1','images/scene1/scene1-7dof.png')">
</p>
<p>
  <input type="button" value="7DOF-PCA" onclick="pictureChange('scene1','images/scene1/scene1-7dof-pca.png')">
</p>

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-08-21 12:29:29

代码语言:javascript
复制
function pictureChange(imgId,path) {
  document.getElementById(imgId).src=path;
}
代码语言:javascript
复制
.sid {
  display: inline-block;
  vertical-align: top;
}

img {
  width:200px;
  height:200px;
}

.sid input {
  display: block;
}
代码语言:javascript
复制
<img class="sid" id="scene1" src="http://via.placeholder.com/200x200">
<!---->
<div class="sid">
  <input type="button" value="4DOF" onclick="pictureChange('scene1','images/scene1/scene1-4dof.png')">
  <input type="button" value="6DOF" onclick="pictureChange('scene1','images/scene1/scene1-6dof.png')">
  <input type="button" value="6DOF-PCA" onclick="pictureChange('scene1','images/scene1/scene1-6dof-pca.png')">
  <input type="button" value="7DOF" onclick="pictureChange('scene1','images/scene1/scene1-7dof.png')">
  <input type="button" value="7DOF-PCA" onclick="pictureChange('scene1','images/scene1/scene1-7dof-pca.png')">
</div>

我所做的是将display: inline-block;添加到图像中,并添加div“以包含输入”。

<!---->表示inline行为在inline-block中“显示元素之间的任何间距”

也是右上半部分的vertical-align: top;

票数 4
EN

Stack Overflow用户

发布于 2017-08-21 13:05:26

这个解决方案将根据周围的元素进行缩放。为了显示这一点,我添加了一个额外的包装器。

代码语言:javascript
复制
.wrapper {
  position: relative; 
  /* width of the image here */
}
.wrapper .buttons {
  position: absolute;
  right: 3%;
  top: 3%;
}
#scene1 {
  width: 100%;
  height: auto;
}
代码语言:javascript
复制
<div class="wrapper">
  <img id="scene1" src="http://via.placeholder.com/350x150">
  <div class="buttons">
    <p><input type="button" value="4DOF" onclick="pictureChange('scene1','images/scene1/scene1-4dof.png')"></p>
    <p><input type="button" value="6DOF" onclick="pictureChange('scene1','images/scene1/scene1-6dof.png')"></p>
    <p><input type="button" value="6DOF-PCA" onclick="pictureChange('scene1','images/scene1/scene1-6dof-pca.png')"></p>
    <p><input type="button" value="7DOF" onclick="pictureChange('scene1','images/scene1/scene1-7dof.png')"></p>
    <p><input type="button" value="7DOF-PCA" onclick="pictureChange('scene1','images/scene1/scene1-7dof-pca.png')"></p>
  </div>
</div>

票数 1
EN

Stack Overflow用户

发布于 2017-08-21 12:45:41

纯Css :

1)图像上的按钮:

代码语言:javascript
复制
div {
    position: relative;
    display: inline-block;
}

img {
    width:300px;
    border:1px solid #000;
}

.right {
    position: absolute;
    top: 0;
    right: 0;
    background-color: rgba(0,0,0,0.7);
    text-align: center;
}
代码语言:javascript
复制
<div>
<img id="scene1" src="http://justcuteanimals.com/wp-content/uploads/2016/10/baby-bear-pictures-cute-animal-pics.jpg">
<div class="right">
<p><input type="button" value="4DOF" onclick="pictureChange('scene1','images/scene1/scene1-4dof.png')"></p>
<p><input type="button" value="6DOF" onclick="pictureChange('scene1','images/scene1/scene1-6dof.png')"></p>
<p><input type="button" value="6DOF-PCA" onclick="pictureChange('scene1','images/scene1/scene1-6dof-pca.png')"></p>
<p><input type="button" value="7DOF" onclick="pictureChange('scene1','images/scene1/scene1-7dof.png')"></p>
<p><input type="button" value="7DOF-PCA" onclick="pictureChange('scene1','images/scene1/scene1-7dof-pca.png')"></p>
</div>
</div>

2)图片后的按钮:

代码语言:javascript
复制
div {
    position: relative;
    display: inline-block;
}

img {
    width:200px;
    border:1px solid #000;
}

.right {
    background-color: rgba(0,0,0,0.7);
    text-align: center;
    vertical-align: top;

}
代码语言:javascript
复制
<div>
<img id="scene1" src="http://justcuteanimals.com/wp-content/uploads/2016/10/baby-bear-pictures-cute-animal-pics.jpg">
<div class="right">
<p><input type="button" value="4DOF" onclick="pictureChange('scene1','images/scene1/scene1-4dof.png')"></p>
<p><input type="button" value="6DOF" onclick="pictureChange('scene1','images/scene1/scene1-6dof.png')"></p>
<p><input type="button" value="6DOF-PCA" onclick="pictureChange('scene1','images/scene1/scene1-6dof-pca.png')"></p>
<p><input type="button" value="7DOF" onclick="pictureChange('scene1','images/scene1/scene1-7dof.png')"></p>
<p><input type="button" value="7DOF-PCA" onclick="pictureChange('scene1','images/scene1/scene1-7dof-pca.png')"></p>
</div>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45796925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档