javascript - 无法破解通过 css 插件使两个输入元素在线显示?

标签 javascript html css

我正在为下拉菜单 使用插件。插件链接是here. .我想将此代码添加到已经制作的 html 代码中,但首先我想进行测试。所以,到目前为止,一切正常,直到我尝试制作两个小部件副本并使它们并排显示。默认情况下输入元素显示在行中,但插件 css 将其向下推变成单列(堆叠)我不想要这个。这是 HTML 代码。

HTML

<head>
<script type="text/javascript" src="lib/jquery-1.2.6.js"></script>
<script type="text/javascript" src="lib/jquery.mcdropdown.js"></script>

<!---// load the mcDropdown CSS stylesheet //--->
<link type="text/css" href="css/jquery.mcdropdown.css" rel="stylesheet" media="all" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>



<body>
<ul id="categorymenu" class="mcdropdown_menu">
  <li rel="1">
    Arts &amp; Humanities
    <ul>
      <li rel="2">
        Photography
        <ul>
          <li rel="3">
            3D
          </li>
          <li rel="4">
            Digital
          </li>
        </ul>
      </li>
      <li rel="5">
        History
      </li>
      <li rel="6">
        Literature
      </li>
    </ul>
  </li>
  <li rel="7">
    Business &amp; Economy
  </li>
  <li rel="8">
    Computers &amp; Internet
  </li>
  <li rel="9">
    Education
  </li>
  <li rel="11">
    Entertainment
    <ul>
      <li rel="12">
        Movies
      </li>
      <li rel="13">
        TV Shows
      </li>
      <li rel="14">
        Music
      </li>
      <li rel="15">
        Humor
      </li>
    </ul>
  </li>
  <li rel="10">
    Health
  </li>
</ul>

<div class="test"> <input type="text" class="category" name="category" id="category" value="" />
<input type="text" class="category" name="category" id="category_1" value="" /></div>

JavaScript

<script>
$(document).ready(function (){
  $("#category").mcDropdown("#categorymenu");
    $("#category_1").mcDropdown("#categorymenu");

});
</script>
</body>
</html>

CSS 插件

/* 
    styles for the psuedo-select box 
*/
div.mcdropdown {
    position: absolute;
    border: 1px solid #8e9daa;
    padding: 1px;
    display: -moz-inline-block;
    display: inline-block;
    width: 408px;
    height: 14px;
    padding: 2px;
}

/* style either the input or div where the plug-in is attached to */
div.mcdropdown input, 
div.mcdropdown div {
    position: absolute;
    background-color: #fff;
    left: 0;
    top: 0;
    width: 98%;
    border: 0;
    padding: 2px 0 0 3px;
    font: 11px Arial, Helvetica, sans-serif;
}

div.mcdropdown a {
    position: absolute;
    right: 1px;
    top: 1px;
    background: transparent url(../images/mcdropdown/mcdd_select_button_sprite.gif) no-repeat top left;
    display: -moz-inline-block;
    display: inline-block;
    height: 16px;
    width: 15px;
    text-decoration: none;
    font-size: 0pt;
    z-index: 2;
    outline: 0;
}

div.mcdropdown a:hover, div.mcdropdown a:focus {
    background-position: 0% -16px;
}

div.mcdropdown a:active {
    background-position: 0% -32px;
    outline: none; /* hide dotted outline in Firefox */
}

div.mcdropdownDisabled {
    background-color: #e1e0e0;
    filter:alpha(opacity=75);
    -moz-opacity: 0.75;
    opacity: 0.75;
    -khtml-user-select: none;
    -o-user-select: none;
    -moz-user-select: none;
    -moz-user-focus: ignore; 
    -moz-user-input: disabled; 
}

div.mcdropdownDisabled input {
    cursor: default;
}

div.mcdropdownDisabled a:hover, div.mcdropdownDisabled a:focus {
    background-position: 0 0;
    cursor: default;
}

/* 
    styles for the dropdown menu 
*/
ul.mcdropdown_menu {
    display: none;
    margin: 0px;
    padding: 0px;
    list-style-type: none;
    /* float so we can calculate the size of the columns */
    float: left;
    clear: both;
    z-index: 10000;
    -khtml-user-select: none;
    -o-user-select: none;
    -moz-user-select: none;
    -moz-user-focus: ignore; 
    -moz-user-input: disabled; 
}

ul.mcdropdown_menu ul {
    display: none;
    font: 11px Arial, Helvetica, sans-serif;
    /* float so we can calculate the size of the columns */
/*
    float: left;
*/
}

/* -- Sub-Menus -- */
ul.mcdropdown_menu ul {
    position: absolute;
    list-style-type: none;
    margin: 0px;
    margin-left: 30px;
    padding: 0px;
    z-index: 10000;
}
ul.mcdropdown_menu ul li {
    margin: 0px;
    min-width: 150px;
    _width: 150px; /* ie6 min-width hack */
}


/* color schema */
ul.mcdropdown_menu {
/*
    height: 19px;
*/
    height: auto;
    background-color: #e1e0e0;
    padding: 5px 5px;
    /* define font here for IE6 */
    font: 11px Arial, Helvetica, sans-serif;
}

ul.mcdropdown_menu li {
    padding: 2px 20px 2px 6px;
    /* this is needed to ensure that all browsers have the same line-height--fixes issues in Chrome (Mac) and IE10 */
    line-height: 14px;
}

/* we don't use "ul.mcdropdown_menu > li" here so that IE6 knows how to style the root level */
ul.mcdropdown_menu li.mc_root {
    cursor: pointer;
    white-space: nowrap;
    color: #666;
    border-top: 1px solid #fff;
    padding: 2px 20px 2px 6px;
    margin: 0 10px;
}

