Guide on aligning two text boxes next to each other using CSS flexbox and restricting the width for desktop screens exclusively

I am struggling with arranging two text boxes in a CSS flexbox. The left side contains a tagline while the right side has a brief summary. My goal is to have these boxes display side by side at the center of the webpage for desktop screens (min width 1024px), but stack up below that breakpoint for tablets and phones with widths below 1024px. The challenge is to ensure that the combined width of both boxes does not exceed 50% of the page horizontally. Currently, when the screen size increases, the text stretches to the ends of the screen despite my attempts to fix it!

Here is my HTML Code:

<div class="info-block">
    <div class="info-item">
        <div class="info-col">
            <h4>Modern Approach, Innovative Solutions, Accessible Support</h4>
        </div>
        <div class="info-col">
            <div class="info-text">We approach problems with holistic and practical solutions every time.</div>
        </div>
    </div>
</div>

And here is my CSS code:

.info-item {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    margin: 0; 
}
.info-item:last-child {margin: 0;}
.info-col {
    width: 46.6%;
    font-size: 24px; 
}
.info-col:first-child {
  text-align: right;
}
.info-text {
    margin: 0 0 20px;
    font-size: 24px; 
    line-height: 115%; 
    font-weight: 200; 
}

@media screen and (min-width: 1900px) {
    .info-text {
        margin-right: 200px;
        max-width: 420px; 
        margin-top: 5px;
    }
    .info-col {
        max-width: 420px; 
    }

I would greatly appreciate any help, suggestions, or insights to resolve this issue!

https://i.sstatic.net/lck4l.png

https://i.sstatic.net/JsUuU.png

Answer №1

Simple solution. Just insert the following code snippet into your CSS:

@media screen and (max-width: 1200px) { /* Adjust for screen size up to 1200px */
    .item-container {
        flex-direction: column; /* Change flex direction to column */
    }

    .item-column {
        width: 100%; /* Set width to 100% */
    }
}

To ensure the items remain centered, make sure to set the width to 100% as you arrange the columns on smaller screens.

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

Assign a distinct color to each character of the Russian alphabet within a specified text using CSS and/or JavaScript

My experiment involves testing the concept of "induced synesthesia" by assigning different colors to individual characters in text. I plan to map each character in the Russian alphabet to a specific color, for example, A is red, B is blue, and so on, resul ...

What's the reason for the align-self: flex-end CSS property not working as expected on a flex div element?

I am trying to align the "Click me" button to the left of the div that contains it. Here is my code: render = () => { return ( <Wrapper> <Body> <span>Title</span> <Desc ...

Safari's CSS Hacking Problem

After testing the code below, it appears to be working on both Safari and Chrome. I am seeking a hack specifically for Safari, not Chrome .contactDiv img:not(:root:root) { margin-top:-75px; } @media screen and (-webkit-min-device-pixel-ratio:0) { ...

Exploring Font Choices: Customizing Your Text Style

I've been attempting to incorporate my own font into my website, but despite researching several Stack Overflow articles, I'm facing various browser-specific and path-related issues. Sadly, I haven't been able to successfully display my font ...

Is it possible to change the title of a QGroupBox using HTML expressions in Python?

Does anyone know how to set the title of a QGroupBox with HTML expressions in a Python program? For example, using ABC for subscript. If you have any insights or solutions, please share! Thank you. ...

Having performance issues with an HTML5/JavaScript game on Internet Explorer 8

A new game has been developed using html/javascript. Due to confidentiality reasons, the code cannot be fully shared. The game runs smoothly on most browsers except for IE, which poses a challenge. Compatibility with IE8 is essential, despite its limitati ...

Show an Angular Mat Card beneath the Input Field and position it on top of all other div elements

I am designing a signup page and I need to include a material card below the password field with checkboxes for password requirements. The challenge is that when the card appears, it pushes down all other elements such as the sign-up button. I want the ca ...

Can javascript be used to swap out the folder in my URL?

I have been searching for solutions on how to change the language of my website using jQuery, but so far I have not found anything that works for me. Let's take my website as an example: www.domain.com I have separate folders for different languages. ...

Is the Data Being Saved: Verifying if the Value Has Been Altered?

Imagine your form containing numerous fields, where typically only 1 or 2 are modified and require saving. What approach do you take? Update the database with all values, regardless of any changes. Utilize form states to post back only the changed values ...

From JSON object to HTML table: converting structured data into a user

I'm currently facing a challenge when trying to iterate through JSON data retrieved from an API and display it in an HTML table. After parsing the original JSON, I accessed its elements as follows: JSON (data retrieved from API): {"PrekesID" ...

What is the best way to programmatically select a checkbox that was created dynamically using jQuery?

I've been scouring the internet trying to find information on what I'm attempting to accomplish, but so far I haven't come across anything helpful. The issue I'm facing is with a form that has a section dynamically added using JavaScri ...

Why won't my sticky element function properly with the position attribute set to sticky?

Hey there! I've been diving into learning all about CSS positions and have nailed down most of them. However, for some reason, the sticky position just won't cooperate and is stubbornly acting like a relative one instead. Check out my HTML snipp ...

What is the best way to retrieve the content of HTML tags from a string using JavaScript or AngularJS?

I have a string with mixed content of HTML tags and text. Here is an example: var str = "<p></p><p><i>blabla</i></p><p><i><b>blaaaaaablaaaaa</b></i></p><iframe src="..." height=" ...

Using Jquery to run a jquery script stored in a variable within jQuery syntax

This question may seem a bit confusing, so allow me to explain further. I am trying to execute a jquery script that is written in a text file obtained through an ajax request. For example, the code I receive from the ajax request looks like this: ($($(" ...

Every fourth list item, beginning with a designated number

I'm attempting to add a border to specific list items in my HTML. I want the border to start from the 9th child and then continue every 4th child after that. For clarification, I'd like the 9th, 13th, 17th, 21st, 25th... list items to have white ...

Tips for disabling the Enter key event specifically (without the combination of Shift+Enter) in a contenteditable field

I'm trying to incorporate the contenteditable attribute in my code, but I've run into an issue. I would like for pressing (shift + enter) to move to the next line (Note: I only want shift + enter to trigger this action), and when I press the ent ...

tips for generating a random number for direct display

Can anyone help me figure out how to automatically display the total of numbers from this script on my blog post without having to click anything? Additionally, I need it to update if the browser is refreshed. ` http://jsfiddle.net/BenedictLewis/xmPgR/ ...

Increase the background image size for a <li> element

I am working with an unordered list and have set it up to display a background image on the li element when the cursor hovers over it: <div class="sidebar"> <ul> <li>test</li> <li>test</li> ...

Tips for identifying a webpage and making class modifications based on it

I am working on a customized bar with 4 distinct parts. Each part corresponds to a different page on the website. I want each part of the bar to change color based on which page the user is currently browsing. For example, if the user is on page A, I want ...

Setting the height of a Bootstrap radio button

My Bootstrap radio buttons are set to a width of 200px. However, when the text inside the button exceeds this width, it wraps onto two lines leading to changes in button height. How can I ensure that all other buttons displayed scale to the same height? h ...