Image failing to align properly within div container

When attempting to align an image in the middle vertically inside a DIV on my website, it does not work properly. This issue does not occur when I do it on jsFiddle. It appears there may be a CSS conflict that I am unable to identify.

I have applied the same CSS as in the working jsFiddle example, but on the actual website, the logo always aligns to the top position.

I would greatly appreciate any assistance with this matter.

Possible Solution:

<script type="text/javascript">
    $(document).ready(function () {
        var h = $("#BannerSlider").height();
        $.map($("#BannerSlider img"), function (e) {
            var top = (h - $(e).height()) / 2;
            $(e).css("margin-top", top);
        });
    });
</script> 
    <title></title>
    <style>
.SponsorLogos
{
    width:600px;
    margin-top:50px;
    margin-left:60px;
    min-height:550px;
    background:red;
}
.SponsorLogoWrapper
{
    width:160px;
    height:160px;
    margin-right:30px;
    margin-bottom:30px;
    border:1px solid #78AC1B;
    line-height:160px;
    text-align:center;
    overflow:hidden;
    float:left;

}
.SponsorLogoWrapper img
{
    display: inline-block;
    border:0px;
}

    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <div class="SponsorLogos">

          <div id="BannerSlider" class="SponsorLogoWrapper" >
               <img src="http://www.nikolakis.net/liquidcarousel/images/01.jpg" width="88" height="126" alt="image"/>
               </div>
         <div id="BannerSlider" class="SponsorLogoWrapper" >
                <img src="http://www.nikolakis.net/liquidcarousel/images/02.jpg" width="88" height="110" alt="image" />
                 </div>
        <div id="BannerSlider" class="SponsorLogoWrapper" >
                <img src="http://www.nikolakis.net/liquidcarousel/images/03.jpg" width="88" height="100" alt="image"/>
                       </div>
         <div id="BannerSlider" class="SponsorLogoWrapper" >
                <img src="http://www.nikolakis.net/liquidcarousel/images/04.jpg" width="88" height="126" alt="image"/>
                       </div>
        <div id="BannerSlider" class="SponsorLogoWrapper" >
                <img src="http://www.nikolakis.net/liquidcarousel/images/05.jpg" width="88" height="90" alt="image"/>
           </div>
</div>

    </div>
    </form>

Answer №1

If you adjust the jsFiddle DOCTYPE to match your website's, the images will align correctly at the top once again (located in the info panel on the left).

You may find this answer helpful: Vertical-align not working with XHTML 1.0 Transitional doctype?

In response to the first comment:

The easiest solution would be to change the DOCTYPE. If that is not an option, then alternative methods must be explored. Vertical alignment is most effective with tables, so changing the display properties to a table-based format could be beneficial. Take a look at this example: http://jsfiddle.net/64UnS/1/

Implementing this may vary depending on browser support. It seems you are already using display: inline-block; and there is no IE7 fallback, so this approach might work for you.

Other options to consider include:

  • Adjusting your images to be 160 x 160px
  • Modifying the markup so that each image is displayed as a background-image inline within the <a /> tag. This allows for easier centering, but be mindful of image dimensions since background-size support is limited
  • Exploring a javascript solution (jQuery is already included in the <head />)

I hope these suggestions prove helpful!

Answer №2

It seems that the discrepancy in rendering may be attributed to the fact that the website is coded with the XHTML transitional doctype while JS Fiddle operates on the HTML5 (html) doctype.

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

Assistance needed in restructuring code to eliminate white space between Divs

I am looking to combine two divs in the header section of my website. Both divs should have a black background with no white space between them. Can anyone provide advice on this? Additionally, I would appreciate any recommendations on how to structure my ...

How to Get Rid of the Padding on an HTML Dropdown List

How do I eliminate the padding on the top/left side of a select menu? https://i.sstatic.net/N1mS2.png I attempted to set the padding and margin to 0 but it did not make any difference. Below is the HTML code: <form class="timePeriodMenu"> < ...

Incorporate a particular video directly into HTML code

I'm having trouble embedding a video into my html web page. The video I want to use is located at . I tried using the following code snippet based on the source code of another page where the video is currently embedded: <embed height="100%" width ...

What is the best way to organize controls on my website?

