Adjusting divs and modifying based on the size of the screen

My website features a list of images with corresponding paragraphs of text displayed to the right of each image. I am trying to adjust the layout so that when the screen size is 736 px or less, the text is shown below the image and the image is centered. This change is necessary to ensure compatibility with tablets and phones.

To achieve this layout shift, I have been experimenting with div tags and the @media query in CSS. Currently, on desktop screens, the image occupies 20% of the width and the text takes up 80%, sitting next to each other. When the screen size decreases to 736px, I want the image width to increase to 50% while the text expands to 100%, moving below the image.

However, despite my efforts with @media queries, I have encountered an issue and I am unable to identify the problem. Can anyone provide guidance on how to address this?

Furthermore, what additional steps do I need to take to easily duplicate this design for multiple images and texts? Shouldn't the layout automatically arrange new content below existing ones once copied and pasted?

CSS:

 div.sidebyside{

    @media only screen and (max-width : 736px){
        border: 5px solid #000000;
    }

    @media only screen and (min-width : 737px){
        float:left;
        border: 5px solid #000000;
    }
}

div#image{

    @media only screen and (max-width : 736px){
        width : 50%;
        align-items: center;
    }

    @media only screen and (min-width : 737px){
        width : 20%;
    }
}

div#info{
    @media only screen and (max-width : 736px){
        width : 100%;
    }

    @media only screen and (min-width : 737px){
        width : 70%;
        padding-left: 5%;   
    }
}

HTML:

<div id="image" class="sidebyside"><img src="url" alt="" /></div>
<div id="info" class="sidebyside>
<p style="text-align: justify;">Insert your paragraph text here.</p>

</div>

Answer №1

I want to express my gratitude for your assistance in making the following CSS code functional:

        .sidebyside{
            float:left;
            border: 5px solid #000000;
        }

        #image{
            width : 20%;
        }

        #info{
            width : 70%;
            padding-left: 5%;
        }

        @media (max-width: 768px) {
            #image{
                width: 50%;
                margin-left: 25%;
                margin-right: 25%;
            }
            #info{
                width : 100%;
                padding-left: 0%;
            }
        }

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

Switching from Wordpress to Django and completely revamping the website using only Django

I have a webpage that currently has wordpress.org preinstalled, but I have never utilized it. Now, as I am exploring django, I am interested in using it to build my website instead of relying on wordpress. Can someone guide me on how to transition from wo ...

Transform percentage into pixels

I'm currently utilizing this specific JavaScript range slider and my goal is to define a minimum and maximum value in pixels, rather than the default percentage range from 0 to 100. I have successfully implemented the min and max settings, now my nex ...

When you choose the File->Print option, the PDF contents are seamlessly printed within the document

My web page has an embedded PDF file within the content. <h3>Foo</h3> <object id="foo" data="bigboundingbox.pdf" type="application/pdf" classid="clsid:CA8A9780-280D-11CF-A24D-444553540000"> </object> When viewed in Interne ...

Elevate your design game by mastering CSS transformations for precise element

I am trying to center a div with a variable width using the following code: div { background: red; max-width: 400px; position: absolute; left: 50%; transform: translateX(-50%); } Check out my demo here While this code works well for centering, ...

Is there a way to identify if an element has been clicked using jQuery upon initial page load?

Currently, I am attempting to assign a javascript variable to one of several possibilities. If a specific link has not been clicked (such as on the initial page load), then the variable should default to 0 or 1. However, if one of those links has been cl ...

The Bootstrap row fails to align elements side by side as intended

I'm trying to arrange elements in my navigation menu side by side, so I decided to use the row class from Bootstrap 5.0. However, they are still stacking on top of each other. I am currently working on a Flask project and using Jinja to some extent. ...

Create identical buttons using Bootstrap 4

I am trying to create uniform left and right buttons, but I am facing issues with making them look the same on both PC and mobile devices. Here is the current appearance: View the current button design <h3> <a href="" ...

The $(element).click() function is failing to trigger even when placed within the $(function() {})

I have a hidden input element (Dropzone) that is included in the original HTML body without being appended. <div style="display: none;"> <form action="/uploadProfile" method="post" class="dropzone" id="uploadProfileDropzone"></form> ...

Displaying text on multiple lines

Currently, I am developing a reactjs application where I receive multi-line text data from the backend. When I log the text received, it appears as follows: Gladiator Enya Cricket I am trying to present this text in its original form within my reactjs ...

Enhancing React Flow to provide updated selection and hover functionality

After diving into react flow, I found it to be quite user-friendly. However, I've hit a roadblock while attempting to update the styles of a selected node. My current workaround involves using useState to modify the style object for a specific Id. Is ...

Preventing Mobile Video Downloads: Tips and Tricks

I am facing a challenge with my website that contains several case studies featuring video headers set to autoplay. These videos are placed within a parent div element, which is hidden on mobile and tablet devices. Since the videos will not be visible on ...

Adjusting the navbar color on scroll

I am looking to change the color of my navbar upon scrolling. When the navbar is at the top, the background should be transparent. Thank you to everyone for the attention and I apologize for my poor English! /* Navbar Color */ .navbar-default .navbar-t ...

My Bootstrap navbar seems to be malfunctioning. I'm wondering if there could be an issue with

here is a snippet of the code I'm working on: <nav class="navbar navbar-expand-md navbar-dark bg-dark sticky-top"> <div class="container-fluid"> <a class="navbar-brand" href="#"> <img src="https://i.stack.imgur.com/5XeYV.png" ...

How to add a circular edge to an element with a pseudo-element

I am trying to create an HTML element that needs to be responsive and cannot be an SVG. The element should resize when the text content inside breaks onto a new line. I have already skewed the element slightly, but now I need to add a rounded side on the r ...

What could be preventing the spinning cube from rendering in three.js?

While there are no errors showing up, the result is just a black screen. Due to the small size of the HTML and CSS code snippets, I suspect the issue lies within the JavaScript. // Creating a three.js scene: a 3D environment for objects const scene = new ...

The chat window is tall, stretching to its full height and remains stationary, not moving with the

I seem to be facing a CSS issue with the chat window not taking full height. It doesn't follow along when I scroll to the bottom of the screen. I'm stuck and unsure where to apply min-height: 100%; or if that's even the root cause of the p ...

Are there methods to individually style components that have been generated through the .map() function?

My goal is to style each <Tuner /> component separately, which are being rendered for each item in the this.state.notes array using this.state.notes.map(). I want to position them individually on the page, but currently they all appear together. This ...

Angular 12 experiencing CSS alignment issues

In my Angular component, I have the following CSS: .folders { border-left: 5px solid #b8744f; -moz-border-radius: 5px; -webkit-border-radius: 5px; -moz-box-shadow: inset 0 0 1px #fff; -webkit-box-shadow: inset 0 0 1px #fff; /*CORRECTION NEEDED ...

Building a responsive CardMedia component with React Material UI

I am currently working on creating a gallery using React Material UI (utilizing Card, ...). I am facing some challenges in making the gallery responsive, especially with varying cover sizes: https://i.stack.imgur.com/2n6vf.png Here is the code snippet I ...

Issues arise in mobile Safari when attempting to load JavaScript files, resulting in

Encountering an issue with my Angular app on mobile Safari during the initial load, where it hangs on a blank page for nearly 2 minutes. Interestingly, the app functions perfectly on other browsers, including Mac Safari and iPad Safari. Initially, I suspe ...