How can you change the alignment of items from vertical to horizontal using Bootstrap?

I'm looking to create a responsive layout similar to the design of duckduckgo.com. This page features a logo, the DuckDuckGo brand name in text form, and a search box. When I reduce the width of the browser window to nearly horizontal bar size, the three elements shift from a vertical to horizontal alignment, and the logo and brand name also shrink in size accordingly. I am curious about how I can achieve this using Bootstrap.

Answer №1

If you're looking to learn more about Bootstrap, I recommend checking out their official documentation at the following link:

http://getbootstrap.com/css/

This resource provides comprehensive information on mobile resolution, media screens, and more.

To assist you in getting started with your website, I've put together a simple sample for you:

Here's the HTML code:

<div class="general">
    <div class="container">
        <header class="col-xs-12">
            <img class="logo" src="http://blog.kajrietberg.nl/wp-content/uploads/2013/09/HTML5_oval_logo.png">
                <span class="col-xs-12 title">alexfqc sample</span>
        </header>

            <main>
                <input class="col-xs-10 col-xs-offset-1 col-sm-offset-2 col-sm-8 col-md-offset-3 col-md-6 col-lg-offset3 col-lg-6">                
            </main>
    </div>
</div>

And here's the CSS code:

body{
    background-color:#F7F7F7;    
    min-width:320px;
}

general{
    width:100%;
}

header{
    margin-top:40px;
}

.logo{
    width:35%;
    margin-left:auto;
    margin-right:auto;
    display:block;
}

.title{
    text-align:center;
    margin-top:10px;
}

input{
    height:30px;   
}

In Bootstrap, the "container" class automatically adjusts to screen resolutions. The "col-xs-12" class means it has a width:100% up to 768px screens. Bootstrap divides into 12 blocks, so you can adjust widths based on these blocks. For example, to have width:50% up to 768px, use "col-xs-6". If you don't specify classes for other resolutions (col-sm-, col-md-, col-lg-), the width:100% from col-xs-12 will apply.

I've adjusted margins and input widths based on resolution:

col-xs-10 col-xs-offset-1 = 1 block for margin-left, 10 blocks for width (totaling 11, leaving one block for center alignment).
col-sm-offset-2 col-sm-8 = 2 blocks for margin-left, 8 blocks for width.
col-md-offset-3 col-md-6 = 3 blocks for margin-left, 6 blocks for width.

Answer №2

To create a responsive layout, you can utilize media queries. For detailed information on media queries, visit the following link from Mozilla:

https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries

Here is a simple CSS example:

@media (max-width: 767px) and (orientation: landscape) { 
   .div1{
        width:50%;
        float:left;
   }
   .div2{
        width:50%;
        float:left;
   }
}
@media (min-width: 768px) and (orientation: landscape) { 
   .div1{
        width:100%;
        float:left;
   }
   .div2{
        width:100%;
        float:left;
   }
}

If the screen is in landscape mode with a maximum width of 767px, the divs will be positioned side by side. If the screen is still in landscape but has a minimum width of 768px, then the divs will have a width of 100%.

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

The content in the html document is not flowing outside a div unless I eliminate the floating property from the div(s)

My goal is to create a page layout with three sections, each floated left based on the device width using media queries in my CSS. I have successfully achieved this, but when I inspect the page using Chrome Developer Tools, I notice that the body is not sp ...

The document.getElementsByClassName method in JavaScript is returning an Array with a length property value of 0

My HTML contains a list of li elements with one class. I am attempting to collect them all and place them in an array to determine how many have been gathered. However, when I attempt to display the number using the .length property of the array returned b ...

Is there a way to manipulate CSS to update automatically when new content is loaded via ajax?

I need help with customizing the CSS for 4 image links on my website. Each link is represented by a small image in its normal state and a larger image when hovered over. The content for each link is loaded using ajax. My question is how can I modify the C ...

html scroll to the flickering page

Why is it that when a user clicks on a link in the list, the browser flickers? This issue becomes especially noticeable if a user clicks on the same 'link' twice. Is there a solution to prevent this from occurring? The problem also seems to aris ...

