У меня есть styled-select
, который я сделал для своих требований. Теперь проблема заключается в том, что если выбран вариант больше всей площади, естественно, она заполнит весь div
, как показано на рисунке ниже:Ограничьте текст в div, но сделайте весь div щелчком мыши
Теперь я хочу, чтобы это было ограничено или иметь запас справа, чтобы показать стрелку, который я использовал в качестве background: url
, как на картинке ниже:
Если я уменьшить ширину div
это будет хорошо, но проблема в том, что он выиграл 'clickable i n, чтобы открыть раскрывающееся меню. Теперь я хочу знать, есть ли решение ограничить текст, но все же есть область с кликами?
Вот мой код: Working jsFiddle
$(function() {
$('.styled-select select').hide();
$("select#elem").val('0');
$('.styled-select div').each(function() {
var $container = $(this).closest('.styled-select');
$(this).html($container.find('select option:selected').text());
});
$('.styled-select div').click(function() {
var $container = $(this).closest('.styled-select');
var opLen = $container.find('select').children('option').length;
if (opLen < 5) {
$container.find('select').show().attr('size', opLen).focus();
} else {
$container.find('select').show().attr('size', 5).focus();
}
});
$('.styled-select select').click(function() {
var $container = $(this).closest('.styled-select');
var text = $container.find('select option:selected').text();
$container.find('div').html(text);
$container.find('select').hide();
});
$('.styled-select select').focusout(function() {
var $container = $(this).closest('.styled-select');
$container.find('select').hide();
});
});
.styled-select select {
\t position: absolute;
\t background: transparent;
\t width: 420px;
\t padding-top: 5px;
\t font-size: 18px;
\t font-family: 'PT Sans', sans-serif;
\t color: black;
\t border: 0;
\t border-radius: 4;
\t -webkit-appearance: none;
\t -moz-appearance: none;
\t -o-appearance: none;
\t z-index: 1;
\t outline: none;
\t top: 42px;
\t box-shadow: 0 2px 2px 0 #C2C2C2;
\t }
\t
\t .styled-select {
\t background: url('http://s22.postimg.org/f5gjjtswd/campaign_Selector.png') no-repeat right;
\t background-color: white;
\t width: 420px;
\t height: 42px;
\t position: relative;
\t margin: 0 auto;
\t box-shadow: 0 2px 2px 0 #C2C2C2;
\t background-position: 97% 50%;
\t }
\t
\t .styled-select option {
\t font-size: 18px;
\t background-color: white;
\t margin-left: 3px;
\t }
<div class="styled-select" style="width: 301px; margin:5px 0 0 10px;">
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<div id="userChannelDivId" style="font-size:18px; position: absolute; top: 8px; left: 5px; width: 295px; height: 42px; white-space:nowrap; overflow:hidden"></div>
<select id="userChannelId" name="userChannelId" style="width:100%">
<option value="">resh resh reshadreshadreshadreshadreshad resh</option>
<option value="">--- Select ---</option>
<option value="">--- Celect ---</option>
<option value="">--- Delect ---</option>
<option value="">--- Felect ---</option>
<option value="">--- Gelect ---</option>
</select>
</div>
Было бы лучше, если бы вы выложили ** нерабочим ** код, чтобы мы могли видеть, что вы сделали неправильно, и нужно исправить. – Barmar
@Barmar рабочий код работает не так, как ожидалось.Мое ожидаемое поведение - это тот, у кого ограниченная текстовая область – reshad
Вам лучше разместить более релевантную картину ожидаемого поведения, потому что белая стрелка на белом фоне не имеет большого смысла ... –