I have a snackbar message pop up when there is a successful patch or post in my application. These messages can be short or long sometimes based on the context of the object being updated.
This originally was set to left: 50%
however I changed it because sometimes the message way not centered correctly. How can I make this snackbar always centered no matter how long the text is?
#snackbar {
visibility: hidden;
min-width: 250px;
margin-left: -125px;
background-color: $apple;
color: #fff;
text-align: center;
border-radius: 5px;
padding: 16px;
position: fixed;
z-index: 1;
left: 40%;
bottom: 30px;
}
HTML is as follows
<body>
<%= render "shared/sidenav" if current_user %>
<div id=<%= "#{'main' if current_user}" %>>
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, class: "alert alert-#{name}", id: 'alert' %>
<% end %>
<%= yield %>
<div id="snackbar"></div>
</div>
</body>
Snackbar is visible upon an HTTP request.