The CSS background seems to be malfunctioning in Chrome

Could you please explain why this HTML and CSS code works on FF, IE9, jsfiddle, but not on the live site using Google Chrome?

HTML:

<p>
    <a href="http://tambnguyen.com/wp-content/uploads/2012/05/256501557_1280.jpg">
        <span class="img_wrapper">
            <img class="tn" src="http://tambnguyen.com/wp-content/uploads/2012/05/256501557_1280-580x326.jpg"/>
        </span>
    </a>
</p>

CSS:

img.with-borders, img.tn { 
    margin: 5px 0 0 0;
    padding: 8px;
    background: #f1f1f1;
    border: solid #777;
    border-width: 1px 2px 2px 1px;
    box-shadow: 0 15px 15px -15px rgba(0, 0, 0, 0.9);
    -webkit-transition: all 0.3s ease; -moz-transition: all 0.3s ease; -o-transition: all 0.3s ease;
    transition: all 0.3s ease;
}
span.img_wrapper {
    background: url('http://tambnguyen.com/wp-content/themes/Polished/images/et-image-sliderleft-shadow2.png') no-repeat left bottom, url('http://tambnguyen.com/wp-content/themes/Polished/images/et-image-sliderright-shadow2.png') no-repeat right bottom;
    padding-bottom: 14px;
}
img.with-borders:hover, img.tn:hover, img.post_img:hover, div.related_post_thumb:hover  { 
    border-color: #000;
    filter: alpha(opacity=80);
    opacity: 0.80;
}

The jsfiddle link is available here http://jsfiddle.net/gNtea/, and the live site can be accessed at

Thank you!​

Answer №1

To achieve the desired layout, make sure to include display: inline-block; in the CSS for the img_wrapper element, as shown below:

span.img_wrapper {
  display: inline-block;
  background: url('https://example.com/image-left.png') no-repeat left bottom, url('https://example.com/image-right.png') no-repeat right bottom;
  padding-bottom: 10px;
}

Answer №2

Upon reviewing both the jsFiddle link and the live website in Chrome, I noticed that the current use of the display:inline-block; property is causing a visible gap between the background shadow images and the Social Buttons.

The issue arises due to the use of inline-block. To address this, I recommend refraining from using display:inline-block; and instead defining specific padding values for top, right, bottom, and left.

In addition, given that objects are floated on your live webpage, assigning a value of 1px to padding-right can help resolve the spacing problem.

You have two possible methods to choose from:

Method 1 - Shorthand padding (top, right, bottom, left):
padding: 0 1px 18px 0;
Method 2 - Specifying missing padding-right value:
padding-bottom: 18px;
padding-right: 1px;

Implementing either of these approaches will enable you to display the Poster Image with its background images intact without disrupting the layout of the webpage and eliminating the noticeable gap.

It's crucial to understand why the fix works differently on jsFiddle compared to the live website. The reason lies in the fact that jsFiddle serves as a sandbox environment which may not always replicate real-world scenarios accurately – essentially attributing this discrepancy to a potential bug within jsFiddle.

To demonstrate this behavior, I've included a jsFiddle example showcasing your HTML content directly copied into the platform for comparison.

If you utilize Chrome developer tools (press F12 on the keyboard) to inspect the image element and navigate to the relevant span tag, you can experiment by toggling off the style for display:inline-block;. This exercise reveals a minor pixel adjustment in Chrome when viewing the .png images, emphasizing their continued visibility.

In conclusion, while recognizing the utility of jsFiddle as a valuable testing tool, it's imperative to rely primarily on web browsers such as Chrome – or any chosen browser – to finalize the page design for production purposes, ensuring seamless compatibility across different interfaces.


Reference Photo 1: display:inline-block


Reference Photo 2: padding-right: 1px;

Answer №3

Just remember to adjust the height of the image =)

li.current-menu-item a {
background: url("../images/bg_menu.png") repeat-x;    
height: 35px;
}

Answer №4

Encountering the same issue with Chrome led me to a bizarre solution

In the body wrapper, my original CSS code looked like this

background-image: url(../../img/layout/bgOutside-rtl.jpg);

The image ended up repeating, which was not ideal. Despite trying various solutions found elsewhere, things only seemed to get worse.

To address this, I made the following adjustment

background-image: url(../../img/layout/bgOutside-rtl.jpg);
background-repeat: no-repeat;

Although PHPStorm recommended a different approach

background: url(../../img/layout/bgOutside-rtl.jpg) no-repeat;

This change seemed logical but unfortunately didn't resolve the issue. Instead, Chrome interpreted it as an instruction to not display any image at all.

The only solution that worked for me was reverting back to

background-image: url(../../img/layout/bgOutside-rtl.jpg);
background-repeat: no-repeat;

Interestingly enough, this problem only surfaced when using the Windows version of Chrome, not when coding in Linux...

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

Is there a way to make a table stay at a specific width for screen sizes larger than 1000px, but then adjust its size accordingly as the window size decreases?

