How can I center text and image?
Here is my code
<div class="container my-5">
<div class="row py-4 justify-content-center">
<div class="col-lg-4 mb-4">
<h1 class="text-dark font-weight-bold mb-3">
We've been expecting you
</h1>
<p class="mb-4">At our core is a collection of design and development solutions</p>
</div>
<div class="col-lg-8"><img src='assets/about.png' class="w-80"></div>
</div>
</div>
I tried to implement justify-center, offset,ml-x ,but nothing seems to work? I've already read the bootstrap library and haven't found anything that could help me
In your row, you have a 4 column wide column and an 8 column wide column, so you’re already taking up the full 12 columns, so the content in the row won’t “center.”
Your image will be whatever width it is as w-80 isn’t a Bootstrap 4 class – try w-75 or add your own class for w-80 (although if the image is only 80% of the column, the column won’t look centered - the content is already taking up the full width).
You could make the two columns 3 & 7, and then use a 1 column offset to have the two columns in the center (with the image at 100% of the 7 column width).
<div class="container my-5">
<div class="row py-4">
<div class="col-lg-3 offset-lg-1 mb-4">
<h1 class="text-dark font-weight-bold mb-3">
We've been expecting you
</h1>
<p class="mb-4">At our core is a collection of design and development solutions</p>
</div>
<div class="col-lg-7"><img src='bg400x240-1.png' class="w-100"></div>
</div>
</div>
Related
According to what i've understood when we are giving col-sm-n the columns in the row will arrange in the stack order when the device screen px is less than that specified by sm.Then what is row-sm,does it work similarly to col-sm?What is row-cols-sm-n.
Also when i used:
.boxx{
display:flex
}
<div class="row-sm mt-2 pt-5 m-5 boxx">
<div class="col-sm-3 small-box py-5 ml-3 mt-2 ">a</div>
<div class="col-sm-3 small-box py-5 ml-5 mt-2 ">b</div>
<div class="col-sm-3 small-box py-5 ml-5 mt-2 ">c</div>
</div>
I got the output as responsive columns, but taking out the boxx class, my output just became stacks, that too random stacks. And when I changed row-sm to just row, I got columns but their responsiveness was bad. They went to the same bad stack form as earlier when I reduced the screen width. I am quite new to the bootstrap and flex concepts, so I am trying to understand the difference.
P.s:The code is part of a container class.
.row-sm is not a standard class in Bootstrap 4.X or Bootstrap 5. I believe you're looking for .col-sm on the columns to make equal width on screen width great than sm breakpoint, stack less than sm breakpoint — reference https://getbootstrap.com/docs/4.6/layout/grid/#stacked-to-horizontal for documentation.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<div class="container">
<div class="row mt-2 pt-5">
<div class="col-sm bg-info">
a
</div>
<div class="col-sm bg-danger">
b
</div>
<div class="col-sm bg-primary">
c
</div>
</div>
</div>
On my widescreen monitor, my cover page looks like this (which is how I want it to look):
But on my smaller screen laptop, the words and the buttons (which are each in two separate columns) get spread out and my cover page looks like this:
I've tried several things but I can't seem to get them to stick together on smaller screens. Here is the relevant HTML code:
HTML:
<div class="container h-100">
<div class="row d-flex h-100 justify-content-center align-items-center g-0">
<div class="col-sm-6">
<div class="row">
<h1 class="title">transfer your</h1>
</div>
<div class="row">
<h1 class="title">music</h1>
</div>
<div class="row">
<h2 class="subtitle">between Spotify & YouTube</h2>
</div>
</div>
<div class="col-sm-4">
<div class="row mb-3">
<a class="btn" id="sp-to-yt" href="#" role="button">
</a>
</div>
<div class="row">
<a class="btn" id="yt-to-sp" href="#" role="button">
</a>
</div>
</div>
</div>
</div>
It's based on a percentage width. You can use the responsive classes to manage each screen size.
For small screens use <div class="col-sm-6"></div> which will display half-width on small screens. You can use multiple responsive classes like so...
<div class="col-sm-6 col-md-8 col-lg-3 col-xl-4"></div>
The responsive elements can be remembered as sm = small, md = medium, lg = large, etc, and will control each breakpoints div widths. Remember the max number of columns by default is 12.
Also, in your row.. <div class="row d-flex h-100 justify-content-center align-items-center g-0"> you don't need to define the display flex as .row is already a display flex class.
On large displays: I have an image horizontally aligned with 2 headers.
On small displays: I'm trying to stack the headers underneath the image, aligned vertically.
I suspect it has something to do with either margins, flex direction, some type of align property. Idk.. I've tried a bunch of things, maybe just not the right combination of things. It's possible i'm just having a brain fart or something. Here's the code:
<section>
<div class="container-md d-lg-flex align-items-center align-middle">
<img src="images\logo2.png" class="img-adjustment">
<div class="heading-wrapper">
<div class="display-4 montserrat text-nowrap heading-adjustment" style="">
Phoenix Master Meters
</div>
<h5 class="source-sans text-nowrap heading-adjustment">
Pipeline Consulting, Inspection, and Maintenance Services
</h5>
</div>
</div>
</section>
You can implement Bootstrap Grid, which then will handle display for large and small screens.
Then, remove text-nowrap class in elements inside heading-wrapper div.
This is one example
<section>
<div class="container-md d-lg-flex align-items-center align-middle">
<div class="row">
<div class="col-lg-2 col-sm-12">
<img src="images\logo2.png" class="img-adjustment">
</div>
<div class="col-lg-10 col-sm-12">
<div class="heading-wrapper">
<div class="display-4 montserrat heading-adjustment" style="">
Phoenix Master Meters
</div>
<h5 class="source-sans heading-adjustment">
Pipeline Consulting, Inspection, and Maintenance Services
</h5>
</div>
</div>
</div>
</div>
</section>
In my post section of the web site which I am creating I have 4 columns with post in each post with different height based on it's contents . bootstrap 4 grid system. As per photo under
When I resize the 4th column re-arrange.
As u can see on the above image the 4th column is shifted under number 1 but its align base on the height of the 3rd column. I want to be stacked like the photo bellow.
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row pt-3 port-folio-margins pb-5 pr-4 pl-4">
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 pl-1 pr-1 ">
<div class="post-container">
<div class="post-image"> </div>
<div class="post-title">TEST2016</div>
<div class="post-share-icons"></div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 pl-1 pr-1 ">
<div class="post-container">
<div class="post-image"> </div>
<div class="post-title">TEST2016</div>
<div class="post-share-icons"></div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 pl-1 pr-1 ">
<div class="post-container">
<div class="post-image"> </div>
<div class="post-title">TEST2016</div>
<div class="post-share-icons"></div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 pl-1 pr-1 ">
<div class="post-container">
<div class="post-image"> </div>
<div class="post-title">TEST2016</div>
<div class="post-share-icons"></div>
</div>
</div>
So the question is how to achieve that CSS formatting with Bootstrap or without bootstrap . I have tried putting "float" using "flex wrap" also "clearfix" without result.
Bootstrap has a built in utility for this problem you can use cards and wrap them in card columns. See the documentation here
This is a tricky issue that is often just worked around. Web-pages are much easier to code in grids, so things tend to be in columns and rows. In your example, when wrapped the row needs to be tall enough to contain your third item. That means that if the fourth item sat where you want it, it would be within the cell of the first item.
You can use something like Masonary, which I believe calculates top and left positions as you resize. Or I think you can use flex and a whole lot of wrapper divs, but that will get messy and be horrible maintenance. It's so messy I've never got it into production, either because I lost my mind trying, or hated the thought of maintaining it when it was working in just a small example.
Masonary allows a fairly simple layout
<div class="grid">
<div class="grid-item"></div>
<div class="grid-item grid-item--height2"></div>
<div class="grid-item grid-item--height3"></div>
<div class="grid-item grid-item--height2"></div>
</div>
JSFiddle example
I have the following page structure:
<div class="container">
<div class="row mb-5">
<div class="col-12 col-md-3">
<img class="mr-5 img-fluid" src="big_icon_1.png" alt="Big icon 1">
</div>
<div class-"col-12 col-md-9">
<h3 class="mt-0 mb-1 text-center text-md-left">Item 1</h3>
<p>This is item 1.</p>
</div>
</div>
<div class="row mb-5">
<div class="col-12 col-md-3">
<img class="mr-5 img-fluid" src="big_icon_2.png" alt="Big icon 2">
</div>
<div class-"col-12 col-md-9">
<h3 class="mt-0 mb-1 text-center text-md-left">Item 2</h3>
<p>This is item 2.</p>
</div>
</div>
</div>
What I am expecting is a column layout from the 'md' breakpoint up, and a stacked layout below that, and this is indeed what I'm getting. But the second 'col' is never extending to the right edge of the parent 'row' container and I do not understand why as all of the examples in the Bootstrap documentation show exactly that this should happen.
So my icon column is nicely set to 1/4 row width on a desktop and full width on mobile. But the column with heading and text is only ever as wide as its content, no matter what size the display. Of course, this makes the heading centring pointless.
What am I missing?
The source formatter on this website failed to catch this little gem, and my source editor has a very subtle colour difference that I hadn't noticed:
<div class-"col-12 col-md-9">
Which should, of course, be
<div class="col-12 col-md-9">
Time to change my editor colour scheme.
And, in fact, that line doesn't need the col-12 class in case anyone is looking. I only put it there in desperation.