Optimizing CSS for smartphones and tablets

Using the standard CSS for writing content will ensure compatibility with all mobile devices. In my current project, I have developed a mobile application and utilized the following CSS code to display some data:

<div style="float: left; width: 90%; margin: 0 auto;">
        <div style="float: left; width: 20%; height: auto;">
            <img style="height: 100px; width: 100px;"
                src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSvYw0Fzp3l9dRMBOyRr-MVP_sDgMpyH2V5-iOjHVTzIqlJuwiv3Nsd7fE4" />
        </div>

        <div style="float: left; width: 70%">
            <div style="padding-left: 7%; float: left;">
                <p>Name:</p>
            </div>
            <div style="float: left; margin-left: 1%;">
                ABCD
            </div>
        </div>
    </div>

However, when I viewed this on different simulators, the output was not as expected. Can anyone provide assistance in resolving this issue?

Following the suggested solution:

/*IPad*/
@media only screen and (min-device-width: 1114px) and (max-device-height: 1391px) and (orientation:portrait)
{
    #divName
    {
        margin-left: -6%;
        float: left;
    }
}

@media only screen and (min-device-width: 1114px) and (max-device-height: 1391px) and (orientation:landscape)
{

    #divName
    {
        margin-left: -11%;
        float: left;
    }
}

/*IPhone*/

@media all and (min-device-width: 440px) and (max-device-height: 802px) and (orientation:landscape)
{

    #divName
    {
        margin-left: 7%;
        float: left;
    }
}

@media all and (min-device-width: 440px) and (max-device-height: 802px) and (orientation:portrait)
{

    #divName
    {
        margin-left: 25%;
        float: left;
    }
}

<div style="float: left; width: 70%">
            <div id="divName">
                <p>Name:</p>
            </div>
            <!--<div style="float: left; margin-left: 1%;">
                ABCD
            </div>-->
        </div>

Answer №1

To customize styles for different orientations, you can create specific rules:

 @media all and (orientation:portrait) {
 /* Add styles for portrait mode here */
 }

 @media all and (orientation:landscape) {
   /* Include styles for landscape mode here */
 }

Also, explore more about media queries.

http://css-tricks.com/css-media-queries/

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

Error encountered when attempting to retrieve DateTime from MySQL in PHP: Undefined Index

I'm in the process of setting up a webpage that will display event information fetched from a MySQL Database. I am using a PHP function to retrieve this data and include the datetime of the events. Currently, my PHP function is successfully populatin ...

Assigning random classes from a pool of just 3 variables to over 20 different div elements

I have a total of 20 divs and three different hover effect classes. I would like to randomly assign one of these three hover effects to each div. The JavaScript code I am using is: <script> $(document).ready(function () { viewClasses = 3; randomNum ...

Why is my CSS not recognizing the animation I specified for it to play?

I can't seem to get the simple animation I added to my code working properly. <div class="phone-center"> <div class="phone"> </div> </div> .phone-center { display: flex; justify-content: ce ...

jQuery functions correctly within jsfiddle, yet it encounters issues when utilized within WordPress

I've been experimenting with a jQuery script to grey out the screen. While it works perfectly on my jsFiddle link provided below, I'm having trouble getting it to work from within my WordPress plugin. Check out the working script on my jsFiddle ...

Challenges with resizing in Bootstrap

I need assistance with my login form that is appearing in a Bootstrap modal. The modal I am using is the standard size, not the larger one. In the form, there are 2 input fields and a login button on the left side, while the right side should contain other ...

Express.js problem: Unable to load CSS and JS files from the 'public' directory

Currently, I am working on a web project with Express.js and encountering difficulties in loading CSS and JavaScript files from the 'public' folder. Despite following common practices, it seems that something is amiss. Here is the layout of my pr ...

Ways to recover HTML elements that have been eliminated by jQuery's remove

$(document).ready(function() { $('#remove').click(function() { $('.test').remove(); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="test-wra ...

Utilize Jquery Mobile ThemeRoller's design on your MVC4 mobile app for a cohesive and professional look

After creating an MVC4 Mobile application in Visual Studio 2013, I am struggling to apply jquery mobile themeroller themes to it. I attempted to replace the existing theme css with my custom theme, but it does not seem to be working at all. See the code ...

Replace 'hover' functionality with a different action when another particular class is present

One of the buttons in my project looks like this: <button type="button" class="btn btn-link btn-link-dark"> <i class="material-icons">help</i> </button> By default, when I hover over it, the button turns blue. However, I want to ...

Changing the color of MUI Typography when selected

Struggling to modify the styling of the Typography component nested inside a MenuItem. Unable to apply styles to ListItem as intended Check out my code here: https://codesandbox.io/s/dztbc?file=/demo.tsx:1481-1804 Desired behavior: Change styling on sele ...

How to Align Printed Output in Angular Components

I am a beginner in Angular and I am looking to display modal information. To print the data, I am using onclick=print(). The data shows up in the print preview, but it is not aligned correctly. Here is a screenshot of my page. I want to align the data prop ...

Adjust the size of three panels (left, middle, right) using Javascript, ensuring that the middle panel remains unchanged in size

I am a newcomer to JavaScript and currently working with HTML, CSS, and JS files. I have three panels - left, center, and right - that I want to resize. The left panel resizes correctly when dragging the column border. https://i.stack.imgur.com/LxhUX.png ...

Can curly braces be utilized in the style section of Vue.js?

Can I utilize curly braces in the style section of vue.js to set a value? For instance .container { background: url({{ image-url }}; color: {{ color-1 }} } ...

What might be the reason behind the failure to implement my color class on the text within the <p> element?

I'm looking to streamline my stylesheet to easily change the color of different text elements. I've created a list of general colors that can be applied using classes, like (class="blue") . Here are some examples: .dark-grey { color: #232323; } ...

Complete alignment of several elements in a horizontal scrolling container

In the table-like container, I have elements with horizontal scrolling. Each element has the same width but potentially different heights. I want to add a button in the top-right corner of each element without it disappearing when scrolling. I came across ...

Generating a vertical line right in the middle of the list item

I have recently designed an HTML page featuring a list of links using ul and li elements, with a customized background color for each li. Now, I am looking to add vertical lines next to the li items. When attempting to insert an image, my output looks lik ...

Having trouble adjusting the grid's width property

My personal page features a section dedicated to displaying my skills and proficiency in various programming languages (although it may not be entirely accurate). I am struggling to adjust the width of the Skill grid to match the layout of the other grids ...

Issues have arisen in IE8 with the background gradient on hover elements in the menu, while it functions properly in all other web browsers

Welcome to the website: I've recently taken on a project involving the gradiated menu on this site. The menu works flawlessly in Firefox, Chrome, and Safari - the hover effect changes the background color to a light gradiated green. However, when it ...

Learn how to dynamically disable a button using jQuery within the Materialize CSS framework

While attempting to disable a button in Materialize CSS using jQuery, I encountered an issue. Despite following the documentation found here, it seems that simply adding the 'disabled' class does not automatically disable the button as expected. ...

The CSS center alignment is functioning properly on some pages, however, it seems to be malfunction

I have noticed that the CSS centering is effective on this page: However, it seems to not be working on this page: Despite both HTML pages utilizing the same CSS link, the centering issue persists on one page. Any assistance in resolving this discrepancy ...