Guide on aligning an image in the middle of a column element

Struggling to center an image using CSS within the same .php file as the code

<style type="text/css">

div.item {
    height: 300px;
    width: 300px;
    display: table-cell;
margin-left: auto;
    margin-right: auto;
text-align: center;
}
.item img {
    display:block;
    margin-left: auto;
    margin-right: auto;
text-align: center;
}
<div id="main-page">
    <div class="row">
        <div id="full-sec" class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div id="giveaway" class="body-sec">
                <h2 class="main-title">UPCOMING GIVEAWAY</h2>
<centre>
<h4 class="sub-title"><?php echo $giveaway_title; ?></h4>
</centre>
</div>

</div>
</div>
</div>
<div id="main-page">
    <div class="row">
        <div id="full-sec" class="col-xs-12 col-xs-12 col-xs-12 col-xs-12">
<div class="item">
    <img src="http://community.edgecast.steamstatic.com/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpot7HxfDhjxszJemkV08u_mpSOhcjnI7TDglRc7cF4n-T--Y3nj1H6-hBrMW_3LIOWdlU_MlGDqwO6wrvq15C6vp-bnHY36SAm4XbYl0SwhgYMMLJqUag1Og/360fx360f" />
</div>
</div>
</div>
</div>

Check out the live version here:

Any assistance would be greatly appreciated.

Answer №1

Make sure to apply the margin auto to the parent element containing the image, not directly to the image itself.

div.product {
    height: 300px;
    width: 300px;
    margin: 0 auto;
    text-align: center;
}
.product img {
    width: 100%;
}

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

Difficulty Aligning Header Elements - Combining Navigation and Logo on the Same Line

I am currently facing an issue with positioning a logo and navigation links within a <header> element. When I apply the CSS property text-align:center;, the logo aligns to the center on one line while the navigation links appear on another line direc ...

The screen reader is unable to interpret the text that is visible within the anchor tag

I have an Angular application with a dropdown menu implemented as shown below. When using the NVDA screen reader to navigate, only the content inside the aria-label attribute is being read when tab focused. However, I want it to also read the content (&ap ...

Ways to duplicate a letter in HTML?

How can a character be printed repeatedly within a table cell using only HTML or HTML and CSS (excluding HTML5)? *(limiting to only HTML or a combination of HTML and CSS) ** The goal is to print the character "." across the entire length of the cell, wit ...

When trying to iterate through a list, I am unable to access a property using `<html:checkbox property="...">`

Within my Struts form, there lies a list. Within the JSP file, I am iterating through it in the following manner: <c:forEach items="${MyForm.types}" var="type"> <tr> <td>${type.name}</td> <td>${type.forced ...

Leveraging Bootstrap cards to create clickable links

I am working with a bootstrap card that serves as a link. When I attempt to enclose it with an <a>, the styling of the card gets completely altered. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min ...

Innovative Double Navigation Menu Dropdown Utilizing Bootstrap 4.5

Need Help with Bootstrap 4.5 Double Navigation Menu Dropdown I'm facing an issue with the 'Reports' submenu not working properly. Any advice would be appreciated. Check out the template here <div class="nav-scroller bg-white shadow- ...

The specified variable is not present within the for loop

This script dynamically generates table rows for each client, populating each row with specific values such as name, IP address, operating system, country, and time. These values are stored in an object or dictionary named clientel. The setup of the progr ...

What is the best way to eliminate concealed divs from the view source of a webpage?

On my HTML page, I have some hidden DIVs that can still be viewed in the page source. I want to ensure that these DIVs are not visible to users when they inspect the page source. Is there a way to achieve this using Javascript or another solution? ...

Utilizing Python's urllib and urllib2 to automatically populate web forms

My goal is to automatically submit an HTML form using both urllib2 and urllib. import urllib import urllib2 url = 'site.com/registration.php' values = {'password' : 'password', 'username': 'username& ...

The text does not change in the input field even with the .value method

I'm encountering an issue where I want to use .value to set the text of an input field. However, after setting the value of the input field, the text disappears when clicked on. I would like to find a solution where the text does not disappear upon cl ...

Utilizing either Maps or Objects in Typescript

I'm in the process of developing a simple Pizza Ordering App. The concept is, you select a pizza from a list and it's added to a summary that groups all the selections together. Here's how I want it to appear: Pizza Margarita 2x Pizza Sala ...

Video background is malfunctioning on Firefox and Internet Explorer

Currently, I am facing some issues with the JQuery plugin 'videoBG'. The problem is that when I view the video offline, it works perfectly in all browsers. However, once I go online, the video stops working in FireFox and IE. It seems like the sc ...

What is the best method for web scraping from the NVIDIA website using Python?

My current setup involves the utilization of BeautifulSoup4 and requests for web scraping. from bs4 import BeautifulSoup import requests url_NVIDIAGEFORCE = f'https://shop.nvidia.com/de-de/geforce/store/gpu/?page=1&limit=9&locale=de-de&ca ...

Trouble accessing Angular page after resource call was made

Seeking assistance with creating a Dispatchsystem for the local taxi company using Angular. While not an expert in Angular and its functionalities, I encountered an issue after setting up angular-route to inject html pages into the main html document and e ...

Retrieve the background color using code-behind

Despite its humorous appearance, I am having trouble with the Syntax :( I have a background color in my code behind file and need to correct the syntax here so that my Table displays the correct background color: <Table style="background-color:" &apos ...

Troubleshooting Firefox HTML Positioning Problem (Functioning Properly in IE and Chrome)

After implementing the code below, I encountered an issue. In IE and Chrome, when hovering over the "CODE" section, the div correctly appears at position 100 x 100. However, in Firefox, the div fails to move to the specified position. What changes should b ...

How can I showcase an image from the search results using the Giphy API?

Find the GitHub link to the Giphy API here: https://github.com/Giphy/GiphyAPI. As a newcomer, I'm facing a roadblock. Currently, I am receiving random gifs from the Giphy API instead of the specific search result requested by the user. Is there a wa ...

How can I trigger a function in code.gs to execute a script in an html file when a dialog is opened?

Within my Index.html file, I have a script tag that allows me to execute the code below when I launch the Modal Dialog on Google Sheets using google.run. --Index.html-- <script> function onSuccess(info) { ...add options to select tags... } functio ...

Using PHP to utilize logical OR or AND operators when adding a class to the global navigation's list items

I am currently working on implementing a global navigation bar using PHP on all pages. The PHP code is also being used to add a class and display the current page. The main challenge I am encountering involves selecting the parent navigation item. When on ...

The header is visible above the navigation bar when scrolling on mobile, but it should be hidden

I am facing an issue with fixed content on mobile positioned above a Bootstrap navbar. The problem arises when scrolling down, causing the navbar to move up by 50px (the height of the content above the navbar). Everything seems to work fine initially, but ...