0

I'm trying to build a mobile application, with a mail, where you can select a sample message. My problem is that when you clic on the 'select a message' (the beginning of the select), a pop up shows up and you chose the message. BUT I can't (or just don't find how) to change the skin of this pop up... Some one know? My code :

JavaScript:

function selection(select) {
    var valeur = select.options[select.selectedIndex].value;
    if(valeur !="Messages Pré-enregistrés")
        document.getElementById("basic").value = valeur;

}

HTML:

<div id="ContenuBasic">
    <label for="basic">Votre message:</label>
    <input type="text" name="basic" id="basic" value="">    
</div>

<select onchange="selection(this)">
    <option value="">Choisissez un message</option>
    <option value="Pneu crevé">Pneu crevé</option>
    <option value="Batterie morte">Batterie morte</option>
    <option value="Accident">Accident</option>
    <option value="Flic">Flic</option>
</select>

CSS: design.css

select, select :hover {

    width: 100%;
    margin-right : 10px;
    margin-left : 10 px;
    height: 34px;
    overflow: hidden;
    -webkit-appearance: none;
    appearance:none;
    background-color : #3797d3;
    color : white;
    font-size : 14px;
    font-weight: 100px;
 }
3
  • You want to know, how to display a pop up or change styling of pop??? Commented Aug 12, 2014 at 14:50
  • Form input elements are intentionally difficult to style, so that they maintain the appearance of their operating systems. Try a plugin Commented Aug 12, 2014 at 14:57
  • In cases like this I don't use native elements. Create a custom popup of your own that is styled how you like and then create an onclick method that sets the selection to a hidden form field to retain the selection. Sometimes it is better to create your own solution rather than hack an existing one. Commented Aug 12, 2014 at 14:59

2 Answers 2

1

I found how to do it (not hacking an existing plugin, you were right...) it's not fabulous but it's working!

HTML :

<div id="ContenuBasic">
<label for="basic">Your message:</label>
<input type="text" name="basic" id="basic" value="">

</div>

<a href="#" data-width="400" data-rel="popup_name" class="poplight">Messages Pré-enregistrés</a>
<div id="popup_name" class="popup_block">
<div class="message " id="msg1" >Choose a message</div>
<div class="transition"></div>
<div class="message" id="img1" ><p>Message1</p></div></a>
<div class="transition"></div>
<div class="message" ><p>Message2</p></div>
<div class="transition"></div>
<div class="message" ><p>Message3</p></div>
<div class="transition"></div>
<div class="message" ><p>Message4</p></div>


</div>  

Jquery :

jQuery(function($){

//Lorsque vous cliquez sur un lien de la classe poplight
$('a.poplight').on('click', function() {
    var popID = $(this).data('rel'); //Trouver la pop-up correspondante
    var popWidth = $(this).data('width'); //Trouver la largeur

    //Faire apparaitre la pop-up et ajouter le bouton de fermeture
    $('#' + popID).fadeIn().css({ 'width': popWidth}).prepend('');

    //Récupération du margin, qui permettra de centrer la fenêtre - on ajuste de 80px en conformité avec le CSS
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({ 
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues d'anciennes versions de IE
    $('body').append('<div id="fade"></div>');
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();

    return false;
});


//Close Popups and Fade Layer
$('body').on('click', 'a.close, #fade', function() { //Au clic sur le body...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  
}); //...ils disparaissent ensemble

    return false;
});

});

$(document).ready(function(){$('.message').click((function(){

var val = $(this).text();
if(val !="Choisir un message pré-écrit")
document.getElementById("basic").value = val;
$('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  
});
}));});

CSS

#fade { 
display: none; 
background: #cecece;
position: fixed; left: 0; top: 0;
width: 100%; height: 100%;
opacity: .80;
z-index: 9999;
}

a:link, a:visited {
font-family : 'Open Sans';
font-weight: 200;
text-decoration : none;
}
img.btn_close {
float: right;
}
*html #fade {
position: absolute;
}
*html .popup_block {
position: absolute;
}

#msg1{
font-family : 'Open Sans';
font-weight: bold;
color: #3797d3;
margin-left : 20px;
margin-top : 10px;
}
#msg1:hover{
background-color : transparent;
}

.message p{
margin-top:8px;
padding-left : 30px;
}
.message{
width : 400px;
height : 50px;
padding-top:10px;
font-family : 'Open Sans';
font-weight: 200;
}

#basic
{
width: 100%;
}


#img1{
height : 80px;

}
.message:hover{
background-color : #3797d3;
color:white;
}

.transition{
width : 400px;
height : 1px;
background-color : #cecece;
}





.popup_block{
display: none; 
background: #fff;
border: 2px solid #cecece;
float: left;
font-size: 1.2em;
position: fixed;
top: 50%; left: 50%;
z-index: 99999;
-webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000;
-webkit-border-radius: 1px;
-moz-border-radius: 1px;
border-radius: 1px;
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can't realy use css to style your select element. Using javascript you can 'recreate' a select element using regular DOM elements like div.

Some plugins already exists to achive this, for instance take a look at http://davidwalsh.name/jquery-chosen

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.