How can I achieve both horizontal and vertical centering simultaneously?

UPDATE: Seeking advice on aligning a rangeslider and its label vertically within the same row. The goal is to have them centered with respect to each other while ensuring the rangeslider takes up all available space.

How can I vertically center a floating element?

Link for reference: http://jsfiddle.net/v2jaY/8/

Alternatively, what's the best way to make an inline block fill the entire width?

Link for reference: http://jsfiddle.net/v2jaY/7/

I've combined these questions because solutions I've come across involve using inline-block for centering and float for filling width. I'm looking for a way to combine both approaches in this case.

HTML:

<div id="table">
    <div data-role="rangeslider" id="column2">
        <label for="slider-bedroom-min" id="column1">Bedrooms:</label>
        <input name="slider-bedroom-min" id="slider-bedroom-min" min="1" max="4" value="1" type="range" />
        <label for="slider-bedroom-max">Bedrooms:</label>
        <input name="slider-bedroom-max" id="slider-bedroom-max" min="1" max="4" value="2" type="range" />
    </div>
</div>

CSS with float:

#table {
    /*overflow-x: hidden;*/
}
#table > label {
    float: left;
    vertical-align: middle;
    margin: 0;
}
.ui-rangeslider {
    overflow-x: hidden;
    vertical-align: middle;
}

CSS with inline:

#table > label {
    display: inline-block;
    vertical-align: middle;
    margin: 0;
}
.ui-rangeslider {
    display: inline-block;
    vertical-align: middle;
    width: 50%;
}

Answer №1

If anyone has a clever approach to achieving this using only CSS, I would love to hear about it. I typically utilize jQuery for tasks like these: http://jsfiddle.net/MHQ6A/

$(function() {
    var $rangeSliderHeight = $(".ui-rangeslider-sliders").height();
    var $label = $("#column1");
    var moveDown = ($rangeSliderHeight / 2) - ($label.height() / 2);
    console.log(moveDown)
    $label.css({
        position: "relative",
        top: moveDown
    });
})

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

Google Feed API - Retrieving saved data from RSS feed cache

We have implemented the Google Feed API to display our latest blog posts on our website. However, even after 24 hours, our most recent post is still not appearing on our site. Despite confirming that the RSS feed contains the newest content, it seems that ...

Troubleshooting the Three.js installation and modules on a local server issue

Seeking assistance from experienced individuals on this platform for my three.js issue. The current problem I am facing is the inability to run the three.js library properly on my localhost, resulting in a white screen. Here are my files: My JavaScript c ...

Transform charset X to Unicode using Java

What is the process to convert a specific charset to unicode in Java? We have discussed charsets extensively, but this particular topic has not been covered yet. I have a hex string that follows the criteria length%4==0 (e.g. \ud3faef8e). Typically, ...

`resolve() and then() taking precedence over asynchronous operations`

I recently came across a tutorial on promises that explained: const promise = new Promise((resolve, reject) => { // Perform asynchronous tasks // If successful resolve(); // If fails reject(); }); After trying to implement this, I haven't had ...

Interconnected realms communication

I'm currently in the process of developing a Facebook iframe app. At one point, I initiate a friends dialog from Facebook and embed an HTML button to add some customized functionality for my app. dialog = FB.ui({ method:'fbml.di ...

Is there a problem with the map() function in React.js?

Every time I try to add a new To Do without modifying the HTML at all and push() the array, everything works smoothly. However, once I trigger the onChange event listener, I encounter the error "this.state.tasks.map is not a function". I'm struggling ...

Firebase Issue in Next JS Authentication Flow: Unconfirmed Email Causes "auth/email-already-in-use" Error to Trigger

I have encountered a perplexing issue while setting up user registration with Firebase Authentication in my Next.js application. The problem arises when I try to register a new user with an unverified email address. Instead of following the correct flow to ...

Pause the scrolling div on hover using jQuery

Currently, I have implemented a WordPress plugin that allows for infinite scrolling of posts. However, I am looking to add a feature where the scroll stops when hovering over a post. I attempted to achieve this using the following script: <script> ...

The JQuery $.post() method is encountering an issue with the incorrect character encoding

I am currently facing an issue with a specific function: $.post('classes/processPage.asp', { param1: $('#hdnValue').val() } Whenever I test this value on the processPage, it returns incorrect characters. I attempted to resolve this ...

Slicknav is failing to appear on the screen, although it is being

After spending hours trying to implement a slicknav menu into my school project, I'm stuck and seeking guidance. Despite having some coding experience, I can't seem to find the solution to my problem. Any help, insight, or tips on fixing or impro ...

Is it advisable to start a function within the componentDidMount() method in ReactJS when using promises?

I am developing an application that utilizes promises to manage animations. After a few attempts, I encountered the following error message: Warning: Can’t call setState on a component that is not yet mounted. This is a no-op, but it might indica ...

Is it possible to adjust the code for fs.readFileSync(__dirname + '/index.html);?

Is it possible to change the code from fs.readFileSync(__dirname + '/game.php'); to fs.readFileSync(__dirname + '/game.php?id='+id);? I encountered an error while trying to do so: fs.js:549 return binding.open(pathModule._makeLong( ...

Struggling to align Jssor slider perfectly within a Bootstrap container

Struggling to center my slider images while using bootstrap with jssor. Despite trying to zero out the margins in the code below, the images within the slider remain aligned to the left side of the container. Any suggestions on how I can properly center ...

Do Material-UI pickers only validate on blur, not on change events?

When you type inside the DatePicker component, validation is triggered immediately. Is there a way to trigger validation on blur instead of onChange when using @material-ui/pickers with material-ui v4 Passing the value to the blur function should work a ...

Is there a way to enhance the functional purity by creating a single function that subscribes and returns a

I'm currently developing a project that involves receiving humidity data from a raspberry pi sensor connected to a backend. Within my Angular Component, I am aiming to display this data in a functional and pure manner. However, I have some doubts rega ...

enhanced labeling for checkboxes in Vuetify

Below is a snippet of my straightforward code: <v-checkbox v-model="rodo" label="I consent to Terms and Conditions (click for more info)" :rules="termsRules" required ></v-checkbox> I am looking to keep the label simple with an option ...

Struggling with implementing a fade effect in JQuery. Any suggestions or solutions?

My task is to create a fading effect that repeats on a webpage until the 'reset' button is pressed. No further information is needed on that. On the webpage, there is a paragraph element with the id 'fail' that is initially completely ...

Tips for shutting down an open section within a jQuery Accordion?

I am having trouble closing the active panel using jQuery. The rest of my code is functioning perfectly, but for some reason, I can't get the active panel to close. Currently, the code is working correctly in that only one panel can be open at a time ...

I am attempting to utilize the fetch API method to initialize the store's state, but for some reason, it is not functioning properly

Within my store.js file, I have a state called user_data, with its initial method set to fetch_user_data: export default new Vuex.Store({ state: { user_data: util.fetch_user_data('username') ... } located in the util.js file: util. ...

Tips for formatting a lengthy SQL query in a Node.js application

Currently, I am facing a challenge with a massive MySQL select query in my node.js application. This query spans over 100 lines and utilizes backticks ` for its fields, making me uncertain if ES6's multi-line string feature can be used. Are there any ...