Creating adaptive layouts with Bootstrap and HTML

Currently learning .net and bootstrap, I've encountered an issue while designing a web page. When viewed on smaller screens, the structure appears messy. Each col-md-6 contains rows where I want text to appear beside its corresponding image in the row. However, on smaller screens, the text ends up below the image. Feel free to take a look at the source code on the webpage. Apologies for any language barriers! To view the page, visit this address: [][1]

[1]:

  <div class="container">

    <div class="row ">

        <div class="col-md-6  " id="" style="background-color: #ff6a00; min-height: 650px;">

            <div class="row" style="min-height: 35%">

                <img class="img-responsive img-logo" src="img/about-us.jpg" style="transform: rotate(-10deg);" />

            </div>
            <div class="row" style="background-color: #ff6a00;min-height:550px;top:300px;">
                <div class="direction" style="color: black;">
                     <h4 style="padding-right:50px;">درباره ما</h4>
                    <br />
                    <div class=" float pading-top text-justify text">

                            <p>
                               some text
                            </p>
                        </div>
                    </div>
                </div>
            </div>


            <!----------------------------->

            <div class="col-md-6 otherbak2 " id="boss" >
                <div class="row height margin-top2 " >
                    <div class="col-md-6 height2 " >
                        <img class="img-responsive img-logo height2" src="img/png-ico/ali.JPG" />
                    </div>
                    <div class="col-md-6  height float" >
                        <p class="text-center" style="font-size: 17px; color: #d9534f">

                           some text
                             </p>
                    </div>
                </div>

                 <div class="row height margin-top2 ">

                    <div class="col-md-6 height2" >
                    <img class="img-responsive img-logo  height2" src="img/png-ico/mazdak.jpg" />
                    </div>
                    <div class="col-md-6  height float" >
                        <p class="text-center" style="font-size: 17px; color: #f0ad4e">
                             some text
                              </p>
                    </div>
                </div>

                <div class="row height margin-top2 ">
                    <div class="col-md-6 height2" >
                        <img class="img-responsive img-logo  height2" src="img/png-ico/babak.jpg" />
                    </div>
                    <div class="col-md-6 height  " >
                        <p class="text-center" style="font-size: 17px;color: #ea4619">

                             some text
                            </p>
                    </div>
                </div>
                <div class="row height margin-top2 " >
                    <div class="col-md-6 height2">
                        <img class="img-responsive img-logo height2 " src="img/png-ico/amin.jpg" />
                    </div>
                     <div class="col-md-6 height ">
                        <p class="text-center" style="font-size: 17px;color:#24a947;">
                          some text
                            </p>
                    </div>
                </div>
            </div>
            </div>

   </div> 

 <style type="text/css">
    body {
        background-image: url(../img/backgrnd.jpg);
    }

    .btn2 {
        color: #fff;
        background-color: #428bca;
        border-color: #428bca;
    }

    .width {
        width: 250px;
    }

    .height {
       min-height: 190px;
    }

    .height2 {
       min-height: 100%;
    }


    a:hover,
    a:focus {
        color: #FA6210;
        text-decoration: underline;
    }

    .width {
        width: 60%;
    }

    .danger {
        color: #d9534f;
    }

    .warning {
        color: #f0ad4e;
    }

    .success {
        color: #5cb85c;
    }

    .info {
        color: #5bc0de;
    }

    .primary {
        color: #FA6210;
    }


    .btn2 {
        color: #fff;
        background-color: #428bca;
        border-color: #428bca;
    }


    .style {
        color: white;
    }

    .pading-top {
        padding-top: 30px;
    }

    .margin-top {
        margin-top: 10px;
    }

    .menu2 {
        border-bottom: 5px solid #096DB9;
        border-radius: 10px 10px 10px 10px;
    }

    .menu3 {
        border-bottom: 8px solid #096DB9;
        border-radius: 15px 15px 15px 15px;
    }

    .direction {
        direction: rtl;
        float: right;
    }

    .direction2 {
        direction: ltr;
        float: left;
    }

    .float {
        float: right;
    }

    .padding {
        margin: 50px 5% 100px 5%;
    }

    .img-size {
        height: 128px;
        width: 128px;
    }

    .fixed2-menu {
        z-index: 1;
        direction: rtl;
        float: right;
        width: 100%;
    }

    .margin-top {
        margin-top: 30px;
    }

    .margin-top2 {
        margin: 5px 0 0 0;
    }

    .text {
        padding: 0 20px 0 20px;
        line-height: 25px;
        font-size: 14px;
    }

    .opacity {
        opacity: 1.0;
    }


