Mobile Display of Div Blocks

I am having trouble with my media query not working to display "third_div" as a block in mobile and inline on a desktop. I have included two pictures demonstrating what I want to achieve. How can I resolve this issue? View Picture One

View Picture Two

<h2 style="text-align: center;font-size: 25px;font-family: Arial, Helvetica, sans-serif;line-height: 1.3;
margin-bottom: 18px;
font-weight: 400;"><strong>Premium Transportation Servicing The Dominican Republic</strong></h2>
<p style="text-align: center;">Transekur is the only company in the Dominican Republic dedicated exclusively to providing premium transportation and airport transfers in private, luxurious vehicles. No matter how big or small your vacation party, we have the transportation to fit your needs.</p>
&nbsp;
...
...
...
...
 <!-- End of the first div -->
<div id="third_div" style="width: 100%; background-color: #363636;display:inline-block">
 <style>@media only screen 
 and (min-device-width: 320px) {
  #third_div{
   display:block;
   }
 }</style>
<img src="http://transekur.seobrandserver.com/wp-content/uploads/2016/03/logo_transekur.png"/>
<h2 style="color:white;padding-left:50%;padding-top:2%;">Book Transport With Us Today!<h2>
<p><a href="tel:18888858708">1-888-885-8708</a></p>
<p><img src="http://transekur.seobrandserver.com/wp-content/uploads/2016/10/testgif.gif" style="width: 48px;
height:24px;" /></p>

</div>
</div>

Answer №1

Incorporating media queries, my recommendation would be to adopt a mobile-first strategy. Begin by setting display:block; as the default style and then switch it to display:inline-block; when the window reaches 320px or larger (I included some spans for visual demonstration):

#third_div {
  display:block;
  width:100%;
  background-color:#363636;
  color:white;
}
.mobile {
  display:block;
}
.desktop {
  display:none;
}

@media only screen and (min-width:320px) {
  #third_div {
    display:inline-block;
    color:red;
  }
  .mobile {
    display:none;
  }
  .desktop {
    display:block;
  }
}
<div id="third_div"><span class="desktop">DESKTOP</div><span class="mobile">MOBILE</div></div>

If you are creating an e-blast or a similar project, it is best to avoid inline styling. Utilizing external CSS offers a cleaner and more manageable approach.

Answer №2

Here is the recommended code snippet:

For desktop:

#third_div {
    display: inline-block;
}

If you are optimizing for mobile devices, consider using the following code:

For mobile:

@media only screen and (min-width:320px) and (max-width:767px) {
    #third_div {
        display: block;
    }
}

Alternatively, you can also try this solution:

For mobile:

#third_div {
    display: block;
}

For desktop:

@media only screen and (min-width: 1024px) {
    #third_div {
        display: inline-block;
    }
}

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

Guide on receiving a date input in a datetime format upon clicking a submit button

Currently, I am developing a daily report feature for my system. One of the requirements is to have an input field where users can select a date using a datepicker. When the user clicks the submit button, the system needs to retrieve the date from the data ...

Dealing with JSON data in the format of `(Object object)` requires a specific approach

I originally encountered object object when attempting to display JSON API data in HTML. I then used keyvalue in *ngFor which allowed me to display the object, but I am wondering how I can access and display the entire JSON data? Here are the relevant cod ...

Can you tell me how to implement a shopping basket in vue.js that only appears when an item has been added to it?

After numerous attempts, I often find myself clearing everything and starting from scratch. How can I make this work? Observing and learning from others will greatly assist me! This area is designated for shopping cart items. If it's empty, nothing ...

JavaScript not functioning on Express-powered HTML document

I have set up an express server to render my payj.html file, which includes a script tag for the clyint.js file. However, I am encountering an error in the browser's console: GET net::ERR_ABORTED 404 I also attempted to include all the JavaScript ...

`Selecting the ideal dropdown menu placement`

I've been working on creating a drop-down menu using CSS, and I've managed to hide the drop down menu successfully. However, I'm facing difficulty in making it reappear. I suspect that the issue lies with the :hover tag, which I have removed ...

