html - <select> custom style - html

i'm trying to customize the whole style of the component, and hide the selector image. All graphics style such border, shadows are setted in the previous table. Now i want to remove all style from the selection menu such as the horrible icon to select an item
My original code in jsf:
<h:panelGrid class="dropDown">
<h:selectOneMenu value="#{myBean.selected}"
id="list" class="test" style="border-style:none; height:31px;">
<f:selectItems value="#{myBean.list}" var="item"
itemLabel="#{item.name}" itemValue="#{item.code}" />
<f:ajax execute="#this" />
</h:selectOneMenu>
</h:panelGrid>
This is my style for class .test
.test{
background-color: white;
clear: both;
color: black !important;
font-family: Helvetica !important;
font-size: 16px !important;
height: 30px;
margin-bottom: 0;
border-style: none;
}
My page rendered in html:
<select id="list" name="item" class="test" size="1" style="border-style:none; height:31px;"onchange="jsf.util.chain(this,event,'disableBox()','mojarra.ab(this,event,\'valueChange\',\'#this\')')">
<option value="1">al</option>
...
<option value="22">re</option>
</select>
But when i open the webpage from a webview (Android) I still see the icon .
Is it impossible to remove if I'm on a simple Webview? Or what element should I use to remove it? Or, it's another component I could use?
My idea is to hide the icon and allow a user to click on the single line, then the Android original component drop down list is opened.
I know that it's styled by the operating system.. any suggestion?
I think it's not usefull.. but I created a simple jsfiddle page where I can test css style modifications.
jsfiddle

The standard JSF html renderkit will render an h:selectOne as a simple html select tag with you f:selectItems becoming the child option tags.
<select>
<option value="a">a</option>
<option value="b">b</option>
</select>
so your question is really is there a way to remove the icon from an html select tag. It really has nothing to do with JSF.
Once you've figured out how to write the html and cssto get the effect you want, you can then write a custom renderer to reproduce that html.

Found a working solution with custom css:
Since the component jsf is rendered as , we include all elements inside a , or in this case inside a
<h:panelGrid class="parent dropDown">
<h:selectOneMenu value="#{myBean.selected}"
id="list" class="test" style="border-style:none; height:31px;">
<f:selectItems value="#{myBean.list}" var="item"
itemLabel="#{item.name}" itemValue="#{item.code}" />
<f:ajax execute="#this" />
</h:selectOneMenu>
</h:panelGrid>
adding the class parent to the panelGrid and defining:
.parent{
width:98%;
overflow:hidden;
}
.parent select{
width:100%;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: none;
background: none;
}
Our jsf component is rendered without the arrow and other components, like borders and shadows.

custom style select using only html and css not any js/javascript
`http://jsfiddle.net/suyogN/39tx46L3/`

Related

How to add styles to angular component? (every second element)

I have a question about adding styles to Angular components.
e.g I would like to have every second angular component in a list to have red background-color.
How can I make it happen?
I tried a lot of different things - it seems that it is added in HTML but doesn't work.
<ang-component class="someClass" />
<ang-component class="someClass" />
I tried setting it in parent component styles
ang-component:nth-child(odd) {
background-color: red;
}
but it doesn't work. It shows up while inspecting but there is no visible effect
EDIT: Code - to show an example how it looks
<form [formGroup]="form" class="someParentClass" (ngSubmit)="onUpdateForm()" >
<item></item>
<hr />
<item></item>
<item></item>
<hr />
<div id="btn-save-section">
<button class="cancel-btn" type="button">Cancel</button>
<button class="update-btn" type="button">Update</button>
</div>
I want item components to change - so every second should have background color red
ang-component:nth-child(odd) > * {
background-color: red;
}
because your component root element is probably only a container w 0 width and 0 height

CSS Class applies, but style doesn't change

My html elements have the CSS classes, I can clearly see them when I inspect elements in the browser (F12) but there are no style changes.
This is my reference to my css page:
<link href="MyCSSPage.css" rel="stylesheet" type="text/css" />
And this is my actual CSS page:
.rightMargin {
margin-right: 30px;
border-radius: 3px;
margin-bottom: 14px;
}
And my html element looks like this:
<asp:TextBox ID="txtUsername" runat="server" Height="50px" Width="300px" CssClass="rightMargin" />
The strange thing is, when I had the CSS right on my aspx page with the style tags around it, it all worked. Any ideas?
Here's how the code appears in the DOM explorer:
<input name="txtUsername" type="text" id="txtUsername" class="rightMargin" style="height:50px;width:300px;">
.rightMargin {
margin-right: 30px;
border-radius: 3px;
margin-bottom: 14px;
}
<input name="txtUsername" type="text" id="txtUsername" class="rightMargin" style="height:50px;width:300px;" />
I had the same situation. In the inspector I saw the class being added by an event listener, but the style attached to it was not visible on the page.
I had the following code:
div {
style: working;}}
div.highlight {
style: not-working;}
As you can see, I had an unwanted } at the end of the first block, left by accident, so the second block was ignored by the browser.
As I was searching through SO, I saw many questions related to similar problems by various reasons. I hope my answer helps someone in the future.

How to give scrolling effect in datalist dropdown?

