Styling the right button of the split button in jQuery Mobile version 1.4.0 using CSS

I was attempting to create a listview with list items that have a button on the right side, much like a jQuery Mobile split button listview. However, I only want the right button to be clickable. The left part of each item should contain a label along with a text input field.

In my search for a solution, I came across this helpful answer:

Unfortunately, the class used in the provided answer was removed or renamed in jQuery Mobile 1.4.0. Some properties can now be found in .ui-btn-a, but not all of them.

With limited CSS knowledge, I decided to try and implement it myself. Here is what I have so far:

HTML:

<li class="readonly-li-a">
    <a class="readonly-btn-a ui-field-contain">
        <label for="boss">Boss:</label>
        <input type="text" id="boss" name="boss">
    </a>
    <a data-role="button" data-inline="true" data-icon="bars" data-iconpos="notext"></a>
</li>

CSS:

.readonly-btn-a {
    background: #fff!important /*{a-bup-background-color}*/;
    color: #333!important /*{a-bup-color}*/;
    text-shadow: 0 /*{a-bup-shadow-x}*/ 1px /*{a-bup-shadow-y}*/ 0 /*{a-bup-shadow-radius}*/ #f3f3f3 /*{a-bup-shadow-color}*/;
    cursor: default !important; /* don't change to hand cursor */
    border: none !important;
}

.readonly-li-a {
    border: 0 solid #ddd !important;
    border-top-width: 1px !important; /*the line above the li */
    padding: .7em 1em !important; /*copied from .ui-li-static */
    background: #fff!important; /*white background instead of grey*/
    margin: 0 1px!important; /*the li stands out by 1px left/right without this*/
    -webkit-box-shadow: 0 1px 3px /*{global-box-shadow-size}*/      rgba(0,0,0,.15) /*{global-box-shadow-color}*/;
    -moz-box-shadow: 0 1px 3px /*{global-box-shadow-size}*/         rgba(0,0,0,.15) /*{global-box-shadow-color}*/;
    box-shadow: 0 1px 3px /*{global-box-shadow-size}*/              rgba(0,0,0,.15) /*{global-box-shadow-color}*/;
}

To see it in action, you can check it out here: http://jsfiddle.net/MasterQuestMaster/QJ9m2/

However, there are two issues with this current solution that I need help addressing:

  • When you enter text into the field, the blue shine effect gets cut off by the border of the <a> tag. This could be due to the padding added to .readonly-li-a.
  • The text input is not aligned correctly, although the label is positioned correctly.

If anyone has encountered these problems before or has a better solution, please share your insights. Your help would be greatly appreciated.

Answer №1

To achieve the desired layout with minimal CSS rules, a small adjustment in the markup can do the trick. The existing classes ui-li-static and ui-body-inherit already handle styling for LI elements, so only two CSS rules are needed: one for setting margins to align inputs and another for a specific button class (readonly-btn-a):

<ul data-role="listview" data-inset="true">
    <li>
        <div class="ui-field-contain">
            <label>Normal:</label>
            <input type="text" id="normal" name="normal"/>
        </div>
    </li>
    <li class="ui-li-static ui-body-inherit">
        <a href="#" class="readonly-btn-a" >
            <div class="ui-field-contain">
                <label>Link:</label>
                <input type="text" id="link" name="link"/>
            </div>
        </a>
        <a href="#" class="ui-btn ui-icon-bars ui-btn-icon-notext ui-btn-inline"></a>
    </li>
    <li>
        <div class="ui-field-contain">
            <label>Normal:</label>
            <input type="text" id="normal2" name="normal2"/>
        </div>
    </li>
</ul>

li .ui-field-contain {
    margin-right: 42px; !important;
}
.readonly-btn-a {
    background:             #fff!important /*{a-bup-background-color}*/;
    color:                  #333!important /*{a-bup-color}*/;
    text-shadow: 0 /*{a-bup-shadow-x}*/ 1px /*{a-bup-shadow-y}*/ 0 /*{a-bup-shadow-radius}*/ #f3f3f3 /*{a-bup-shadow-color}*/;
    cursor: default !important;
    border: none !important;
    padding: 0 !important;
    margin: 0!important;
}