What could be the reason for having two HTML nodes within a one-node HTML document?

My goal is to use DOMdocument to retrieve a list of HTML nodes in order to create a visually appealing CSS3 tree visualization on a web page. However, I've encountered an issue with the code snippet below: // Compressed, testing HTML $text = '&l ...

When I click on any input field, button, or other controls on a webpage, the page automatically zoom

I am currently trying to troubleshoot an issue with a bootstrap theme. It seems to be working perfectly on all browsers except for ios safari browsers. Whenever I click on an input field or button, the page suddenly zooms in. It's quite frustrating. ...

Safari 5 experiences delays with JQuery and CSS3 animations

Encountering issues with jQuery animations specifically in Safari 5 on my Windows system. Struggling with a simple image fade slider that still has some flickering. The slider involves click events moving two pages at once, one active page right and the o ...

Creating a customized display on a webpage using XML and XSL to generate unique

Looking to utilize my xml file for generating various xsl pages. <movies> <movie> <name>Shark tank</name> <movie> <movie> <name>Tank Shark</name> <movie> ...

Customizing and adjusting the CSS for all individuals accessing the website

I am in the process of developing a system that will notify users in the office when a specific individual is busy and cannot answer the phone. How can I implement a feature where clicking "engaged" changes the color of the availability box to red on thei ...

The positioning of drawings on canvas is not centered

I'm facing an issue while attempting to center a bar within a canvas. Despite expecting it to be perfectly centered horizontally, it seems to be slightly off to the left. What could possibly be causing this discrepancy? CSS: #my-canvas { border: ...

Prevent the cursor from exiting the div element when the tab key is pressed

Currently, I have implemented a search input box allowing users to either enter a value or select from a list of suggestions. The issue arises when the user selects an option using the tab key, as it causes the cursor to move outside the input box despite ...

Having trouble getting my AngularJS directive with a number in the name to function properly

Check out my code snippet: app.directive('3dPlansSlider', function(){ return { controller: 'projectCtrl', restrict: 'E', templateUrl: 'views/3dPlansSlider.html', link: function(scope, element, attr ...

Is it possible to display a subtle grey suggestion within an HTML input field using only CSS?

Have you ever noticed those text input boxes on websites where a grey label is displayed inside the box, but disappears once you start typing? This page has one too: the "Title" field works the same way. Now, let's address some questions: Is ther ...

Is there a way to display the # symbol instead of characters in the input text field?

I have a text input field in a PHP page with a maxlength attribute set to 11. This input field is specifically used for entering phone numbers. The requirement is that when the user types a phone number, it should display as "#" symbols for all 11 characte ...

``Incorporate images into a slideshow container with proper alignment

I'm currently using a jquery slideshow on my homepage with fading images, but I'm having trouble centering them. The images are all different sizes and they're aligning to the left instead of being centered. Here is the CSS code I've b ...

Having trouble getting a jQuery variable to work as an argument in an onclick function for an HTML

success: function(jsonresponse) { data = JSON.stringify(jsonresponse); $.each(JSON.parse(data), function (index, item) { var Id=item.id; var JobId=item.JobId; var eachrow = "<tr>" + "<td>" + item.id + "</td>" ...

Can you provide a succinct explanation of what constitutes a well-defined "landing page"?

Could someone provide a clear and concise explanation of what exactly constitutes a landing page and how it should be utilized? I'm struggling to grasp the concept. Where is the optimal placement for a landing page on a website? Is it best placed o ...

What causes the "v-col" width to suddenly alter after adding the "bg-red rounded" class?

I'm struggling to organize the data into blocks using Vuetify. When I apply the "bg-red rounded" class to the "v-col", it alters the width of the column, resulting in an undesired grid structure. Here is the template section of my Vue file. Some data ...

Incorporating Ace Editor into a jQuery UI Resizable Element

I am attempting to create a resizable Ace editor by placing it inside a resizable component. Despite my efforts with the jQuery UI Resizable component, I am unable to get the ace editor to display within the resizable component. Code: <!doctype html> ...