Position a centered responsive image above the table with a horizontal line crossing underneath

#logo-center {
    max-width: 100%;
    height: auto;
    display: flex;
}

@media only screen and (min-width:991px) {
    .logo-div {
        -webkit-margin-start: -5%;
        -webkit-margin-end: -15%;
        -webkit-margin-before: -6%;
        left: 40%;
        top: 40%;
        right: 40%;
        position: absolute;
        z-index: 100;
        display: flex;
    }
}

@media only screen and (max-width:990px) {
    .logo-div {
        -webkit-margin-start: -5%;
        -webkit-margin-end: -15%;
        -webkit-margin-before: -6%;
        left: 40%;
        top: 42%;
        right: 42%;
        position: absolute;
        z-index: 100;
    }
}

@media only screen and (max-width:700px) {
    .logo-div {
        left: 38%;
        top: 43%;
        right: 40%;
        position: absolute;
        z-index: 100;
    }
}

@media only screen and (max-width:500px) {
    .logo-div {
        left: 35%;
        top: 42%;
        right: 40%;
        position: absolute;
        z-index: 100;
    }
}
<div class="logo-div">
            <div id="logo-center"><img style="border-radius: 7%;" src="https://www.crockerriverside.org/sites/main/files/main-images/camera_lense_0.jpeg"></div>
        </div>

https://jsfiddle.net/8rmL5a7f/ I want to adjust the size of an image in the center to make it responsive across different browsers. The goal is to have the image cover the intersection point of table borders on a webpage. My code currently functions correctly in Firefox, but encounters issues in Chrome and IE. Seeking assistance to troubleshoot the cross-browser compatibility problem.

Answer №1

If you have a large image and do not specify the width, it may overflow the containing div.

Here is how you can fix it:

#logo-center img {
   width: 100%;
   height: auto;
}

The height:auto property will maintain the aspect ratio of the image.

Before on Chrome (Windows):

https://i.sstatic.net/DrVVO.jpg

After on Chrome (Windows):

https://i.sstatic.net/bSLuj.jpg


To center the image in the div:

You need to ensure that both .table-responsive.bordered.fill and .logo-div have the same width and height, and then use the following CSS:

#container {
  position: relative;
}
#container .logo-div {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

Make sure to remove the right property from .logo-div.

