Jeremy Logan
Jeremy Logan

Reputation: 47514

Theming elements within a Jquery UI Dialog with CSS... how?

Since the old version was apparently way too hard for people to understand, here's the HTML, CSS, and JavaScript combined:

$(document).ready(function() {
  $('#test').dialog({
    autoOpen: false,
    modal: true
  });
  $("#test-link").click(function() {
    $('#test').dialog('open');
  });
});
div#main div#test label {
  display: block;
}

div#main div#test input {
  padding-left: 100px;
}
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>

<div id="main">
  <p><a href="#" id="test-link">test</a>
    <p>
      <div id="test" title="Submit Bug or Feature Request">
        <form>
          <label for="test_desc">Short Description:</label>
          <input type="text" name="test_desc" id="test_desc" value="" />
          <input type="submit" name="" value="Submit" />
        </form>
      </div>

</div>

The dialog works fine, but the CSS does not. Any ideas why?

Upvotes: 1

Views: 484

Answers (2)

Jeremy Logan
Jeremy Logan

Reputation: 47514

JQuery moves a dialog's DIV in the DOM tree and wraps it in some others. Therefore the CSS selectors won't work. Using the above example you'd have to do something like this:

div.ui-dialog div#test label {
    display: block;
}
div.ui-dialog div#test input {
    padding-left: 100px;
}

Upvotes: 1

tom
tom

Reputation: 2077

The css should work. It might be a problem with how the css rules cascade. Is there a more specific selector applying these rules like "#dialog div#test label"? Without the rest of html/css it's impossible to point out the specifics. Get firebug and see what rules are getting applied to those elements.

Upvotes: 0

Related Questions