I am using HTML datalist to show various career paths but my number of options is too long . I wish to give it a scrolling effect. I have searched for it but only thing I found was CSS cannot be applied on datalist. Is it possible to apply styles on datalist using jQuery?
Here is my HTML markup:
<input class="form-control searchbar" #input (input)="filterdata(input.value)" [(ngModel)]="homesearch" id="home_ssearch" name="careerr" list="careers" placeholder="Discover more about any career you like" />
<div>
<datalist class="datalist" id="careers" >
<option *ngFor = "let career of carrerpathList" value="{{career.title}}" ></option>
</datalist>
</div>
Try this
.scrollable {
overflow-y: auto !important; // Use !important only if there is already an overflow style rule for this element and you want to override
}
And just apply it like this:
<datalist class="datalist scrollable" id="careers" >
<option *ngFor = "let career of carrerpathList" value="{{career.title}}" ></option>
</datalist>
Hope it helps! ;)
Update 1:
I hate inline styles, but let's try it to see if <datalist> accepts styles. Try this:
<datalist class="datalist scrollable" id="careers" style="overflow-y: auto!important">
This simple approach works for me:
datalist {
max-height: 500px;
overflow-y: auto;
}
Note: This CSS will apply the scroll effect to all <datalist>
In general, you can't. This element is an example of a "replaced element", these are OS-dependent and are not part of the HTML/browser. It cannot be styled via CSS.
Instead you can use bootstrap dropdown or any other plugin for the same.
I have used bootstrap for it, you can adjust the height accordingly for e.g,
.dropdown-menu {
max-height: 150px;
overflow-y: auto;
}
jsfiddle link
try this:
.datalist {
height:50px !important;
max-height:80px !important;
overflow-y:auto;
display:block !important;
}

Primefaces styling component class with CSS

How can I change properties of component using CSS?
Let's say I have two buttons:
<p:commandButton id="mySmallButton" styleClass="smallButton">
<p:commandButton id="myButton">
I want all my buttons to have font-size: 14px; so I added this rule:
.ui-button .ui-button-text{
font-size:14px;
}
But my smallButton should have different size, so I added:
.smallButton{
font-size:11px;
}
Unfortunatelly this doesn't work. This is produced HTML:
<button class="ui-button ui-widget ui-state-default ui-corner-all
ui-button-text-only smallButton" (...)>
<span class="ui-button-text ui-c">MY TEXT</span>
</button>
The text on this button is stil 14px size. How should CSS look like to have all my smallButton font-size: 11px ?
Your problem is related to the loading order of all the CSS. CSS are cascading style sheets. So if you want your .smallButton style to be applied, it must be the last in the css chain, in order to override any previous matching styles.
Check the order of the CSS (see generated source header in your browser)
If you want your CSS to be the last one, you can use this inside your page or template:
<f:facet name="last">
<h:outputStylesheet library="default" name="css/yourstyles.css" />
</f:facet>
This avoids overuse of !important tag, that works either.
EDIT
This works fine for me on chrome. Chrome says font-size is 11px for ui-button-text embeded span, and displays the first button smaller than the second one, which font-size is 14px.
<style>
.ui-button-text{
font-size:14px;
}
.smallButton .ui-button-text {
font-size:11px;
}
</style>
<p:commandButton id="mySmallButton" styleClass="smallButton"/>
<p:commandButton id="myButton"/>
Also, please notice that the generated html buttons do not have any ui-button class.
I found the solution to my problem. All I need is this:
.smallButton.ui-button-text-only .ui-button-text {
font-size: 11px;
}
So now ui-button-text-only .ui-button-text only apply to the smallButton. I tried it before but with space after .smallButton so it didn't work. Now it is working properly. Thanks for your answers.
PrimeFaces overrides your css with the default rules for the parent form.
You can define your css for the form like this:
form .smallButton{
font-size:11px;
}
or you can use the !important keyword:
.smallButton{
font-size:11px !important;
}
See also:
PrimeFaces: how to override CSS class
PrimeFaces overrides my custom CSS style

How to style the border of a h:selectBooleanCheckbox?

How can I give the <h:selectBooleanCheckbox> a red border?
I tried it as follows, but the border doesn't appear at all.
<h:selectBooleanCheckbox style="border: 1px solid red;" />
try this one ,
<h:selectBooleanCheckbox id="deleSub" style="border-color:red;" value="#mobeeCustomerHome.deleteSubscription}" />
The JSF <h:selectBooleanCheckbox> generates a HTML <input type="checkbox"> element. The style of the HTML <input type="checkbox"> element is very strictly controlled by the specific webbrowser used by the client.
Using border works in Internet Explorer only and even then the appearance is ugly. There's some good padding between the box and the border. To get it to appear the way you want in other browsers you should be using outline instead.
<h:selectBooleanCheckbox style="outline: 1px solid red" />
Note that this does in turn not work in IE! You'd likely want to specify the both CSS properties if you want to have a red border across all browsers.
<h:selectBooleanCheckbox style="border: 1px solid red; outline: 1px solid red" />
Please note that this is completely unrelated to JSF. It's a pure HTML/CSS matter. JSF is merely a HTML code generator. The problem ultimately boils down to the styleability of a HTML <input type="checkbox"> element.
A completely different alternative is to go for a 3rd party JSF component library which allows more fine grained control over the UI, such as PrimeFaces. See also the <p:selectBooleanCheckbox> showcase. It's using jQuery UI (with CSS themeroller!) under the covers.
This has more the to due with the HTML checkbox itself rather than the JSF tag.
See post: How to change checkbox's border style in CSS?
You could try:
outline: 1px solid red;
-moz-appearance: none;
This gets part of the way I think your looking for in FF it does nothing in IE8 (border does nothing in IE8 either). I haven't tested any other browsers.