``Display text in the center of a column when viewed on mobile

I am facing some challenges when trying to center text within a specific section of my webpage, particularly in the mobile view. This section is identified by the class about and is contained within a container-fluid div. I also encountered an issue where there was blank space on the sides of this section, which was not filled with the background color as desired (I temporarily fixed it by adding color to the body element). My goal is to have the text centered and fill 80% of the screen width.

https://i.sstatic.net/oiSn4m.jpg

Check out the CodePen link for reference.

Here is the snippet of HTML code pertaining to the affected section:

        <section class="about" id="about">
          <div class="row">
            <div class="col">
              <h2>About</h2>
            </div>
          <div class="row">
            <div class="col-md-5">
              <img src="img/circle-portrait-small.png" class="portrait">
            </div>
            <div class="col-md-7">
              <p>.....</p>
            </div>
          </div>
        </section>

The relevant CSS styling for the section is as follows:

.about {
  padding: 3em 0;
}

.about p {
  text-align: left;
  width: 80%;  

}

/* Additional styling */
.about .row {
  width: 100%;
}

@media screen and (max-width: 767px) {
  .about {
    padding: 2em;
  }

  .about p {
    font-size: 15px;
  }

  .portrait {
    height: 250px;
    margin-bottom: 1em;
  }
}

Answer №1

The issue with the spacing may be due to negative margins set on the row element:

.row {
    margin-right: -15px;
    margin-left: -15px;
}

Try removing these margins to eliminate the extra space. As for centering the paragraph on mobile, you can achieve this by adding the following CSS:

.about p {
    margin: 0 auto;
}

It appears that your paragraphs are not taking up the full width of their parent container after a certain breakpoint because of padding set on various elements such as col, about, and container-fluid. You may want to adjust or remove this padding at that specific breakpoint to ensure your paragraphs occupy the desired space.

Answer №2

insert the following CSS specifically for mobile devices

.about .row {
    margin: 0px auto;
    display: table;
}
.about p {
    text-align: center;
    width: 100%;
}

Answer №3

Check out this updated code

You may want to consider removing any unnecessary margin or width specifications.

Answer №4

There seems to be a few issues with the code.

  • The opening row tag is not properly closed.
  • The CSS rule restricting the text width to 80% is unnecessary;

Please remove this...

/* I am unsure why this rule is included */
.about .row {
  width: 100%;
}
.about p {
  text-align: left;
  width: 80%;  
}

If utilizing the Bootstrap grid system, make sure to adhere to the correct structure of container>row>col(s).

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

Issue with customizing the appearance of the selected option in a dropdown menu