Shift all content to the right when viewing on mobile devices

I'm looking to create space for a menu on the left side, similar to the one on Mashable's mobile view. How can I move all the content to the right? Feel free to resize the window and compare with . Thank you. Best regards, Marius ...

Adding CSS stylesheets on-the-fly in JavaFX

I am looking to incorporate a CSS file from the filesystem into my application. The goal is to allow users to dynamically add JavaFX CSS files that can be created by anyone and stored anywhere on their system. I attempted a test scenario to see if adding ...

Is it possible to use window.print() to print the entire contents of a DIV with both horizontal and vertical scroll bars?

In my code, I have a div that contains both horizontal and vertical scrollers. Whenever I try to print the content inside this div using the window.print() method, it only prints the visible portion of the div. Here is the code snippet that I have attempte ...

How can one ensure that the column width in a Datatable adjusts dynamically based on the content within?

My data table creation code looks like this: var Master = $('#MasterGrid').DataTable( { "data": response, "columns":columns, "scrollX": true, }); $('#Mas ...

Guide on transferring the td id value to a different page

document.getElementById('scdiv').innerHTML=Quantity <td id="scdiv"> </td> document.getElementById('quantitydiv').innerHTML=mrp <td id="quantitydiv"> </td> I am currently facing an issue where the code is being d ...

Adjusting the image height to match the container height while preserving its original aspect ratio

Is there a method, using CSS alone, to adjust an image's height to fit its container while preserving aspect ratio and allowing the overflow of width to be concealed? It may seem like a complex set of requirements, but is it achievable? Essentially, I ...

Why isn't Bootstrap validation functioning properly in my Modal?

I am attempting to implement client-side validation using bootstrap, as outlined here: https://getbootstrap.com/docs/4.0/components/forms/#custom-styles The challenge I'm facing is that my form is within a modal. When I click the submit button, nothi ...

How can you declare variables in CSS using LESS?

I am facing a challenge where I need to dynamically change the branding color and other styling variables on the portal based on certain conditions at runtime. I have successfully implemented this functionality using CSS with the code snippet provided be ...

How can I customize the appearance of the file input button in Angular Material?

Despite browsing numerous similar questions, I have yet to find a solution to my issue. My setup includes Angular 11, Angular Material 8, and a file input structured like this: <div class="form-group"> <input #myInput type="fil ...

How can we determine the dimensions of an absolutely positioned element within a relatively positioned element?

One thing I noticed is that when placing an absolutely positioned element within a relatively positioned element, the latter does not automatically inherit the width and height of the former unless manually set. Take this example: <!DOCTYPE html> ...

Having trouble loading background color or image in three.js

I've been struggling to load a background image or color on my webpage. Despite trying various methods, including commenting out javascript files and checking the stylesheet link, nothing seems to work. Even when I load the three.js scene with javascr ...

Guide on aligning all list items to the left using React Material-UI, incorporating fontAwesome icons, and styling with Tailwind.css

I am trying to align the text of my list items to the left. Here is what I have currently: https://i.stack.imgur.com/a5o5e.png Is there a way to left-align the text in this code snippet? import React from 'react'; import PropTypes from 'p ...

What is the best way to create an impact?

Need help fixing the parallax effect on this page. I attempted to implement a parallax effect but encountered some issues. Here is the JavaScript code: $objWindow = $(window); $('section[data-type="background"]').each(function(){ var $bgOb ...

What is the best way to align product cards side by side instead of stacking them on separate lines?

I am currently working on a mock-up website for a school project. For this project, I am developing a products page where I intend to showcase the items available for sale. Although I managed to successfully copy a template from w3schools, my challenge lie ...

Refinement of website footer alignment

As a web designer, I am experiencing difficulty in adjusting the footer on my website. I would like the footer to be fixed at a specific height and remain in the same position unless the content increases, in which case it should move down accordingly. Can ...

Tips for maintaining the default page size on your website when adjusting the browser window size

I've been struggling with a problem for quite some time now. How can I maintain the default page size of my website while resizing the browser? Let's assume the page size is 1280x720, how do I ensure that size remains intact when I adjust t ...