The Solution:
To achieve the desired layout, make sure to apply the following properties within your .parent-canvas
class:
.parent-canvas {
display: inline-block; /* Set to inline but retain block-level characteristics */
overflow: hidden; /* Conceal text overflow within the container */
position: relative; /* Use absolute positioning to remove text from normal flow and contain it */
}
You have two options after this step - you can either utilize word-break
, or max-width
in your .text-canvas
class:
.text-canvas {
word-break: break-all;
}
A Code Snippet Example:
function submit_button() {
// Image upload function
}
$(".text-canvas").draggable({
containment: ".imageupload",
create: function() {
$("#text-canvas ").css("width", 'auto');
},
drag: function() {
$("#text-canvas ").css("width", 'auto');
},
start: function() {
$("#text-canvas ").css("width", 'auto');
},
stop: function() {
$("#text-canvas ").css("width", 'auto');
}
});
$("#fontsize").on("change", function() {
var v = $(this).val();
$('.text-canvas').css('font-size', v + 'px');
});
.text-canvas {
z-index: 1;
position: absolute;
}
.imageupload {
z-index: -1;
}
.parent-canvas {
display: inline-block;
overflow: hidden;
position: relative;
}
.text-canvas {
word-break: break-all;
}
.image-canvas img {
vertical-align: middle;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div class="col-sm-4">
<div name="anotherdiv">
<input type="range" min="12" max="54" id="fontsize">
</div>
</div>
<div class="col-sm-8">
<div class="parent-canvas">
<div class="text-canvas" id="text-canvas" contenteditable="true">
Sample Text Here
</div>
<div class="image-canvas">
<div class="imageupload" onclick="submit_button()">
<img src="http://placehold.it/100x100">
</div>
</div>
</div>
</div>
Alternatively, you may combine both approaches without any conflicts:
.text-canvas {
word-break: break-all;
max-width: 100%;
}
Code Snippet Display:
You also have the option to use both methods together, as they complement each other well:
.text-canvas {
word-break: break-all;
max-width: 100%;
}
Additional Test Details:
System Tests Performed on:
- Chrome Version 54.0.2840.71 (64-bit)
- FireFox Version 49.0.2
- Microsoft Edge Version 25.10586.0.0
iOS Device Testing Conducted On:
- Iphone 6 Safari Mobile Browser
Potential User Experience Enhancement:
In terms of user experience improvement, consider adding the cursor: grab;
and cursor: grabbing;
properties to indicate draggable elements for Chrome and Firefox users. This small addition can enhance interaction with the interface.
Suggested CSS Properties for jQuery Draggable Classes:
.ui-draggable {
cursor: -webkit-grab;
cursor: grab;
}
.ui-draggable-dragging {
cursor: -webkit-grabbing;
cursor: grabbing;
}
Final Code Snippet Including UX Adjustment:
function submit_button() {
// Image upload function
}
$(".text-canvas").draggable({
containment: ".imageupload",
create: function() {
$("#text-canvas ").css("width ", 'auto');
},
drag: function() {
$("#text-canvas ").css("width ", 'auto');
},
start: function() {
$("#text-canvas ").css("width ", 'auto');
},
stop: function() {
$("#text-canvas ").css("width ", 'auto');
}
});
$("#fontsize").on("change", function() {
var v = $(this).val();
$('.text-canvas').css('font-size', v + 'px');
});
.text-canvas {
z-index: 1;
position: absolute;
}
.imageupload {
z-index: -1;
}
.parent-canvas {
display: inline-block;
overflow: hidden;
position: relative;
}
.text-canvas {
word-break: break-all;
max-width: 100%;
}
.image-canvas img {
vertical-align: middle;
}
.ui-draggable {
cursor: -webkit-grab;
cursor: grab;
}
.ui-draggable-dragging {
cursor: -webkit-grabbing;
cursor: grabbing;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div class="col-sm-4">
<div name="anotherdiv">
<input type="range" min="12" max="54" id="fontsize">
</div>
</div>
<div class="col-sm-8">
<div class="parent-canvas">
<div class="text-canvas" id="text-canvas" contenteditable="true">
my text
</div>
<div class="image-canvas">
<div class="imageupload" onclick="submit_button()">
<img src="http://placehold.it/100x100">
</div>
</div>
</div>
</div>