I have a div with a span in it, which contains a button. When you click the button, jquery adds a new span to the div. The span should sit next to the first span, but as you can see the new span is behind the first. It is added properly in the source code but they aren't lining up properly. The span is also as small as possible instead of the same height, and 3 times longer than the first span. Why is the span not behaving as expected?
EDIT 1: Ok so making them position: absolute
means that they aren't in the flow anymore. So removing that fixes the positioning. But it doesn't solve the issue of why the spans are minimally thin, even though I specify the height. Source
EDIT 2: Height issue has been resolved by making both spans display: inline-block;
, but as show in the picture below all is not well. There is something pushing the second span down. Source
HTML:
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="index.js"></script>
</head>
<body>
<div class="container">
<span class="menu">
<button class="add_button">+</button>
<button class="minimize_button">m</button>
</span>
</div>
</body>
</html>
CSS:
/*----------------*/
/*----Main Page---*/
/*---------- -----*/
.container {
background-color:grey;
position:relative;
height:20%;
width: 100%;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box;
}
.menu {
background-color:lightblue;
position:absolute;
height:90%;
width: 60px;
margin: 1%;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box;
border-radius:5px;
}
button {
background-color:blue;
height: 50px;
width: 50px;
margin: 5px;
font-size: 20px;
color: white;
border: 0px;
border-radius:7px;
}
/*-----------------*/
/*Timeline Element*/
/*----------------*/
.timeline_element {
height:90%;
width: 360px;
background-color:red;
border: 2px black;
margin: 1% 0%;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box;
border-radius:5px;
}
.text_area {
height: 50%;
width: 50%;
}
JS:
$(function(){
$(".add_button").click(add_timeline_element);
function add_timeline_element() {
debugger;
var timeline_element = $('<span></span>').addClass('timeline_element')
$('<button>/', {
text: '-',
click: function() {(".timeline_element").remove();}
}
).appendTo(timeline_element);
var text_area = document.createElement("textarea").className ="text_area";
$(timeline_element).append(text_area);
$(".menu").after(timeline_element);
}
});