Unable to get 'margin: 0 auto' to function properly on mobile devices

We recently created a website at but are facing issues with mobile device compatibility and centering the content using margin: 0 auto along with a specified width.

The problem can be seen here: for "topuctovnici.sk"

We have set .core to 1240px in width, followed by a div with 1000px width and margin: 0 auto, but this alignment is not working on mobile devices.

If you have any insights or suggestions, we would greatly appreciate your help. Thank you.

Answer №1

My preferred approach is as follows:

#main-wrapper {
   width: 100%;
   max-width: 1000px;
}

By setting the width of #main-wrapper to 100%, it ensures that mobile devices display content fully, while limiting larger screens to a maximum width of 1000px. This setup allows for seamless horizontal centering across various screen sizes.

Answer №2

Consider using max-width rather than width for your fixed dimensions.

Answer №3

It's hard to pinpoint where the issue is occurring with the CSS and HTML markup, but you could attempt the following solution:

Try setting your div to have a width of 1000px as an inline-block element.

<div style="width: 1000px!important; display: inline-block;">

Additionally, within your parent container .core, make sure to set the text-align property to center.

.core {
    width: 1240px;
    margin: 0 auto;
    text-align: center;
}

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

designing a button layout with bootstrap framework

I am attempting to position a "Redigera" button after the "Avsluta" button <div class="row"> <div class="col-md-4"> </div> <div class="col-md-4"></div> <div class="col-md-4"> <button class=" ...

The class "col-md-*" is not functioning properly when used with an Infragistics grid

I am working with a simple HTML table and an Infragistics (igx) grid to display data: <div class="container"> <div class="row"> <div class="col-md-4"> <table> </table> </div> < ...

Differences in color rendering between XAML WPF and HTML

After migrating my app from WPF to HTML, CSS, and JavaScript, I noticed a discrepancy in color representation. Despite using the same hex value, the HTML color appears lighter than in WPF. See the comparison image here: https://i.sstatic.net/vB7rR.png In ...

Having trouble getting JavaScript validation to function properly

I'm struggling to make validation work properly when hitting the submit button. No alert messages appear, even though I should be receiving alerts for empty fields. Can someone identify what is wrong with my code? I have tried checking the validation ...

Adjust the background color and transparency of a specific section using HTML

Is there a way to modify the background color or opacity of a specific area within an image? Take a look at my HTML, JavaScript, and CSS: function changeColor() { document.getElementById('testid').setAttribute("class", "style1"); } ...

How to layer a div on top of another using CSS

I have a container div that is styled with CSS properties. When a button is clicked, I need to display a modal overlay with a message. <div class="dvLanding"> <div class="popupArea"> <span class="VoteOnce">You can only vote ...

Transform the CSS to a Mat-Form-Field containing a search box within it

I am currently working with Angular, Angular Material, and SCSS for my project. Here is the front-end code snippet that I am using: <mat-form-field class="custom-form-field" style="padding-top: 5px;padding-bottom: 0px; line-height: 0px; ...

How can I target specific HTML comments using XPath?

I need to extract specific nodes from a large HTML page by using Xpath: <html> ........ <!-- begin content --> <div>some text</div> <div><p>Some more elements</p></div> <!-- end content --> ....... ...

The concept of CSS inheritance within div elements

I've been researching extensively about the concept of CSS inheritance, but I have come across a puzzling question that remains unanswered. Consider the code snippet below: <!DOCTYPE HTML> <html> <head> <style type="text/css"> ...

I need some assistance, please. Can someone explain why the Bootstrap card is staying aligned to the left in mobile view

I've tried everything, but it's still not working. Can anyone help me out? Here are some photos. BEFORE AFTER When I view the card on mobile, I want it to stay centered. Could there be some missing code that I'm overlooking? I would great ...

Progressive zoom effect applied to an image in a JavaScript slideshow

Can someone assist me in replicating the zooming effect demonstrated in this code snippet: `http://codepen.io/docode/pen/EjyVQY`. I am specifically focusing on the zooming feature of this slideshow. How can I replicate this zooming effect in JS rather t ...

Angular has the capability to rewrite URLs in CSS, providing a unique way

An issue arises in Angular when using a base set and html5mode with SVGs. This causes things like filter: url(#url) to be rewritten as filter: url(/base/#url). https://github.com/angular/angular.js/issues/8934 Disabling html5 mode and removing the base d ...

node js returning undefined value

I'm currently working on configuring my node.js to retrieve and display the value submitted through an HTML form. Here's a snippet of the node.js file: const app = express(); var path = require('path'); var fs = require('fs' ...

"Utilizing the ng-class directive in AngularJS to apply multiple

I have been attempting to utilize the ng-class directive in AngularJS based on a certain condition: if a JSON value is 1, it should display as green; if it's 2, red; and if it's 0, white. However, I am unable to achieve the desired result for som ...

What is the best way to ensure that the item beneath two images is always centered in HTML5?

When designing a webpage with text and images, it's important to consider the layout on different screen sizes. To avoid text wrapping under images, adjusting the spacing around the image is sometimes necessary. Similarly, when embedding a video, cen ...

Sending data from an HTML table hyperlink to a SQL query on a subsequent page

I am in need of assistance with passing a value from a database. I have successfully achieved this using drop-down boxes, selecting the option and then posting it with a submit button to populate tables in Display.php. However, my current task involves an ...

I am seeking advice on how to incorporate JavaScript to adjust slider values and add numerical values or prices. Any suggestions would

Seeking assistance with a unique project: I am currently developing a calculator that allows users to utilize sliders to select the best option for themselves across various categories. My experience with JavaScript is limited, so I decided to reach out h ...

The event is being triggered on two separate occasions

Hey there! I'm trying to bind the onclick event to both a parent and child element using the same method. However, I'm running into an issue where the event is being fired twice. Any suggestions on how to prevent this from happening? <div id= ...

Select either one checkbox out of two available options

My form includes two checkboxes, allowing users to click on both of them. I'm wondering if it's possible to set it up so that only one checkbox can be selected at a time. For example, clicking on the first checkbox would turn it on while turning ...

Tips for saving a PHP variable in an HTML attribute

I am working on a page that allows users to select colors from a list using checkboxes. When the user submits their selections, I want all the chosen colors to be displayed with their corresponding color as their font color. Below is the code I have so fa ...