Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Materialize css - change position of toast dialog

I am using Materialize css (www.materializecss.com). Want to change position of toast dialog. In smaller screens it is on proper position. For wide screen and box layout it goes to right corner out of my layout. (http://materializecss.com/dialogs.html)

When toast get triggered, it appends "<div id="toast-container"></div>" in body. I don't want to append it in body. I want it in specific div.

like image 247
Manish Rane Avatar asked Nov 06 '15 11:11

Manish Rane


People also ask

How do you materialize toast?

Materialize provides an easy way for you to send unobtrusive alerts to your users through toasts. These toasts are also placed and sized responsively, try it out by clicking the button below on different device sizes. Toast! To do this, call the M.

How do I show a toast message in HTML?

To show a toast with a click of a button, you must initialize it with JavaScript: select the specified element and call the toast() method.

What is the use of materialize CSS?

Materialize is a UI component library created with CSS, JavaScript, and HTML. Materialize UI components help in constructing attractive, consistent, and functional web pages and web apps, while adhering to modern web design principles such as browser portability, device independence, and graceful degradation.


2 Answers

The position of the toast dialog can be changed by setting the dafault values of #toast-container to auto with !important.

For example, if you want the opposite position of the default on a desktop screen, change it to:

#toast-container {
  top: auto !important;
  right: auto !important;
  bottom: 10%;
  left:7%;  
}
  • Using !important is is necessary otherwise materialize.css will override it
  • Using position:absolute; or position:fixed; is not necessary

Demo of version 0.97.6

Materialize.toast('I am a toast!', 4000);
#toast-container {
  top: auto !important;
  right: auto !important;
  bottom: 10%;
  left:7%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css" rel="stylesheet"/>
like image 169
NiZa Avatar answered Oct 08 '22 01:10

NiZa


To set toast position at center of the document, you can add this style:

#toast-container {
    min-width: 10%;
    top: 50%;
    right: 50%;
    transform: translateX(50%) translateY(50%);
}
like image 3
Alexander Goncharov Avatar answered Oct 08 '22 00:10

Alexander Goncharov