我的代码工作正常,但在输出我的图像之后,我希望它们相互重叠一点,可能是使用边距,填充或任何其他脚本,并且是否有可能添加z-index这些因为这些图像应该相互重叠。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Petroleum Project</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/shop-item.css" rel="stylesheet">
<link href="css/home.css" rel="stylesheet">
</head>
<body>
<div id="main">
<nav id="nav01"></nav>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="home.html">Home</a>
<!--<a class="navbar-brand" href="index.html"><img src="images/main-icon.jpg" style="width:80px;"/></a>-->
<a class="navbar-brand" href="index.html">Layers_Lib</a>
<a class="navbar-brand" href="well_formation.html">Well Formation</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-md-4" >
<div class="thumbnail" style='padding-left:20px;' >
<div class="caption-full" >
<center><h2><strong>Well Formation Inputs</strong></h2></center>
</div>
<h4><b>Enter Height of the well:</b><input type="text" id="well_height"></h4>
<h4><b>Select Layers:</b>
<select multiple="true" id="layers_box">
<option value="conglomerate">Conglomerate</option>
<option value="gravel">Gravel</option>
<option value="sandstone">Sandstone</option>
<option value="siltstone">Siltstone</option>
<option value="shale">Shale</option>
<option value="clay">Clay</option>
<option value="limeStone">LimeStone</option>
<option value="dolomite">Dolomite</option>
</select>
</h4>
(press and hold CTRL to select multiple layers)
</br></br>
<button id="layer_submit"class="btn-info btn" ><b>Submit</b></button>
<button id="layer_clear"class="btn-info btn" onClick='$("#layers_box option:selected").removeAttr("selected");$("#well_height").val("");' ><b>Clear</b></button>
</div>
</div>
<div class="col-md-5" id="" style="display:block">
<h3> Layers </h3>
<div id="layer_structure" style="width:402px;border:1px solid #000;margin-left:200px;">
</div>
</div>
</div>
</div>
</div>
<!-- /.container -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<script>
function img_create(src, alt, height) {
var img= document.createElement('img');
img.src= src;
if (alt!=null) img.alt= alt;
img.style.width = '400px';
img.style.height = height+'px';
$("#layer_structure").append(img);
}
jQuery(document).ready(function(){
$("#layer_submit").click(function() {
height_of_well = $("#well_height").val();
hw = parseInt(height_of_well);
if(height_of_well == ""){
alert("Please Enter Height of Well");
return false;
}
console.log(height_of_well);
layers = $("#layers_box").val();
layer_heights = [];
$("#layer_structure").html("");
$("#layer_structure").css("height",height_of_well+"px");
for(i = 0; i< layers.length; i++){
layer_heights[i] = prompt("Please Enter height of" +layers[i],"");
hw = hw - parseInt(layer_heights[i]);
if(hw < 0){
alert("Well height is less than layers height");
return false;
}
img_create("images/well_formation/"+layers[i]+".png",layers[i],layer_heights[i]);
}
});
});
</script>
<style>
.list-group{
background-color:#337ab7;
}
</style>
</div>
</body>
</html>
答案 0 :(得分:1)
CSS中的重叠可以像这样完成。顶部图片的z-index
应大于下图。而且,这些元素必须设置position
。
.frame{
position:relative;
}
.frame img{
width: 100%;
position:absolute;
}
.frame img#gabe{
z-index: 10;
top: 50px;
left: 50px;
opacity: 0.5;
}
.frame img#hl3{
z-index: 9;
}
&#13;
<div class="frame">
<img id="gabe" src="http://www.indiavision.com/news/images/articles/2013_01/386025/u8_Gabe-Newell.jpg">
<img id="hl3" src="http://masterherald.com/wp-content/uploads/2014/12/Half-Life-3.jpg">
</div>
&#13;