【问题标题】:Change style of only one auto complete on site现场仅更改一种自动完成的样式
【发布时间】:2017-05-27 19:10:40
【问题描述】:

使用这个 Q http://stackoverflow.com/questions/17838380/styling-jquery-ui-autocomplete

我能够在我的网站上设置所有自动完成的样式。但是我只想将 WIDTH 样式应用于一个特定的自动完成文本字段。

        <script>
  $( function() {
    var availableCountries = [   
 "Country1",
    "Country2",
    "Country3",
    ];
    $("#tbCountries").autocomplete({
      source: availableCountries
    });
  } );
  </script>



<input id="tbCountries" type="text" class="textEntry form-control RegistrationPage-AutoCompleteCountryWidth" maxlength="30">

我尝试通过输入的 ID 访问它并添加一个类

#tbCountries ul
{
     width:14% !important;
}

.RegistrationPage-AutoCompleteCountryWidth ul
{
   width:14% !important;
}

这些都不起作用....但是...通过从开发人员工具中获取 ul 的 ID,我可以将所需的宽度更改为

#ui-id-1
{
    width:14% !important; WORKING
}

但是,这种糟糕的编码是不是可以这么说,因为从我的网站添加或删除更多自动完成可能会改变这个的 ID?

有什么想法吗? 塔

【问题讨论】:

  • document.getElementsByClassName("yourclass")[0].style.width="14% !important";

标签: javascript css asp.net autocomplete


【解决方案1】:

您尝试选择 ul 元素作为输入的子元素。 在 CSS 中,您可以选择在选择器之间有空格的元素的子元素。

试试这个(只是没有ul childselector 的 ID):

#tbCountries {
     width:14% !important;
}

进一步阅读: https://css-tricks.com/child-and-sibling-selectors/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 2020-05-27
    • 2016-06-07
    • 2021-04-15
    • 2019-08-22
    • 2020-07-30
    • 1970-01-01
    相关资源
    最近更新 更多