Search code examples
djangohtmldjango-formsmaterialize

Checkbox not rendering when materialize css is used in html page


Checkbox not rendering in the html page when materialize css is used. I am trying to use materialize css for my Django form. I tried in the Django form and it didn't work. So, I tried a separate sample html page. Still checkbox doesn't render. I have attached of screenshot of the rendered html page. "Married" checkbox can be seen without a checkbox. I tried using inspector tool on the page and seems like a checkbox is there but it is not visible.

enter image description here

Below is the sample html code I tried using to test the functionality.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
  <script>
  $( function() {
      $('.collapsible').collapsible();
    $( "#datepicker" ).datepicker();
  } );
  </script>
</head>
<body>

<p>Date: <input type="text" id="datepicker"></p>

<div class="container">
  <h2>Collapsible Panel</h2>
  <p>Click on the collapsible panel to open and close it.</p>
  <div class="panel-group">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 class="panel-title">
          <a data-toggle="collapse" href="#collapse1">Collapsible panel</a>
        </h4>
      </div>
      <div id="collapse1" class="panel-collapse collapse">
        <div class="panel-body">Panel Body</div>
        <div class="panel-footer">Panel Footer</div>
      </div>
    </div>
  </div>

  <ul class="collapsible">
    <li>
      <div class="collapsible-header"><i class="material-icons">filter_drama</i>First</div>
      <div class="collapsible-body"><span> ></span></div>
    </li>
    <li>
      <div class="collapsible-header"><i class="material-icons">place</i>Second</div>
      <div class="collapsible-body"><span>Lorem ipsum dolor sit amet.</span></div>
    </li>
    <li>
      <div class="collapsible-header"><i class="material-icons">whatshot</i>Third</div>
      <div class="collapsible-body"><span>Lorem ipsum dolor sit amet.</span></div>
    </li>
  </ul>

         <div class ="input-field col s12">
            <p>
            <input id = "married" type = "checkbox" />
            <label for = "married">Married</label>
            </p>
        </div>


</div>
</body>
</html>

Solution

  • You are using materialise CSS and bootstrap CSS both in your sample HTML page. As far as i know and have worked on materialise, the CSS of both bootstrap and materialise clash resulting in not rendering of certain controls.

    I know some sites use bootstrap and materialise both but they have been specifically made for such sites that they don't clash.

    If you want to use both of them, i suggest you go and download a bootstrap materialised template. I did the same and it worked for me.