如何仅使用无序列表创建语言选择下拉列表?

问题描述 投票:0回答:1

基本上我想创建一个带有标志的语言下拉列表,默认为德国。

首先,创建一个div并在里面

  • 一个
    img
    代表德国国旗和一个
    p
    标签包含国家名称
  • 然后
    ul
    列出我用CSS隐藏的其他县,所以德国是唯一默认显示的国家

但是,这样一来,一旦点击其中一个国家,我就无法显示其他国家;使用jquery。

所以我想做的就是把所有语言都放在

ul
里面,并带有列表项,但这打破了我原来的风格

任何人都可以帮助我设计样式,以便我知道如何在默认情况下显示德语

li
,当有人单击另一种语言时,默认值会随 jquery 更改?

这是我到目前为止的代码:

body {

    font-family: Arial, sans-serif;
    background: #ddd;
    font-weight: 300;
    font-size: 15px;
    color: #333;
    -webkit-font-smoothing: antialiased;
}

.wrapper-country-dropdown {

    position: relative; 
    width: 200px;
    margin: 0 auto;
    padding: 10px 15px;
    background: #f1f1f1;
    cursor: pointer;
    outline: none;
    -webkit-border-radius:5px;
    -moz-border-radius:5px;
    border-radius:5px;
}

.wrapper-country-dropdown:after {

    content: "";
    width: 0;
    height: 0;
    position: absolute;
    right: 16px;
    top: 50%;
    margin-top: -3px;
    border-width: 6px 6px 0 6px;
    border-style: solid;
    border-color: #444 transparent;
}

.wrapper-country-dropdown .country-dropdown-list {

    position: absolute;
    top: 35px;
    left: 0px;
    right: 0px;
    background: #f1f1f1;
    -webkit-transition: all 0.3s ease-out;
    -moz-transition: all 0.3s ease-out;
    -ms-transition: all 0.3s ease-out;
    -o-transition: all 0.3s ease-out;
    transition: all 0.3s ease-out;
    list-style: none;
    opacity: 0;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}

.wrapper-country-dropdown .country-dropdown-list li a {

    display: block;
    text-decoration: none;
    color: #838383;
    padding: 10px;
    -webkit-transition: all 0.3s ease-out;
    -moz-transition: all 0.3s ease-out;
    -ms-transition: all 0.3s ease-out;
    -o-transition: all 0.3s ease-out;
    transition: all 0.3s ease-out;
}

.wrapper-country-dropdown .country-dropdown-list a > img{margin-left: 5px;

}

.flag-icon {
    padding-right: 5px;
    float: left;
}

p { 
    font-size: 16px;
    display: inline;
}

/* Hover  */

.wrapper-country-dropdown .country-dropdown-list li:hover a {
    color: grey;
}

/* Active  */

.wrapper-country-dropdown.active:after {
    border-width: 0 6px 6px 6px;
}

.wrapper-country-dropdown.active .country-dropdown-list {
    opacity: 1;
    pointer-events: auto;
}
<div class="container">

     <div id="dd" class="wrapper-country-dropdown">

      <img src="images/flage/england.png" class="flag-icon">

      <p>England</p>

      <ul class="country-dropdown-list">

      <li>
      		<a href="#">
      			<img src="images/flage/england.png" class="flag-icon">
      			<p class="country-name">Germany</p>
      		</a>
      	</li>

      	<li>
      		<a href="#">
      			<img src="images/flage/germany.png" class="flag-icon">
      			<p class="country-name">England</p>
      		</a>
      	</li>

      	<li>
      		<a href="#">
      			<img src="images/flage/france.png" class="flag-icon">
      			<p class="country-name">France</p>
      		</a>
      	</li>
      </ul>
     	
     </div><!-- end wrapper country dropdown -->

	</div><!-- enc container-->

javascript jquery css hide
1个回答
0
投票

您可以通过以下方式创建列表。

<select name="teste " id="teste ">
     <option >  <li>Coffee</li> </option>
     <option selected="selected">   <li>Tea</li> </option> 
     <option>  <li>Milk</li> </option> 
</select>

其中 selected="selected" 该字段默认处于选中状态。

你可以通过jquery获取该值。

$( "#teste  option:selected" ).text();

您可以参考以下网址了解更多。

Jquery 选择器

© www.soinside.com 2019 - 2024. All rights reserved.