I designed three boxes in this section with content inside. To enhance the functionality, I added a feature that made the boxes smaller. Everything was functioning perfectly, but I encountered an issue with the alignment of the buttons at the bottom. Is there anyone who could help me align those buttons properly within the div?
;(function (win, doc, undef) {
'use strict';
/**
* @desc this object holds all functions
*/
var RM = {};
/* ============================== */
/* HELPERS */
/* ============================== */
RM.helpers = {
extendObj: function() {
for (var i = 1, l = arguments.length; i < l; i++) {
for (var key in arguments[i]) {
if (arguments[i].hasOwnProperty(key)) {
if (arguments[i][key] && arguments[i][key].constructor && arguments[i][key].constructor === Object) {
arguments[0][key] = arguments[0][key] || {};
this.extendObj(arguments[0][key], arguments[i][key]);
} else {
arguments[0][key] = arguments[i][key];
}
}
}
}
return arguments[0];
}
};
/* ============================== */
/* MAIN FUNCTIONS */
/* ============================== */
// Return the number of words of string.
RM.countWords = function (str) {
return str.split(/\s+/).length;
};
// Rturn string starting from first word untill number specified.
RM.generateTrimmed = function (str, wordsNum) {
return str.split(/\s+/).slice(0, wordsNum).join(' ') + '...';
};
// Plugin Initialization
RM.init = function (options) {
var defaults = {
target: '',
numOfWords: 50,
toggle: true,
moreLink: 'Read more...',
lessLink: 'Read less',
linkClass: 'rm-link',
containerClass: false
};
options = RM.helpers.extendObj({}, defaults, options);
var target = doc.querySelectorAll(options.target), // Get the node list of target elements specified by the user.
targetLen = target.length, // Length of the targets node list.
targetContent, // The initial text that is contained in the target element.
trimmedTargetContent, // The final (trimmed) text.
targetContentWords, // The number of words the initial text has.
initArr = [], // Array to hold the initial text of each target element.
trimmedArr = [], // Array to hold the final (trimmed) text of each target element.
i, j, l, moreContainer, rmLink, moreLinkID, index;
// Loop through all target elements
for (i = 0; i < targetLen; i++) {
targetContent = target[i].innerHTML; // Get the initial text of each target element.
trimmedTargetContent = RM.generateTrimmed(targetContent, options.numOfWords); // Generate the trimmed version of the initial text.
targetContentWords = RM.countWords(targetContent); // Count the number of words the initial text has.
initArr.push(targetContent); // Push the initial text to initArr.
trimmedArr.push(trimmedTargetContent); // Push the trimmed text to trimmedArr.
// Proceed only if the number of words specified by the user
// is smaller than the number of words the target element has.
if (options.numOfWords < targetContentWords - 1) {
target[i].innerHTML = trimmedArr[i]; // Populate the target element with the trimmed version of text.
moreContainer = doc.createElement('div'); // Create a div element to hold the More/Less link.
if(options.containerClass) {
moreContainer.className = options.containerClass;
}
moreContainer.innerHTML = '<a id="rm-more_'+ i + '"' // Create the More/Less link.
+ ' class="'+ options.linkClass +'"'
+ ' style="cursor:pointer;padding:10px;background-color:#86BC25;margin-left:10px;color:#fff;text-decoration:none;fonr-weight:bold;border-radius:5px;" data-readmore="anchor">'
+ options.moreLink
+ '</a>';
target[i].parentNode.insertBefore(moreContainer, target[i].nextSibling); // Insert the More/Less link after the target element.
}
}
rmLink = doc.querySelectorAll('[data-readmore="anchor"]'); // Reference the More/Less link.
// Loop through all links and attach event listeners.
for (j = 0, l = rmLink.length; j < l; j++) {
rmLink[j].onclick = function () {
moreLinkID = this.getAttribute('id'); // Get each link's unique identifier.
index = moreLinkID.split('_')[1]; // Extract index number from each link's 'id'.
// if (!helpers.classList.contains(this, 'less')) {
if (this.getAttribute('data-clicked') !== 'true') {
target[index].innerHTML = initArr[index];
if (options.toggle !== false) {
this.innerHTML = options.lessLink;
this.setAttribute('data-clicked', true);
} else {
this.innerHTML = '';
}
} else {
target[index].innerHTML = trimmedArr[index];
this.innerHTML = options.moreLink;
this.setAttribute('data-clicked', false);
}
};
}
};
// Return as global object
window.$readMoreJS = RM;
}(this, this.document));
$readMoreJS.init({
target: '.show_more',
numOfWords: 50,
toggle: true,
moreLink: 'Show more content',
lessLink: 'Show less content'
});
.col-container {
display: flex;
width: 100%;
}
.col {
flex: 1;
padding: 10px;
margin: 10px;border:2px solid green;
}
div.text-container {
margin: 0 auto;
width: 75%;
}
.hideContent {
overflow: hidden;
line-height: 1em;
height: 2em;
}
.showContent {
line-height: 1em;
height: auto;
}
.showContent{
height: auto;
}
h1 {
font-size: 24px;
}
p {
padding: 10px 0;
}
.show-more {
padding: 10px 0;
text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" ></script>
<div class="col-container">
<div class="col">
<h2>Column 1</h2>
<p class="show_more">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Conten </p>
</div>
<div class="col">
<h2>Column 2</h2>
<p class="show_more">when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including</p>
</div>
<div class="col">
<h2>Column 3</h2>
<p class="show_more">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
</div>
</div>
Hello there, I designed three boxes in this area with unique content. To add more functionality, I reduced the size of these boxes. Although the overall setup was working well, I encountered a slight misalignment issue with the buttons located at the bottom. Would appreciate any assistance in fixing the button alignment within the div.