Title Text Alignment on the Left that Adjusts Based on Screen Size

I am working on creating a text layout within a bootstrap card that adjusts well on different screen sizes. Currently, the Title and body text are not responsive, causing issues on smaller screens. How can I modify the layout so that the Title appears above the body text on smaller screens? Here is my current code:

HTML

<div class="card shadow hover-scale-110 mt--100" style="background-color: #F3E500;border-radius: 25px;">
    <div class="card-body p-5">
        <div style="width: 100%;">
            <div class="innerDiv" style="width: 15%;">
                <h2 style="font-weight:bold;">Dear fellow Kenyans</h2>
            </div>
            <div class="innerDiv" style="width: 85%;">
            <span>Power is one of the most essential utilities in these difficult times of the COVID-19 pandemic.
                As Mobisol, we are extending a caring hand to help equip the more than 27 million Kenyans staying at home in the dark, with no or limited access to power.
                Solar energy is easy to acquire, install and inexpensive to use with the sun shining free of charge! We are contributing by making it more affordable and convenient to purchase, transport and install the Mobisol solar power package to benefit these families.
                Below are our discounted items categorised according to their specifications.<br/>
            </span><br>
                <span style="font-style:normal;font-weight:bold;">Please join us in spreading the #PowerOfLove.</span>
            </div>
        </div>
    </div>
</div>

CSS

.innerDiv{
float: left;
width: 100%;

}

Answer №1

Here is the solution:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css">
    <link rel="stylesheet" href="style.css">
    <title>Title</title>

</head>

<body>

    <div class="container-fluid " style='background-color: #F3E500; border-radius: 50px;'>
        <div class="row">
            <div class=" col-xs col-sm-3 col-md-3 col-lg-3 col-xl-3 ">
                <h1>
                    <bold>Dear fellow Kenyans</bold>
                </h1>
            </div>
            <div class=" col-xs col-sm-9 col-md-9 col-lg-9 col-xl-9">
                <span>Power is one of the most essential utilities in these challenging times of the COVID-19 pandemic.
                As Mobisol, we are reaching out to help provide power solutions to over 27 million Kenyan households facing darkness and limited access to electricity.
                Solar energy is a cost-effective and easily accessible option with sunlight available for all. We are committed to making our solar power packages more affordable and convenient for families in need.
                Below are the discounted products based on their specifications.<br/>
            </span><br>
                <span style="font-style:normal;font-weight:bold;">Join us in spreading the message of #PowerOfLove.</span>
            </div>
        </div>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/js/bootstrap.min.js"></script>
</body>

</html>

For demonstration, visit:https://jsfiddle.net/sugandhnikhil/4y3fm1Lh/1/ try resizing the window for effect

Thank you!!!! :-)

Answer №2

<style>
.card-body-content {
  display:flex;
}

.innerDiv.title{
  flex:15;
}

.innerDiv.detail{
  flex:75;
}

@media screen and (max-device-width: 500px) {
  .card-body-content {
    flex-direction: column;
  }
  .innerDiv.title{
    flex:1;
  }
  .innerDiv.detail{
    flex:1;
  }
}
</style>
<div class="card shadow hover-scale-110 mt--100" style="background-color: #F3E500;border-radius: 25px;">
  <div class="card-body p-5">
    <div class="card-body-content" style="width: 100%;">
      <div class="innerDiv title">
        <h2 style="font-weight:bold;">Greetings to all!</h2>
      </div>
      <div class="innerDiv detail">
        <span>Electricity plays a vital role in our lives, especially during these challenging times of the COVID-19 pandemic. At SunPower, we are reaching out to support over 27 million individuals in Kenya who are currently living without adequate access to power. Solar energy offers a convenient and affordable solution with the sun's free energy! We aim to make the purchase, delivery, and installation of solar power systems more accessible and cost-effective for these households. Explore our discounted products tailored to meet your specific needs below.</span>
        <br>
        <strong>Join us in sharing the #SolarRevolution!</strong>
      </div>
    </div>
  </div>
</div>

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

Using jQuery to target a specific item from a retrieved list of elements

I'm currently working on a photo gallery feature that is reminiscent of Instagram or Facebook user photos. My goal is to enable users to view details about each image (such as the date) in a box that appears over the image when they hover over it. E ...

I am currently exploring the world of HTML and CSS, but I am struggling to grasp the concept of how contact forms operate. Can anyone provide some

I'm new to learning HTML and CSS and I'm struggling to understand how contact forms function. Where does the email address get stored in this code? Do I need a PHP file for this to work? <section class="signup-section" id="signu ...

