javascript - 在国家文本旁边显示下拉框

标签 javascript css

请访问link你可以在左上角看到“国家:”& 下面是下拉框。

enter image description here

1)我想把那个下拉框移到 "country:"旁边,我可以使用 top:5px;lefdt:140px;

但我认为这不是好的 css 实践。

2)我还想在国家名称后留一些空间&

3) 当我们将鼠标悬停在特定国家/地区时,它应该显示不同的颜色。

我想要如下图:

enter image description here

CSS

select#select-language {
    position: absolute;
    top: 30px;
    z-index: 2;
}

脚本

<script>

jQuery(document).ready(function () {
  jQuery('select#select-language').hover(function () {
    jQuery(this).attr('size', jQuery('option').length);
  }, function () {
    jQuery(this).attr('size', 1);
  });
});

</script>

php

 <?php if(count($this->getStores())>1): ?>
<div class="form-language">
    <label for="select-language"><?php echo $this->__('Country:') ?></label>
    <select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value">
    <?php foreach ($this->getStores() as $_lang): ?>
        <?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
        <option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->escapeHtml($_lang->getName()) ?></option>
    <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>

最佳答案

  1. 将其移动到国家/地区,

应该这样做

select#select-language {
    position: relative;
    z-index: 2;
}
  1. 将 size="1"更改为 "5"的悬停效果看起来不是解决该问题的好方法。我建议用户在不悬停的情况下单击下拉菜单。

  2. 如果您想在悬停时使用不同的颜色,您可以在 span 元素中添加一个类,封装选项文本并使用伪 :hover 在 css 中使用您想要的颜色分配颜色。如果您像我上面提到的第 2 点那样更改悬停,则选择突出显示将由浏览器自动呈现。

关于javascript - 在国家文本旁边显示下拉框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37020332/

相关文章:

css - 我将如何设置 :checked radio button? 之后的文本样式

javascript - 用于检测超链接的正则表达式

javascript - 模态对话框适用于 Mozilla,但不适用于 Chrome

javascript - 无法理解为什么 javascript 函数无法正确设置变量

css - 无法为 Check this potential box model size issue 设置 stylelint 规则

c# - 如何获得具有不同背景颜色的下拉菜单。下拉选项是动态的

javascript - 使用纯组件模式测试 Gatsby 的静态查询时,你能做到完全覆盖吗?

javascript - 访问控制公开 header 在 Safari 5.1.7 中不起作用

HTML Outlook 忽略图像的 td 宽度

html - 如何更改 MetisMenu 下拉菜单的背景颜色和设置边距?