</style> 

Answer №1

Adjust the height to min-height in the code snippet below to ensure that the picture does not overlap with the text

<div style="background-color: rgb(255, 106, 0); min-height: 650px;" id="about" class="col-md-6  ">

While your initial effort is commendable, there are several ways to improve the code. The issue lies with the classes height and height2. By removing them, the layout should correct itself. Additionally, consider removing the absolute positioning from the picture and substituting it with pull-left, which can be applied using the img-logo class.

Below is an example where I have made changes to one of the code blocks:

<div class="row height margin-top2 ">
     <div class="col-md-6 ">
           <img src="img/png-ico/ali.JPG" class="img-responsive pull-left">
     </div>
     <div class="col-md-6  ">
          <p style="font-size: 17px; color: #d9534f" class="text-center">
                رییس هیئت مدیره    
                        <br>
                علی کولیوند
           </p>
     </div>
</div> 

p.s: Very nice improvements ;)

Answer №2

It appears from the feedback that not all of the CSS you've written is necessary. In my opinion, Bootstrap styles can be categorized into two or three main groups.

  • DOM infrastructure [row, col-lg-12, etc..]
  • Component/element
    [form-control, form-group, btn, etc..]
  • Style [btn-primary btn-warning]

You have the flexibility to modify style-related aspects such as button colors, font sizes, and icon sets without impacting the overall structure.

Remember to maintain a maximum of 12 columns per row in your layout.

<div class='row'>
   <div class='col-md-7'></div>
   <div class='col-md-5'></div>
</div>

Review your HTML tags for alignment issues and consider removing unnecessary custom float classes.

Looking at Your Example

 <div class="row height margin-top2 " >
   <div class="col-md-6 height2 " >
      <img class="img-responsive img-logo height2" src="img/png-ico/ali.JPG" />
   </div>
   <div class="col-md-6  height float" >    
        some text                  
   </div>
 </div>

The issue here is with floating the right column unnecessarily. You can achieve the desired result without it.

If I'm understanding the problem correctly, you could potentially resolve it with the following:

CSS

.text-padding {
   text-align: right;
   vertical-align: middle;
   padding-top: 80px; // half of your image size 190px
}

HTML

<div class="row height margin-top2 " >
    <div class="col-md-6 height2 " >
        <img class="img-responsive img-logo height2" src="img/png-ico/ali.JPG" />
    </div>
    <div class="col-md-6 height text-padding" >    
         some text                  
    </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

What are the steps to personalize Twitter Bootstrap with Less for changing the height of the Navbar?

I recently stumbled upon some interesting articles that explain how to customize various elements of Twitter Bootstrap using LESS. You can check out one of the articles here and find more information about Twitter Bootstrap here. However, I am still unsure ...

Encountering the error "fn.dataTable.moment is not a function" when trying to use momentjs with DataTables in Angular

Feeling a bit frustrated as I struggle with what seems like a simple issue to fix. Using a DataTable that is working fine, but now I want to make a column of dates sortable in the German date format dd.MM.yyyy. Found the documentation on the official dat ...

Establish the default settings for the jQuery datetimepicker extension

Utilizing the jQuery timepicker addon alongside the jQuery datepicker has allowed me to create a date+time picker. Here is the link to the addon To establish default settings such as formatting and regional settings, I use the setDefaults option for both ...

Looking for a custom JavaScript color wheel with advanced features?

In search of a javascript color picker/wheel that allows users to easily select colors for our paint shop. Once the color is selected, it should automatically add the color value to the shopping cart. Our online store is operated using PrestaShop, so we ...

Is it possible to generate a "pop-up" window upon clicking on the register button?