Align the bottom of an image with the top of text to achieve perfect vertical alignment

My goal is to arrange numerous images in a row, with text displayed below each image. Each block of text may consist of multiple lines and should be centered. While the heights of the images may vary, their widths will remain consistent. It is important th ...

Tracking changes in real time and calculating the sum with AJAX, PHP, and MySQL for efficient processing

Initially, I kindly request you to read this until the end. I am in dire need of assistance with my problem as I have searched for solutions but still remain clueless. https://i.sstatic.net/DAb1q.png Referring to the image provided, the first 'Produ ...

Is it possible to utilize the text-search feature in browsers for an HTML5 application?

Our team is currently developing a new feature for our HTML5 app that mimics the 'text search' function found in web browsers, which highlights specific texts. We're considering whether we can utilize this existing feature in browsers by ca ...

Adjust the dimensions within the class in bootstrap

Objective: My goal is to adjust a CSS code to be 700 instead of 870, based on the second image. Challenge: Currently, the default value is set at 870 (as shown in picture 1), but I need to use CSS to change it to 700. I attempted to make this adjustm ...

When I apply a percentage to the height of a div element, it shrinks down to a height

I have several lists with a flex layout. Each column contains 3 list items, and the flex-basis is set to one-third. Within each li element, there is a div for a background image and another div to display text, which should be positioned below the image. ...

exploring the network of connections

This is what the HTML structure of the webpage looks like: <body> <form> <input type='file'/> </form> <div id='list'> <div>value here<input id='delete' type='button'/>< ...

Having trouble opening or closing the nav menu with a click?

I've been struggling to get my hamburger menu to work properly for a while now. I've tried various solutions, but it seems like I just can't get it to open (Menu not opening is the issue :( ), The tutorial I followed to create this menu can ...

Working with Thymeleaf and DatePicker to establish a minimum date

Looking to establish a minimum selectable date in my datepicker using Thymeleaf. Attempted code: <label th:utext="#{${name}}" th:for="${name}" class="control-label"></label> <div class="input-group input-group-prepend"> <span cla ...

Parent element unable to trigger event due to interference from child elements

Within my HTML document, there is a parent <span> element that contains nested <em> elements. This <span> is styled with a specified width and display:block property using CSS. Despite a jQuery trigger event being successfully fired on t ...

Background image investigation

As a newcomer to web development, I am facing challenges in achieving the desired look for my first website. Despite spending over 2 hours researching and testing various CSS properties, I have not made much progress. What I aim for is quite straightforwa ...

What is the best way to show all cards in Angular when no filtering input is provided?

I have implemented a filter feature for multiple cards in Angular using Pipes. The filter works well, but I am facing an issue where no cards are displayed when there is no input value provided. I would like all the cards to be displayed when no input is g ...

Why is it that text doesn't function properly next to certain images?

I have been using the code below to place text next to an image: <div style="display:inline-block;vertical-align:bottom"> <p><img src="CIMA/CimaMetanoia.png" alt="Cool" height="50%" width="50%" /></p> </div> ...

Label embedded within field giving it a crispy touch

Utilizing Bootstrap5, Django, and Crispy Forms to develop a custom calculator application. The app is functioning as intended, but I am looking to modify the appearance of the forms. I've successfully eliminated the required field asterisk by includi ...

Creating golden phone numbers from a numerical series using JQuery

My latest work assignment involves generating gold numbers from a number series such as 52xxxxxx. Gold numbers could be examples like 52999999, 52727272, or something similar. I'm feeling a bit overwhelmed and unsure of where to begin with this task. ...

Utilizing Spring Boot API in conjunction with thymeleaf and bootstrap for seamless email communication

I'm currently developing a spring boot REST API that only exposes the backend logic. One of the functionalities we have is the forgot password feature, which requires sending an email to the user. To achieve this, I have implemented the thymeleaf temp ...

How can I ensure that an absolutely positioned element [created with React] snaps to the edge of its parent div when the page loads

I am currently developing a unique two-thumb slider bar component using React. Each thumb in the slider snaps to the closest discrete tick so that users can easily select values along a number line visually. One challenge I'm facing is that the thumbs ...

A guide on updating CSS content dynamically within ExtJS

In my resource folder, I have a CSS file that contains some values which I need to change or add based on certain conditions. However, I'm struggling to figure out how to achieve this. Here is an example of the code: triggers: { clear: { ...

The navigation bar is failing to display all of the titles

Having trouble with my HTML page. I can only see the first word of the title in the drop-down list. The navigation bar refuses to center despite trying various styles. Below is my CSS code: background-color: #78706e; height: 100%; font-family: Arial; c ...