<table id="example" class="row-border compact" style="width:1000px; table-layout:fixed;"> The table is currently set to have a width of 1000px, but I would like it to be 90% of the screen width when the window size is less than 1000px. Is it possibl ...

"Trigger a hover effect on one element, but have it impact a

I have a simple question that I couldn't find a direct answer to, so here it is: I have two boxes and I want to hover over the first one but have it affect the second one (meaning when hovering over the first box, the second box should scale up with a ...

Click on the navlink to open the HTML page in the same window

I have developed a navigation bar with a menu that includes options like home, about-us, and more. When I click on the navbar, the nav-menu slides down to display a list of navlinks. However, when I select a navlink, such as about-us, the nav menu slides b ...

Learn how to automatically set the checked state of a radio button by toggling another radio button

I have two sets of radio buttons, each with four options. The first set has no default selection (unchecked) using jQuery, while the second set has the first option checked by default. What I'm looking to achieve is that when a radio button in the f ...

What is the best way to line up inputs and button-styled links in Bootstrap v4?

I have designed a form using the grid system Within one row, I have a styled link that I want to be aligned with the input fields Despite trying various combinations of align-button and align-items-button classes, I have not been able to achieve the desi ...

Uneditable border in Bootstrap table

I am currently utilizing Bootstrap table to showcase some basic information, however, I am facing a peculiar problem. Upon using the bootstrap-table stylesheet, the table displays as desired without an outer border. However, upon initializing the styleshe ...

Require an additional button to dynamically load more content and shift all existing elements further down the page

I am looking to implement a "load more" button for an Instagram feed on my website. My current approach involves increasing the height of a specific section while moving the rest of the page down. This is what I have tried: <script> $(document.ready ...

The absence of the pyramid in the WEB GL canvas is noticeable

I encountered an issue while attempting to generate two shapes on the canvas: an octagon and a pyramid. The octagon displays correctly, but the pyramid does not appear as expected. Below is the code snippet related to the creation of the pyramid: pyramidP ...

What are the possible reasons for my load function failing intermittently?

I have encountered an issue with my app where sometimes the content is not loaded into a dialog. Most of the time it works perfectly, but occasionally it fails to display the content. Here is the code snippet that I am using: $('#popup_background&apo ...

Tips for modifying the size of the <code> tag against a background?

Is there a way to adjust the width of text within a (code) tag so it always fits within the background? I want the text in the (pre) element to resize along with the background as the browser window resizes. Please see the pictures below for reference: I ...

Transform a section of a canvas into a PNG file

I am in the process of converting my html5 canvas into a png format using this code snippet: var canvas = document.getElementById("mycanvas"); var img = canvas.toDataURL("image/png"); document.write('<img src="'+img+'"/>'); I ...

Can the labelDisplayedRows be disabled in the table pagination actions of Material UI?

I am currently working on customizing the table pagination actions in Material UI's table and I need to remove the labelDisplayedRows function. My goal is to only show next/previous icons in the footer without the counter (e.g., 1 of 5). I managed t ...

Executing $(this).parent().remove() triggers a full page reload

A unique feature of my webpage is that with just a simple click of a button, users have the ability to dynamically add an endless number of forms. Each form contains fields for user input and also includes a convenient delete button. var form = " Name ...

Manipulate the content of any webpage without using external extensions by injecting your own HTML, CSS, and JavaScript code

I am currently following a tutorial on how to draw shapes on a local webpage using Canvas. I came across this helpful article on Html5 canvas paint. Everything is going smoothly, but now I am interested in replicating the drawing functions/CSS/HTML and "i ...

What methods can I use to customize the appearance of the acceptance label in a contact form created with

I am currently developing a WordPress website using the Contact Form 7 plugin. However, I am facing an issue with styling the "I accept" button and text when clicking on the "registrace" button. I would like to center them and create some proper margin aro ...

Shift designated list item to the right with overflow handling

A current project involves working on a sidebar created in bootstrap, and I've encountered an issue. I can't seem to move a selected item to the right and have it flow over the nav div. I attempted to increase the z-index with no success. One su ...

Is it a not-so-great idea to use a combination of Bootstrap CSS and Custom CSS for styling

Is it considered bad practice to apply custom CSS on top of standard Bootstrap CSS for a button? Should I completely remove Bootstrap and use only custom CSS? If so, what is the trade-off in terms of performance? Another web developer mentioned that addit ...

Incorrect page height displayed in the embedded Facebook browser on iOS 9.x

When trying to access the demo application from core-layout using the embedded browser within the Facebook app on iOS 9.x, it appears that the footer element is not visible in portrait mode. When the device is rotated to landscape mode, the footer becomes ...

Using jQuery to identify whether the dates displayed in a table are earlier than the current date

I need some assistance with what appears to be a straightforward task. Unfortunately, I lack the expertise required to solve this issue. Essentially, I have a form where I pick a date (for the due date) using jQuery's datepicker. The outcomes are the ...

Vue Labyrinthine Design theme

Looking for some guidance from experienced developers out there! I'm currently exploring how to incorporate Mazeletter as a background feature for each page in an app project I've been working on. This is all new territory for me, so any assista ...