As a backend programmer, I'm looking to create a popup window that appears in front of the current window when users click "register", eliminating the need for redirection to another page. I believe you understand the concept. How can I achieve this? ...

Choosing a root element in a hierarchy without affecting the chosen style of a child

I am working on a MUI TreeView component that includes Categories as parents and Articles as children. Whenever I select a child item, it gets styled with a "selected" status. However, when I click on a parent item, the previously selected child loses its ...

Inject $scope into ng-click to access its properties and methods efficiently

While I know this question has been asked before, my situation is a bit unique. <div ng-repeat="hello in hello track by $index"> <div ng-click="data($index)"> {{data}} </div> </div> $scope.data = function($index) { $scope.sweet ...

The $_POST method is malfunctioning, but surprisingly, $_GET is working perfectly

I am encountering an issue when trying to submit my form. I have attempted using both ajax and a regular submit ($.post(), $.get(), method="post", method="get"). When using either get method, I am able to retrieve the data successfully with $_GET, but whe ...

Parsing HTML using PHP's Simple HTML DOM Parser

I'm having trouble extracting specific information from HTML code using a DOM parser. <div id="posts"> <div class="post"> <div class="user">me:</div> <div class="post">I am an apple</div> &l ...

Several radial progress charts in JavaScript

While attempting to recreate and update this chart, I successfully created a separate chart but encountered difficulties with achieving the second progress. The secondary chart <div id="radial-progress-vha"> <div class="circle-vha ...

What causes the transformation of a POST request into a GET request?

Upon utilizing jQuery's $.ajax() or $.post() method to transmit form data to the server, I've noticed that the 'data' string gets appended to the end of the URL. This seems to be causing the POST request to transform into a GET request. ...

C# TimePicker Plugin with jQuery

I attempted to incorporate the timepickr plugin from Below are the headers I included: <script src="<%=ResolveUrl("~/Scripts/jquery-1.4.2.min.js")%>" type="text/javascript"></script> <script src="<%=ResolveUrl("~/Scripts/jquery ...

Button for Selecting Colors

I love the color picker button on Google Keep, where a variety of colors pop up for selection. I'd like to add something similar to my website. What steps should I take to implement this feature? ...

How to Use Attributes as Component Parameters in Vue.js

I am currently developing a test Component using Vue.js. I am trying to pass a parameter to be used in my template like this: Vue.component('test', { props: ['href'], template: '<li><a href="{{href}}"><slot> ...

Determining the height of a Bootstrap column in relation to another element

Utilizing the grid layout from bootstrap, I have the following structure: <div id="prof_cont_enclose"> <div class="row"> <div class="prof_cont_row"> <div class="col-xs-12 col-sm-4 col-md-2 col-lg-2 prof_elem"&g ...

Using PHP and jQuery to populate a Bootstrap modal window with data

I am looking for a way to dynamically load data into a bootstrap modal box using JavaScript. Here is the JS code snippet: $(function() { $('.push').click(function() { var id = $(this).attr('id'); $.ajax({ ...

Validate user credentials using both jQuery and PHP to display an error message if login details are incorrect

Working on a form validation using jQuery and PHP. I am utilizing an .ajax request to the server in order to verify if data has been entered into the form, and execute different actions based on the callback response received from the server. For instance, ...

Is it possible to incorporate MUI React components within an iframe?

Looking to replicate the style seen in this Material UI website screenshot, I aim to design a container that will encompass my iframe contents, such as the navBar and menu drawer. However, I want to utilize Material UI's components for these elements. ...

React-router error: Unable to call function _NavbarActions2.default.updateOnlineUsers

My current setup includes nodeJs and react version 0.14.2 with react-router 1.0.3 and history 1.17.0. When I navigate through my application, any action I try to perform results in "undefined", for example, fetching a character from the database. import a ...

Ways to address time discrepancies when the countdown skips ahead with each button click (or initiate a countdown reset upon each click)

Every time I click my countdown button, the timer runs normally once. But if I keep clicking it multiple times, it starts skipping time. Here are my codes: <input type="submit" value="Countdown" id="countdown" onclick="countdown_init()" /> <div i ...