0

I wanted to resize the the text in option, but not all the text. The following will is my code.

<select>
    <?php foreach($dataholder as $key=>$value): ?>
        <option value='<?php echo $value; ?>' ><?php echo $key; ?> <small>(Max: <?php echo $max[$value]; ?>)</small> </option>
    <?php endforeach; ?>
</select>

I wanted the resize or apply style for the text that containing in the .

Below is my original html copy from the browser.

<select class="select form-control col-md-4" id="renewal_period_flag" name="renewal_period_flag" style="width:320px !important;height:32px;">
                                                                                 <option value="1">Weekly (Max: RM6.00)                                         </option>                                                                           <option value="2">Monthly (Max: RM6.00)                                           </option>

</select>
d3no
  • 121
  • 1
  • 3
  • 12

5 Answers5

1

For add sub text to option text Refer this url : https://silviomoreto.github.io/bootstrap-select/examples/#subtext

Need to use Bootstrap.

Select Box Code is

<select class="selectpicker" data-size="5">
  <option data-subtext="Heinz">Ketchup</option>
</select>

Output is

enter image description here

Bharat Dangar
  • 527
  • 4
  • 20
  • Ya, I need subtext in option. Seem to be don't have any way to without using plugin to solve my problem. Anyway, your answer still have me solve the issue I facing now, thank you. – d3no May 10 '17 at 09:23
  • As i know,No it is not possible to add html to option's text.We need to use some plugin. – Bharat Dangar May 10 '17 at 10:40
0

You can achieve by adding css like: [this code is originally from https://codepen.io/ericrasch/pen/zjDBx]

/* -------------------- Page Styles (not required) */

div {
  margin: 20px;
}


/* -------------------- Select Box Styles: bavotasan.com Method (with special adaptations by ericrasch.com) */


/* -------------------- Source: http://bavotasan.com/2011/style-select-box-using-only-css/ */

.styled-select {
  background: url(http://i62.tinypic.com/15xvbd5.png) no-repeat 96% 0;
  height: 29px;
  overflow: hidden;
  width: 240px;
}

.styled-select select {
  background: transparent;
  border: none;
  font-size: 14px;
  height: 29px;
  padding: 5px;
  /* If you add too much padding here, the options won't show in IE */
  width: 268px;
}

.styled-select.slate {
  background: url(http://i62.tinypic.com/2e3ybe1.jpg) no-repeat right center;
  height: 34px;
  width: 240px;
}

.styled-select.slate select {
  border: 1px solid #ccc;
  font-size: 16px;
  height: 34px;
  width: 268px;
}


/* -------------------- Rounded Corners */

.rounded {
  -webkit-border-radius: 20px;
  -moz-border-radius: 20px;
  border-radius: 20px;
}

.semi-square {
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  border-radius: 5px;
}


/* -------------------- Colors: Background */

.slate {
  background-color: #ddd;
}

.green {
  background-color: #779126;
}

.blue {
  background-color: #3b8ec2;
}

.yellow {
  background-color: #eec111;
}

.black {
  background-color: #000;
}


/* -------------------- Colors: Text */

.slate select {
  color: #000;
}

.green select {
  color: #fff;
}

.blue select {
  color: #fff;
}

.yellow select {
  color: #000;
}

.black select {
  color: #fff;
}


/* -------------------- Select Box Styles: danielneumann.com Method */


/* -------------------- Source: http://danielneumann.com/blog/how-to-style-dropdown-with-css-only/ */

#mainselection select {
  border: 0;
  color: #EEE;
  background: transparent;
  font-size: 20px;
  font-weight: bold;
  padding: 2px 10px;
  width: 378px;
  *width: 350px;
  *background: #58B14C;
  -webkit-appearance: none;
}

#mainselection {
  overflow: hidden;
  width: 350px;
  -moz-border-radius: 9px 9px 9px 9px;
  -webkit-border-radius: 9px 9px 9px 9px;
  border-radius: 9px 9px 9px 9px;
  box-shadow: 1px 1px 11px #330033;
  background: #58B14C url("http://i62.tinypic.com/15xvbd5.png") no-repeat scroll 319px center;
}


/* -------------------- Select Box Styles: stackoverflow.com Method */


/* -------------------- Source: http://stackoverflow.com/a/5809186 */

select#soflow,
select#soflow-color {
  -webkit-appearance: button;
  -webkit-border-radius: 2px;
  -webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1);
  -webkit-padding-end: 20px;
  -webkit-padding-start: 2px;
  -webkit-user-select: none;
  background-image: url(http://i62.tinypic.com/15xvbd5.png), -webkit-linear-gradient(#FAFAFA, #F4F4F4 40%, #E5E5E5);
  background-position: 97% center;
  background-repeat: no-repeat;
  border: 1px solid #AAA;
  color: #555;
  font-size: inherit;
  margin: 20px;
  overflow: hidden;
  padding: 5px 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 300px;
}

