Show the main image in the middle of the screen

In my rails3 application, I have user profiles that include 4 profile images of various sizes along with a slideshow feature. Additionally, there is one background image named xx.gif.

If the size of a profile image is less than 640*480 pixels, I want to display the background image (xx.gif) in the background and the smaller profile image in the foreground. The smaller profile image should be centered corresponding to the background image.

Does anyone know how to achieve this?

Answer №1

Give this a shot:

HTML

<div id="container">
  <img id="pic1" alt="example" src="/pictures/pic.png" class="middle">
</div>

CSS

#container {
    background: url("/images/background.jpg") 50% 50% no-repeat; 
    border:2px solid #ddd; 
    width:600px; 
    height:450px;
    display: table-cell; 
    vertical-align: center;
    text-align:center;
}

Check it out here

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

I've noticed that my Bootstrap navbar is currently white, but I have a desire to switch it to a

I'm having trouble changing the transparency of my Navbar. I want it to match the color of my banner image underneath, but no matter what I try with !important, it stays white. Can anyone help me remove the background color from my Navbar? My Navbar ...

Decoding JSON data from serialized form in Symfony2

When I submit my form using ajax, this is what I receive in the controller: $request->getContent() The result is: string 'comment[header]=vcvdfgdfg&comment[body]=dfgfdgdf&comment[_token]=nV0QYu82KWFb-wRIlIoY4MKM6-WUfeFoMidjBHfpupA' ...

Need to wait for current thread execution in jQuery for synchronous AJAX call

Utilizing jquery ajax for a save operation: $.ajax({ type: "POST", url: "/service/save.php", data: dataString, cache: false, async: true, // Avoid using 'false' as it is deprecated success: function(result){ var split = result.s ...

Simple solution for storing key-value pairs temporarily in a form using JQuery

Is there an elegant method to temporarily store an array of string values in a form? In my article editing form, users can add tags as string values. I don't want these tags to be persisted until the user saves the entire article, so I require a way ...

alteration of colors in a Chartist chart

Currently, I am working with a chartist graph where the colors are defined at a framework level. However, I need to make changes to the colors for a specific graph without altering the framework level settings. I attempted to create a .less file, but unfor ...

Execute a jQuery script within an iframe on a webpage by triggering it with an onclick event from a

I have a homepage with two iframes. One of the iframes contains links: <a href="home.html" target="content" onclick="run.slimmscroll(#anchor1);">Home</a> <a href="home.html" target="content" onclick="run.slimmscroll(#anchor2);">Home</ ...

Prevent duplicate email submissions to the database by utilizing the jQuery validation plugin with AJAX

Hello everyone, I am currently utilizing the jquery validation plugin and it is functioning properly. However, I am encountering an issue where if an email already exists in the database, the form should not be submitted until a different valid email is ch ...

The inputs are not responding to the margin-left: auto and margin-right: auto properties as expected

I'm having trouble aligning an input in a form to the center. Even though I have included display: block in the CSS, using margin-left:auto and margin-right: auto is not yielding the desired result. To illustrate the issue more clearly, I've cre ...

Ways to display additional selected values in a select menu

I have a basic form on my website that includes options like: Select 1 and Select 2. I would like to set it up so that if I select value Home in Select 1, the value in Select 2 changes to something like residence. How can I achieve this using a database? ...

What could be causing the issue with this API call using $.ajax and $.post?

<!DOCTYPE html> <html> <head> <script src="js/jquery-3.2.1.js"></script> <script lang="javascript">$.ready(function () { $.post("https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=BTC,USD,EUR,GBP", function( ...

Incorporating live text into a tag while arranging items by price in both ascending and descending order

I recently added a button to my online shop that allows users to sort products by price, even though I don't fully understand the underlying JavaScript code. I want to enhance this button by updating the text to indicate whether the sorting order is ...

After a mere 10 seconds, the cookie is still fresh and ready to indulge in

I recently created a cookie with the intention of having it expire after 10 seconds. Unfortunately, it seems to be persisting even after closing the browser. Below is the code I used to create the cookie. setcookie('attempt','', time( ...

What is the best way to create a clickable anchor tag that is nested within a paragraph tag?

Here is the string I am working with: String txtLink = "<p>Apply directly in our <a href=\"https://theorem.applytojob.com/apply/TyJy6YCsOs/Experienced- Backend-Engineer-Ruby?source=GitHub+Jobs\">careers page</a></p>"; ...

Stretch the div to the right and maintain its horizontal width

I am in the process of coding a two-column layout, with a total width of 980px. Each column will have a background that expands all the way to the left and right sides as shown in the screenshot here. On the left side, there is a blue div with a width of ...

Using jQuery to dynamically update the CSS of one table column depending on the attribute of another column

Welcome to my HTML table <!DOCTYPE html> <html> <body> <table> <thead> <th>Title1</th> <th>Title2</th> </thead> <tbody> <tr> <td><input type="checkbox" id=0 /></td> ...

Tips on showcasing specific test names from an Nunit result XML file within the HTML report generated by Nunit Results.exe

After running my tests using nunit-console, I obtained the result.xml file. Next, I utilized nunit-results.exe to create an HTML report. Unfortunately, the report does not display any of the unit test method names. Is there a feature within nunit-results ...

What is the best way to trigger an ajax request when a user selects a tab?

How can I trigger an ajax call when a tab is clicked by the user? What is the best way to handle the HTML response and display it within the tab? How do I bind JavaScript events to the dynamically loaded HTML content? I am familiar with using jQueryUI tab ...

What is the best way to prevent an HTML table from having columns that adjust their width dynamically based on the content in the <td>?

Is there a way to create a table with equal column sizes that do not change based on the length of the data within the table? https://i.sstatic.net/Gyt4P.png In the image provided, the data under the heading "Title" seems to shift the second column to th ...

The image I want to show is invisible on the CSS custom radio button

I'm having trouble creating a custom radio button that displays the image I want. The current setup doesn't seem to be working as expected. label { font-weight: lighter; cursor:pointer; } input[type="radio"] { display:none; } in ...

VS Code warning about unused CSS selectors in SvelteKit

Is there a way to get rid of the Unused CSS selector warning in VS Code? I keep getting this warning in all files where I use <style lang="scss">. While I'm aware that I don't use the .btn class in some components, I still want it ...