ul.mcdropdown_menu > li.mc_endcol {
    border-bottom: 1px solid #fff;
}

/* this is for IE6 only */
ul.mcdropdown_menu li.mc_hover {
    background-color: #ccc !important;
}

ul.mcdropdown_menu > li:hover {
    border-top: 1px solid #999;
    background-color: #999 !important;
    color: #fff;
}

ul.mcdropdown_menu > li:hover.mc_endcol {
    border-bottom: 1px solid #999;
}

ul.mcdropdown_menu > li:hover + li:not(.mc_firstrow) {
    border-top: 1px solid #999;
}

ul.mcdropdown_menu li.mc_parent {
    padding-right: 20px !important;
    background: url(../images/mcdropdown/mcdd_icon_normal.gif) no-repeat 100% 50%;
}

ul.mcdropdown_menu li:hover.mc_parent {
    background: #999 url(../images/mcdropdown/mcdd_icon_hover.gif) no-repeat 100% 50% !important;
    color: #fff !important;
}

ul.mcdropdown_menu ul {
    background: #f0f0f0;
    /* add a slight border for better visualization of deep menus */
    border: 1px solid #d0d0d0;
    padding-bottom: 10px;
    /* IE 6/7 will bleed through the background color if we don't set the visibility to hidden */
    visibility: hidden;
}

ul.mcdropdown_menu ul li {
    background: #f0f0f0;
    padding-left: 16px !important;
    border-top: 1px solid #fff;
    color: #666;
    white-space: nowrap;
}

ul.mcdropdown_menu ul li.mc_firstrow {
    border-top: 1px solid #f0f0f0;
}

ul.mcdropdown_menu ul li.mc_endcol {
    border-bottom: 1px solid #fff;
}

ul.mcdropdown_menu ul li:hover {
    background-color: #d6d6d6;
    border-top: 1px solid #dedede;
    color: #666;
}

ul.mcdropdown_menu ul li.mc_endcol:hover {
    border-bottom: 1px solid #dedede;
}

ul.mcdropdown_menu ul li:hover + li:not(.mc_firstrow) {
    border-top: 1px solid #dedede;
}

/*
 * drop down shadows
 */
div.mcdropdown_shadow {
    display: none;
    position: absolute;
    margin: 3px 0 0 3px;
    /* for IE6, we use just a square transparent image */
    background: #000;
    filter :alpha(opacity=33);
}

/* ie6 ignores this selector */
html>body div.mcdropdown_shadow {
    /* let's use a transparent PNG */
    margin: 5px 0 0 5px;
    padding: 5px 0 0 5px;
    background: transparent url(../images/mcdropdown/shadow.png) right bottom no-repeat !important;
    /* remove the filter for IE7 */
    filter: none;
}

/* 
 * styles for the dropdown menu 
 */
/* autocomplete styles */
ul.mcdropdown_autocomplete {
    display: block;
  position: absolute;
    height: auto;
    max-height: 210px;
  overflow-x: hidden;
    overflow-y: auto;
  clear: both;
    padding: 5px 10px;
    background-color: #e1e0e0;
    z-index: 10000;

    margin: 0px;
    list-style-type: none;
    width: 392px;
    font: 11px Arial, Helvetica, sans-serif;
}

ul.mcdropdown_autocomplete ul {
    display: none;
    list-style-type: none;
    margin: 0px;
    padding: 0px;
}
ul.mcdropdown_autocomplete ul li {
    margin: 0px;
}

ul.mcdropdown_autocomplete li {
  display: block;
    font: 11px Arial, Helvetica, sans-serif;
    cursor: pointer;
    white-space: nowrap;
    color: #666;
    border-top: 1px solid #fff;
    padding: 2px 26px 2px 6px;
}

ul.mcdropdown_autocomplete li.mc_endcol {
    border-bottom: 1px solid #fff;
}

ul.mcdropdown_autocomplete li.mc_parent {
    padding-right: 20px !important;
    background: url(../images/mcdropdown/mcdd_icon_normal.gif) no-repeat 100% 50%;
}

ul.mcdropdown_autocomplete li.mc_hover {
    border-top: 1px solid #999;
    background-color: #999 !important;
    color: #fff;
}

ul.mcdropdown_autocomplete li.mc_hover_parent {
    background: #999 url(../images/mcdropdown/mcdd_icon_hover.gif) no-repeat 100% 50% !important;
    color: #fff !important;
}

我尝试过但失败的事情

.category {
  float: left;
  display: block;
}

#category_1 {
  margin-left: 20px; /* or space you want..*/
}

    <style>
        #category, #category_1{
            display: inline;
        }
    </style>

请指导我。谢谢。

最佳答案

将此添加到您的 CSS:

div.test > div { 
    float: left; 
    width: 408px; 
    margin-right: 20px; 
}

关于javascript - 无法破解通过 css 插件使两个输入元素在线显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20445899/

相关文章:

html - 为什么浏览器不从缓存中加载 cdn 文件?

php - 如何检索表的列数据,将其存储到数组中,最后回显该数组

css - 带有背景图片的时事通讯

javascript - 如何添加适用于滚动的CSS动画效果仅适用于特定的div?

javascript - 在 Angular2 中使用 Parse 作为模块

javascript - Firebase - 网络。无法显示登录用户的图片

javascript - 我是否适本地使用了 Javascript 回调(面向对象的风格)?

html - Bootstrap 折叠文本装饰

css - 从浏览器在自定义区域打印

javascript - 为什么我会收到 "missing ) after argument list"错误?