select#soflow-color {
  color: #fff;
  background-image: url(http://i62.tinypic.com/15xvbd5.png), -webkit-linear-gradient(#779126, #779126 40%, #779126);
  background-color: #779126;
  -webkit-border-radius: 20px;
  -moz-border-radius: 20px;
  border-radius: 20px;
  padding-left: 15px;
}
<!--
  ** Style a Select Box Using Only CSS
  ** Source: http://bavotasan.com/2011/style-select-box-using-only-css/
  ** Source: http://danielneumann.com/blog/how-to-style-dropdown-with-css-only/
  ** Source: http://stackoverflow.com/a/5809186
-->

<div>
  <select>
    <option>Here is the unstyled select box</option>
    <option>The second option</option>
    <option>The third option</option>
  </select>
</div>

<hr>

<div class="styled-select slate">
  <select>
    <option>Here is the first option</option>
    <option>The second option</option>
    <option>The third option</option>
  </select>
</div>

<hr>

<div class="styled-select black rounded">
  <select>
    <option>Here is the first option</option>
    <option>The second option</option>
    <option>The third option</option>
  </select>
</div>

<div class="styled-select green rounded">
  <select>
    <option>Here is the first option</option>
    <option>The second option</option>
    <option>The third option</option>
  </select>
</div>

<div class="styled-select blue semi-square">
  <select>
    <option>Here is the first option</option>
    <option>The second option</option>
    <option>The third option</option>
  </select>
</div>

<div class="styled-select yellow rounded">
  <select>
    <option>Here is the first option</option>
    <option>The second option</option>
    <option>The third option</option>
  </select>
</div>

<hr>

<div id="mainselection">
  <select>
    <option>Select an Option</option>
    <option>Option 1</option>
    <option>Option 2</option>
  </select>
</div>

<hr>

<select id="soflow">
  <!-- This method is nice because it doesn't require extra div tags, but it also doesn't retain the style across all browsers. -->
  <option>Select an Option</option>
  <option>Option 1</option>
  <option>Option 2</option>
</select>

<select id="soflow-color">
  <!-- This method is nice because it doesn't require extra div tags, but it also doesn't retain the style across all browsers. -->
  <option>Select an Option</option>
  <option>Option 1</option>
  <option>Option 2</option>
</select>
Yashar Aliabbasi
  • 2,663
  • 1
  • 23
  • 35
0

What you want to do is not possible with a native <select>, you can't add anything else than text inside an <option> tag.

You will have to implement a custom select or use a library. There are plenty of solutions for different frameworks, but check this one: http://selectize.github.io/selectize.js/

Danziger
  • 19,628
  • 4
  • 53
  • 83
0

You can simply do it by adding style:font-size in your option like this.

<select class="select form-control col-md-4" id="renewal_period_flag" name="renewal_period_flag" style="width:320px !important;height:32px;">
    <option value="1">Weekly (Max: RM6.00) </option> 
    <option value="2" style="font-size:10px;">Monthly (Max: RM6.00) </option>
    <option value="2" style="font-size:10px;">Monthly (Max: RM6.00)</option>
</select>
Ataur Rahman Munna
  • 3,887
  • 1
  • 23
  • 34
  • Setting a `font-size` in the options won't work, you can only set that for the whole ` – Danziger May 09 '17 at 08:08
-1
i found this,

select {
    -webkit-appearance: button;
    -moz-appearance: button;
    -webkit-user-select: none;
    -moz-user-select: none;
    -webkit-padding-end: 20px;
    -moz-padding-end: 20px;
    -webkit-padding-start: 2px;
    -moz-padding-start: 2px;
    background-color: #F07575; /* fallback color if gradients are not supported */
    background-image: url(../images/select-arrow.png), -webkit-linear-gradient(top, #E5E5E5, #F4F4F4); /* For Chrome and Safari */
    background-image: url(../images/select-arrow.png), -moz-linear-gradient(top, #E5E5E5, #F4F4F4); /* For old Fx (3.6 to 15) */
    background-image: url(../images/select-arrow.png), -ms-linear-gradient(top, #E5E5E5, #F4F4F4); /* For pre-releases of IE 10*/
    background-image: url(../images/select-arrow.png), -o-linear-gradient(top, #E5E5E5, #F4F4F4); /* For old Opera (11.1 to 12.0) */ 
    background-image: url(../images/select-arrow.png), linear-gradient(to bottom, #E5E5E5, #F4F4F4); /* Standard syntax; must be last */
    background-position: center right;
    background-repeat: no-repeat;
    border: 1px solid #AAA;
    border-radius: 2px;
    box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1);
    color: #555;
    font-size: inherit;
    margin: 0;
    overflow: hidden;
    padding-top: 2px;
    padding-bottom: 2px;
    text-overflow: ellipsis;
    white-space: nowrap;
}


customize the properties according to your prefrences,
apelidoko
  • 782
  • 1
  • 7
  • 23