Is there a way to change the background color of each option in a select box when it is selected? Currently, when an option is clicked, it appears blue along with the selected text color. I have tried various selectors like :active, :focus, ::selection, [s ...

What is a CSS drop-down menu/container?

I've been brainstorming a unique dropdown menu style that involves dropping down a container, but I'm a bit stuck on how to execute it effectively. Although I've outlined the basic concept, I'm still unsure of the implementation. Any t ...

Creating a menu bar in jQuery that functions similarly to tabs, but without the need to change divs

Currently, I am exploring ways to create tab functionality similar to jQuery's tabs plugin but without the need to switch between DIVs. Essentially, I am looking for a jQuery plugin that solely handles rendering the tab bar and allows me to designate ...

ExpressJS encountered an error due to an unsupported MIME type ('text/html') being used as a stylesheet MIME type

Whenever I start my NodeJS server and enter localhost:8080, I encounter the mentioned error while the page is loading. The head section of my index.html file is provided below. It's puzzling to me why this error is happening, considering that my index ...

Create a visually appealing masonry grid layout by using CSS column-count and horizontal alignment

I have successfully created a masonry grid using the column-count property with 4 columns. However, all the div elements in the grid are displayed vertically. Is there a way to change this layout and display them horizontally using JavaScript or jQuery? ...

Will my JavaScript function be triggered when the page is resized while printing?

I have a simple HTML layout where I am using the TextFill jQuery library to automatically adjust the text size based on available space. Everything looks good on screen, but when printed, it seems like the page is resized and the JavaScript needs to be re ...

Several DIVs with the same class can have varying CSS values

I am looking to modify the left-margin value of various separate DIVs using JavaScript. The challenge is: I only want to use a single className, and I want the margin to increase by 100px for each instance of the class. This way, instead of all the DIVs ...

The Bootstrap dropdown menu fails to display properly within the "col" element

Here is the HTML code I am working with: <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-t ...

Challenges with pointer-events and z-index

I have been struggling to understand why I am unable to click the links in my footer. Even though my CSS may not be perfect, it does serve its purpose. There must be a more efficient way to create a footer that sticks to the bottom of the page and appears ...

What's causing this issue in Internet Explorer?

I recently created a new website at Unfortunately, I'm facing an issue with Internet Explorer. Despite trying various workarounds, I can't seem to pinpoint the CSS error causing the bug. Why am I struggling to fix this? 1- I predominantly use ...

Font discrepancies in HTML field types "text" and "textarea" are causing inconsistent font display

Why do the text in my "text" and "textarea" fields show different fonts on my pages' HTML? I attempted to specify the font type in both the background CSS file and within the HTML, but it did not resolve the issue. Just to be transparent...I'm ...

Using Angular to Bind Checkbox Value in Typescript

I have a challenge of creating a quiz where a card is displayed with 4 questions structured like this: <div class="col-md-6"> <div class="option" id="Answer1"> <label class="Answer1"> <input value= "Answer1" type="checkbox ...

The select element is displaying with a different width compared to its sibling, causing the Bootstrap spacing to over

Working on styling an input form using Bootstrap-4. I have an input field and a select field, both having the class "col" with different spacing classes. However, the select field appears slightly smaller. When I assign the class "col-6" to both fields, t ...

What impact does the order of the element I'm specifying in my .css file have on its appearance after being rendered?

(An update has been added below) In my project, I am working with a .css file and an index.html document. The goal is to create a panel of buttons on the screen [to prototype the usability of a touchscreen interface], with each button assigned a specific ...

I'm looking to use JavaScript to dynamically generate multiple tabs based on the selected option in a dropdown menu

I'm reaching out with this question because my search for a clear answer or method has come up empty. Here's what I need help with: I've set up a dropdown titled 'Number of Chassis'. Depending on the selection made in this dropdown ...

The navbar collapse feature in Bootstrap 4 is not functioning properly when using JQuery, popper, and bootstrap together

Hello there! I'm currently learning web development and attempting to create a button that collapses the navbar. I've gone through answers to similar questions but haven't found the solution that works for me. I've ensured that I have ...

HTML: Attempting to extract the inner div from the outer div and relocate it outside of the outer div

I am attempting to extract an inner div from an outer div and relocate it outside of the outer div. https://i.stack.imgur.com/NSS7B.png <div class="vc_gitem-zone-mini"> <div class="vc_gitem_row.............."></div> <div> I Would ...

Can Datatables be incorporated with modal pop-ups for editing purposes?

I am dealing with a DataTable that fetches data from a remote server. Each cell in the table has a mouse-over link that can trigger a modal popup (all links are the same). The issue I'm facing is the inability to pass the unique ID of the row and the ...

Difficulty encountered in setting the width of a sticky bottom element to be located at the bottom of the page with Tailwind

Fiddle: https://play.tailwindcss.com/pvT1jW8zZd Here is the code snippet I am working with: Here is how it currently appears: https://i.sstatic.net/2SRny.png <div class="bg-yellow-300"> <div class="p-16 m-5 text-xl bg-gray-500 ...

How can I prevent a span in CSS from stretching its parent element?

Utilizing the twitter bootstrap thumbnails successfully, we have implemented a description feature inspired by the bootstrap documentation. The distinction lies in our decision not to specify a size (e.g., .span4) for our thumbnails; instead, the content d ...