This code snippet uses the transform: translate method to perfectly center the image taking into account the size of the child element (.logo-div) rather than just aligning based on the parent (#container).

Note: There are other ways to achieve this using negative margins or flexbox, but the solution with translate is a common approach I prefer.

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

How to center text both horizontally and vertically in HTML

I am struggling with centering a background image along with a 1-line text vertically and horizontally inside a div. Although I have successfully centered the image, the text remains misaligned. I attempted using vertical-align: middle without success. Be ...

Utilizing Wordpress post images to dynamically change background URLs in CSS

Is there a way to dynamically set a background image in CSS using PHP, specifically the Wordpress post image? background: <?php if(has_post_thumbnail()){ $img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'dest ...

"Utilizing Bootstrap to add borders to div elements is a

https://i.sstatic.net/yPt46.png Hey there! I am working on a project using bootstrap 4. I encountered an issue that I can't seem to solve. I placed an image inside a div, set the div's height and width to 200px with overflow hidden. The image w ...

Removing the animation from a Material-UI Select component in React

Currently, I am utilizing the React Material UI's Select Component and I am looking to either remove or quicken the animation that occurs when opening the menu. I attempted the following approach: <Select ... TransitionComponent={({child ...

Transforming data from PHP JSON format into HTML output

Struggling to convert JSON data into HTML format? Having trouble maintaining the correct order of child elements in your structure? Here's a solution: Take a look at this example JSON: { "tag": "html", "children": [ { "ta ...

Can a font size be adjusted dynamically based on the width of its containing class?

I have encountered this issue before, but the previous solution did not work for me. I am now seeking a viable alternative. Currently, I am developing a website and have an event announcement block that needs to display the event date spanning the entire ...

Alter the drag direction of the dragulaInput boxes

Yesterday, I had a question about changing the size and color of the badge and text in dragulaInput. Now, I'm wondering how to change the boxes vertically on the right side and left side. I came across <div style="display: grid; grid-column-g ...

Modify the surrounding container of the chosen selector

I have a complex website with multiple containers. My objective is to apply a color to a container with the class "colorme" when another container, located far away from it, has the class "active". Here is how the code is structured: .tooltip:has(tool ...

Tips for expanding the contentedible HTML element downwards within its container

When a user inputs content, I need the paragraph to expand only downward while the div with the ID of description also grows in the same direction. The main parent div labeled documentation should remain fixed so it doesn't expand upwards. This scenar ...

Unable to render JSON data using AJAX

I have a JSON file filled with various data and I'm trying to use AJAX to display it. Despite my efforts, I couldn't get it to work and after extensive research online, I decided to reach out for your assistance: $(document).ready(function ...

Creating a JQuery statement to conditionally change CSS values

Is there a way to determine if a div element with a CSS class of "x" has a height set to "auto"? If so, I would like a jQuery script to remove the CSS class "a" from all elements with the class "y". If not, the script can remain unchanged. Thank you. ...

What methods are available to display Excel files in a web browser without any cost? (Specifically looking for solutions involving JavaScript and Python within a Django

When you click on the file, it automatically downloads. However, I would prefer it to open in a new tab, similar to how SharePoint works. Unfortunately, I cannot use SharePoint due to security concerns, as it would require access to all company files. htt ...

Implement a CSS class specifically for products with low stock within the single product page on WooCommerce

I need some assistance with adding a class to 'Low stock' in the code snippet below, as I am not very familiar with php. My goal is to style the Low Stock text in WooCommerce to appear orange using CSS. function change_stock_text( $availability ...

Differences in row padding when transitioning from Bootstrap 3 to Bootstrap 4

One thing I've noticed is that when utilizing Bootstrap 3, the use of div.row would automatically create a vertical spacing between rows which was quite appealing. However, upon transitioning to Bootstrap 4, this automatic spacing seemed to disappear. ...

Can the styling and variables of Bootstrap4 be altered dynamically?

I have recently started working on a project that utilizes Bootstrap4 for design and layout. However, there is now a need for the ability to change certain core styles (such as font-face, primary color, and background color) dynamically at runtime. Curren ...

Issue with JQuery click() not triggering on a specific div button

I am attempting to replicate a user's click on a website where I have no control over the code. The specific element I am trying to interact with is a div that functions as a button. <div role="button" class="c-T-S a-b a-b-B a-b-Ma oU v2" aria-dis ...

Why does this CSS ticker only display the first four posts?

Hello, I'm interested in adding a News Ticker to my Rails application. I came across this CSS ticker: I'm facing an issue where it only displays the first four posts. I believe the problem might not be with my data retrieval using the .each loop ...

"Font-face is effective in Internet Explorer but appears to have compatibility issues in Firefox particularly regarding font formats

I have downloaded a free font that comes in regular and bold variations, with the following formats: svg, eot, ttf, woff. These fonts display properly in Internet Explorer, but they are not working in Firefox. 1. I would like to understand which format is ...

Guide to activating the 'Next' button on WP Forms using JavaScript code when certain conditions are fulfilled

Is there a way to adjust the JavaScript code provided so that the visibility of the "Next" button is dependent on whether at least one item in the 'wpforms-icon-choices-item' class has the '.wpform-selected' class on the current page or ...

Tips for concealing scrollbars across various browsers without compromising functionality

Is there a way to hide the scrollbar functionality on a horizontal scrollbar without using "overflow: hidden"? I need to maintain JS functionality and ensure compatibility with all modern browsers. $j = jQuery.noConflict(); var $panels = $j('#primar ...