Enhancing CSS Responsiveness Challenge

For my mobile version in CSS, I am considering two options:

  1. The first option is to create separate div elements with classes 'desktop' and 'mobile', and build everything from scratch. Here's an example:

<div class="container-fluid bg-1 desktop1">
<div class="container">
<div class="col-xs-5 despre-noi-text first-section">
<h2>asdfsdfdf</h2>
  <p class="despre-paragraph">
           adsdadd
            </p>
  </div>
  <div class="col-xs-7 despre-noi-img second-section"></div>
</div>

</div;
<div class="container-fluid mobile1">
<div class="container">
<div class ="row mobile-row">
<div class="col-xs-12 mobile1-img"></div>
</div>
<div class ="row mobile-row">
<div class="col-xs-12 mobile1-text">
<h2>asdfsdffdfsfsdf</h2>
  <p class="mobile1-despre-paragraph">
            asdfdfdfd 
            </p>
            <p class="mobile1-despre-paragraph2">saddfsdfsdfsdfd</p>
  </div>
  </div>
</div>
</div>

Then, I will use media queries to determine which classes should be hidden based on the screen resolution.

@media only screen and (max-width : 480px) {

.desktop1 { display:none; }
.mobile1 { display:block; } 
 }

Alternatively, I could choose to overwrite all classes within the media queries. Which do you think is the better approach?

Answer №1

Utilizing media queries to customize default properties is essential for efficient and maintainable code. Keeping your code DRY (Don't Repeat Yourself) helps minimize unnecessary duplication, reducing the amount of code that needs to be loaded by the browser and simplifying future maintenance tasks.

There's no performance drawback in using media queries to override styles as CSS is designed to cascade. Take advantage of this feature without guilt, unless you're overly specific with little reason.

In summary: Avoid the headache of duplicating HTML. Opt for a cleaner, more streamlined approach instead.

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

Change the visibility of a div's content when a radio button is selected with only CSS

When the radio buttons are on the same div level as "content1" and "content2", it works properly. But how can I make it work if I move the radio buttons to another div outside of the "second" div? For example, if toggle1 is checked then content1 should be ...

What is the best way to adjust the size of a kendo ui combobox?

Is there a way to adjust the width of the kendo ui combobox? My current version is 2012.3.1114 I've attempted to modify it using the following CSS: #options { padding: 30px; } #options h3 { font-size: 1em; font-weight: bold; margin: 2 ...

Ways to eliminate padding on narrow screens with bootstrap 5.2 features

I have a container with a padding of 5 (p-5) applied to it. However, I am looking for a way to automatically remove the padding when the screen size is small, without adding more CSS rules. Is there a solution using only bootstrap classes? <div class= ...

Learn how to assign an image to a div element when it is collapsed, and then reveal the content when clicked on to expand

I am working on a three div with expand collapse functionality. When I expand one div, I want to set some image to the other divs. And when I go back to normal mode, I need the original content that was inside each div. $("a.expansion-btn").click(functi ...

What is the easiest way to update the border color of a radio button in Material-UI?

I am looking to customize the appearance of the outer ring on Material UI radio buttons. https://material-ui.com/components/radio-buttons/ Currently, my radio button looks like this: https://i.stack.imgur.com/o67mN.jpg However, I would like it to look ...

Increasing the level of CSS list counters

HTML <ol> <li>item1 <ol> <li>item2</li> </ol> </li> <li>item1 <ol> <li>item2</li> <li>item3</li> </ol> </li> </ol> SC ...

Using icons from Bootstrap on your local machine can be a valuable asset for

When using this particular method <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" /> The icon is visible with this reference: <button type="reset" class="btn btn-warning cancel"> <i ...

uploaded documents on the web server are not functioning as expected

I've been having issues with my school website. Everything works fine when I work on it locally using tools like Atom or Wamp, but once I upload the files to my web server (an old laptop running Ubuntu 18.04 with a LAMP server), the CSS files, images, ...

Incorporating a transition effect to simultaneously toggle between two classes

I'm currently troubleshooting the demo below. For some reason, I am unable to apply a transition to either .fa-chevron-right or .fa-chevron-left when toggling between two classes. Can anyone help me figure out why? $("button").on("click", function( ...

What is the best way to center my items vertically in a material-UI Grid row?

Struggling to vertically align three items in a row using Material UI's Grid component. Despite setting "justifyContent: 'center'," it only horizontally centers the items. Here are my styles: const styles = (theme) => ({ root: { te ...

The sliding hamburger menu children fail to move in unison with the parent

I'm currently working on a dynamic sliding navigation menu that activates when the hamburger icon is clicked. However, I am facing an issue where the child <a> elements are not sliding along with the parent div. You can see how it currently loo ...

What steps can I take to make the cards in bootstrap 5.3 responsive for mobile devices?

I'm struggling with my code and need some help. I've been editing it, but things seem to be getting worse instead of better. Specifically, I can't figure out how to set up my container, row, and columns in Bootstrap properly. My site uses ca ...

Using Selenium to choose an element based on the text of its sibling element

I've been working on a selenium script for: My goal is to select the "Add to Compare" element for "Sony Xperia," but it's not being located. I've tried using both cssSelector and xpath, but I can't seem to figure out what I'm doin ...

Creating a dynamic background color that pulses with animation

I recently created a script to animate the menu li element when hovering over the corresponding a element. Everything is functioning as expected, but now I'm looking to enhance the effect by having it continue as long as the mouse remains over the a e ...

The ion-content scrolling directive is failing to show any displayed information

Within my Ionic application, I have a very simple HTML structure: <ion-pane> <ion-header-bar class="bar-stable"> <h1 class="title">Ionic Blank Starter</h1> </ion-header-bar> <ion-content> ...

The error code 13:5 indicates that the "Home" component has been registered in the Vue application but is not being used, leading to the error message "vue/no-unused-components"

I encountered this issue while working with Vue for the first time. I was attempting to construct a website using Vue/CLI by reorganizing and building from the inside out. However, I am unfamiliar with Vue and unsure how to resolve this error. The changes ...

Having issues with the CSS dropdown menu not activating when hovering

I am facing an issue with a simple menu that includes a dropdown feature upon hovering. The code works perfectly fine in Fiddle, however, it fails to work when running the entire page locally on IE. Can someone please assist me? (here's my code at fi ...

A problem arises when trying to showcase the content in a responsive manner on the hamburger menu, particularly when viewing on mobile

As a newcomer to web development, I decided to challenge myself by building an E-Commerce website to enhance my skills. To ensure mobile responsiveness, I opted for a hamburger menu to hide the navbar content. However, despite resizing working flawlessly, ...

Increasing the nth-child Selector in Jquery

Referring to this I am looking to cycle through the nth-child selector, which involves: var i = 1; var tmp = $(this).find('td:nth-child(i+1)'); // I wonder how this can be achieved i++; I have rows with dynamically generated columns i ...

Guide to setting up a horizontal button menu and dropdown submenu beneath the navigation bar using Bootstrap 4

How can I design a horizontal button menu with submenus below the navigation bar in Bootstrap 4? Take a look at the image below to see what I'm aiming for: https://i.sstatic.net/j6b8a.png https://i.sstatic.net/rmtrM.png If you have any ideas or su ...