For an improved version of the solution, check out the updated FIDDLE (based on Jeff's GOOD answer)

UPDATE: To reduce padding within LI elements, include the following CSS rule:

.ui-listview>.ui-li-static {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

Explore the enhanced version through the updated DEMO

Answer №2

Is it necessary to rely on jQuery mobile for the design? It might be simpler to add data-role='none' to your input elements and customize their appearance individually using CSS. I have taken this approach in past projects due to the challenges of working with jQuery mobile.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring design techniques in React Native

I am currently part of a team working on a react native project with multiple contributors. My goal is to find an effective way to segregate the styling tasks from coding, allowing UI developers to work independently without relying on code developers. In ...

increasing the top margin on an HTML document

Looking to create a specific amount of blank space at the top of your HTML page? The space needs to be exactly X pixels tall. How can this be achieved effectively, while ensuring compatibility with Safari? ...

What causes the discrepancy between the values returned by the jQuery getter css() method and JavaScript when accessing the style variable

After recently beginning to use jquery, I decided to switch due to initialization issues when loading external styles with javascript. Here is a rule defined in an external style sheet: #siteLogoDiv { position:absolute; left:0px; top:0px; width:100%; heig ...

Retrieving the input[text] value in TypeScript before trimming any special characters

One of the tasks I am working on involves a form where users can input text that may contain special characters such as \n, \t, and so on. My objective is to replace these special characters and then update the value of the input field accordingl ...

Why won't my jQuery replaceWith function work properly when using </div> tags

I've been struggling to solve this issue for hours with no success.. Let me start by asking my specific question, and then I'll provide the broader context in case my entire approach is flawed. Specific Question: I'm attempting to replace a ...

jQuery function used to create an HTML menu

My goal is to dynamically update the HTML file generated by a PHP script when I modify an item in a drop-down menu using jQuery. Here is the code: JQUERY <script type="text/javascript"> $(document).ready(function() { $('#regioni&ap ...

Is it possible to delay the loading of a page using location.href?

Trying to determine when a page has finished loading using location.href. Currently, my code is set up like this and I want certain events to occur once the page is fully loaded. I attempted using $.get but encountered issues with my existing implementatio ...

What is the process for making an ajax call in CakePHP?

It may seem obvious, but I've searched the internet and couldn't find any useful or updated information on this topic. I'm attempting to make an ajax request in CakePHP controller to retrieve both view contents and JavaScript code. The aja ...

What is the best method for inserting the HTML content from a specific div into a textarea?

Everything seems to be working fine, but once I insert the HTML into the textarea, an issue arises where the div gets wrapped within another div, causing the layout to break. var urls = []; $('body').on('click', '.btn_video&apos ...

The lack of an error event being triggered by jQuery when an ajax call fails has puzzled many users

Why doesn't jQuery trigger an error event when running the following script? Even though I've set up the error event, it's not being called. In Chrome's Network tab in the Console, I see this error: GET http://www.google.com/adfdaf?c ...

Unable to convert information into JSON format

In my PHP file, I created a JSON array like this: $array[1] = "string1"; $array[2] = "string2"; $array[3] = "string3"; echo json_encode($array); I want to assign each string to different ID tags in my HTML, but the following code didn't w ...

Generating pop-up upon loading with CSS3

I have searched through numerous threads and forums in the hopes of finding a solution, but I haven't been successful. My issue lies with triggering a popup on my website. I followed online tutorials to create a popup window, which I was able to do su ...

"Utilizing a media query to display an anchor link at the top based

How can I create a "Back to Top" link that automatically scrolls mobile and tablets to the top of the page? Usually, I would achieve this using JavaScript by detecting the window and body height. Is it possible to accomplish this using a media query? @me ...

What is causing my JS/JQuery code to only function in the console of a web browser?

I am having trouble with the $(element).scroll(function(){}); function. When I put it into a js file, it does not work properly, but when I enter it directly into the console (just the scroll func), it works fine. My goal is to implement scrolling paginat ...

Display HTML code inside a specified div

I am attempting to incorporate content from another HTML file into my current web page using jQuery's .load method. Unfortunately, the content is not loading as expected. Can anyone provide me with a solution to this issue? Below is the HTML and jQ ...

Creating a color-changing checkbox toggle in Bootstrap 5

Is it possible to customize the color of a Bootstrap 5 switch without changing it site-wide? I want some checkbox switches to have a unique color. Most tutorials online only cover how to change colors globally or use images, but I'm hoping to achieve ...

Utilizing the GET method within a form

I'm currently working on testing a form to ensure that my input values are being submitted correctly. At this point, I haven't set up any server script yet. However, I was hoping that upon clicking submit, I would be able to see my values appende ...

Modifying the default text within a select box using jQuery

Within a select box identified as 'edit-field-service-line-tid', there is default text displayed as '-Any-'. This particular select field has been generated by Drupal. I am looking to use jQuery to change the text '-Any-' to ...

What is the reason that setting margin to 0 auto centers an element, while using margin 1 auto does not have the same effect?

When using margin: 0 auto;, it means that there is a margin size of 0 on the top and bottom of the element, with the available space being divided equally for the left and right margins. This behavior works as expected in the example below. In contrast, c ...

What is the best way to hide the drop down menu after it has been opened by clicking on the same element

My attempt to create a code that toggles a drop-down menu on every click and closes any other open menus is not working as expected. The menu doesn't close upon clicking it again. $(document).ready(function(){ "use strict"; $(".dropdown").hi ...