I'm making an element in javascript and appending it to a flex container. The container I'm appending it to has a button in it and a display none div. I want the element I'm making to be positioned at the top of the div I'm appending it to, and I styled the class it has with align-self: flex-start, but for some reason this is doing nothing. Align-self: flex-end doesn't work either or any of the other align-self's. Here is my code-
// //handler to show text from eventData array
document.addEventListener('click', (e)=> {
let noEvents = document.getElementsByClassName('no-Events')[0];
let eventsDescContainer = document.querySelector('.events');
if(e.target.classList.contains('day')){
[...eventData['events']].forEach((event)=>{
if(event['day']===e.target.innerHTML && event['month']===headerMonths.innerHTML && event['year']===headerYears.innerHTML){
//span element to put Event text into
let eventDesc = `${event['description']}`
const span = document.createElement('span');
let EventText = document.createTextNode(eventDesc);;
//clear previous events message
noEvents.style.display='none';
clearEventText();
//append to container
span.appendChild(EventText)
span.classList.add('event-desc', 'event-message');
eventsDescContainer.appendChild(span);
} else {
clearEventText();
noEvents.style.display='initial';
noEvents.innerHTML = `There are no events on ${headerMonths.innerHTML} ${e.target.innerHTML} ${headerYears.innerHTML}`;
}
});
}
});
<div class='events'>
//this span is hidden
<span class='no-Events event-message'>There are no events today</span> //this button has no styles on it, it is just plain html
<button class='show-event-form rotate'>Add new event</button>
//This is the span I want to go at the top of the container but it is positioned after the button
<span class='event-desc event-message'>text</span>
</div>
Here is the html for the container and the span I created. The button has no styles.
.events{
height: 100%;
display:flex;
flex-direction: column;
align-items: center; /*center children vertically*/
overflow-y: auto;
}
.events .event-message {
align-items: center;
width: 80%;
text-align: center;
margin: 20px auto;
padding: 10px 0;
background-image: linear-gradient(to right, #649173, #dbd5a4 );
border-radius: 3px;
box-shadow: 3px 6px 10px #393a39;
}
//this is not working
.event-desc {
align-self: flex-start;
}