My web page controls need to be organized in the specific layout below: Header Left Content - Main Content - Right Content Footer Is there a control available that can assist me with achieving this layout? I prefer not to use a table since it may not b ...

I've found that my div element refuses to be centered on the screen unless I explicitly define

Trying to center a div on the page using jQuery has proven to be a bit tricky. It seems that without specifying a height for the div in the CSS, the centering doesn't work as expected. The challenge lies in the fact that the div is meant to resize bas ...

Issues with 'floating' unordered lists

.menu li { float: left; color: #fff; font-weight: bold; } .menu li a { display: block; height: 20px; min-width: 110px; text-decoration: none; border-radius: 3px; padding: 4px; padding-left: 6px; padding-right: 6p ...

Bootstrap Dropdown Functionality Malfunctioning

Here is a simple piece of HTML code that I have created: <!doctype html> <html> <head> <meta charset="utf-8"> <title>.:Home Page:. The Indian Sentinel</title> <link rel="stylesheet" href=" ...

Align checkboxes horizontally to resemble a progress bar styling

Currently, I have a series of checkboxes that are displayed sequentially on the page. <div class="myCheck"> <h5>Here's what you've selected so far</h5> <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect ...

Dropdown menu with multiple selection options

Is there a way to create a combobox that allows for multiple selections using either Javascript or HTML? While a typical combobox/dropdown structure does not support selecting multiple items, how can this functionality be achieved? ...

Is the HTML templating mechanism compatible with Angular?

Trying to implement HTML templating in my Angular application, my code looks like the following: <script type='text/html' id="sampleId">...</script> However, upon loading the HTML, I noticed that the script block was not present in ...

Swapping images when hovering over a list item or anchor tag

I recently came across an intriguing issue with changing the img src on a:hover. Check out this SCREENSHOT When hovering over the <a> sector, it's not showing the white image as expected. I have black and white icons, and I want the img src to ...

Analyzing an HTML document

My current challenge involves extracting the username from an HTML Page based on who is accessing it. The username is displayed on the page, but its location may vary depending on the user. I'm curious to hear how others would approach this issue. My ...

What is the best method for automating the transfer of data from a database to the user interface of a website using html and javascript?

As a volunteer coordinator for a non-profit organization, I have some basic experience working with Python. I am willing to dedicate fewer than 8 hours of learning time to my current project in order to automate certain tasks (or else I will do them manual ...

Implementing AngularJS drag and drop functionality in a custom directive

I am in search of an example that demonstrates similar functionality to the HTML5 File API using Angular-js. While researching directives for Angular 1.0.4, I found outdated examples that heavily rely on DOM manipulation. Here is a snippet of the pure Ja ...

Avoid the simplified view prompt when using Chrome or utilize the simplified view feature without any interruptions

When I access my website from Chrome on Android, I am prompted to "Show Simplified View" at the bottom of the screen. Clicking this prompt results in only one news item being displayed instead of the intended 25, controls removed, and scrolling disabled. O ...

fa-arrow-circle-o-down and fa-arrow-circle-down

Is it possible to modify the fa-arrow-circle-o-down icon to have the same arrow type as the fa-arrow-circle-down icon? The current arrows on these two icons are different and I want them to be consistent. ...

Tips on activating the CSS style while typing using the onChange event in React

Is it possible to dynamically adjust the width of an input as we type in React? Currently, my input has a default width of 1ch. I would like it to increase or decrease based on the number of characters entered, so that the percentage sign stays at the end ...

Strange Behavior of SVG 'fill: url(#....)' in Firefox

I am struggling with an SVG graphic that I have created. Here is the code: <svg width='36' height='30'> <defs> <linearGradient id="normal-gradient" x1="0%" y1="0%" x2="0%" y2="100%"> <stop offset="0%" s ...

Resolve the issue of text overflow in PrimeNG Turbo Table cells

When utilizing Primeng table and enabling the scrollable feature, the table is expected to display a scrollbar while ensuring that the text within the cells does not overflow. Unfortunately, this expected behavior is not occurring. To see an example of th ...

Fuzzy division following a CSS transformation/animation

I have been working on a content slider, using the guidelines from this demonstration However, I have encountered an issue where my content, which consists of a few divs, appears slightly blurry after the CSS transition completes. This problem only seems ...