bootstrap 4 element positioning in Angular application view - html

I'm working on an Angular 7 blog application where I'm having some difficulty in adjusting the view of a template made with bootstrap 4. In the main HTML component, I've created two cards in a row, one of it is the blog posts and the other card contains category. The category card is getting fetched from a different component and called using it's selector i.e <app-blog-category></app-blog-category> in the main HTML component. Below are the problems I'm facing in the view. Please look at the image below for reference. Also you can view it from this link ---> https://stackblitz.com/edit/angular-tlbxbr?file=src%2Fapp%2Fapp.component.html
1) The category card is getting rendered beside the last blog document thus leaving a significant amount of space on the top. If I apply style margin-top:negetive-value on the card class as style it is getting resolved but then again the value is differing as the device-width increases or decreases and it goes way above or below than what is needed.
2) the image inside the horizontal card is not taking the full height and width of the card
3) When the device-width is between than 768px-991px, the category card elements i.e the header and list items are breaking maybe due to too much padding around them or being centered.
HTML:
<div class="container">
<div class="row col col-md-12 mx-auto" style="text-align:center; font-size:22px">All Blogs
<br><br><br><br>
</div>
<div class="row" *ngIf="allBlogs.length>0">
<div class="col-md-9 card" *ngFor="let blog of allBlogs">
<div class="row">
<div class="col-md-4">
<a [routerLink]="['/blog', blog.blogId]"><img src="http://localhost:4000/{{blog.imagePath}}" class="card-img-top card-img-size" alt="blog1"></a>
</div>
<div class="col-md-8 px-3">
<div class="card-block px-3">
<h4 class="card-title">{{blog.title}}</h4>
<p class="card-text">{{blog.description}}</p>
<br>
<a [routerLink]="['/blog', blog.blogId]" class="mt-auto btn btn-primary">Read More</a>
</div>
</div>
</div>
</div>
<div class="col-md-3 col-sm-12">
<div class="container"> //note that this part is called from a separate angular component by it's selector <app-blog-category></app-blog-category>
<div class="row">
<div class="col-md-12 card">
<article class="filter-group">
<div class="card-body">
<header class="card-header">
<h6 class="title">Categories</h6>
</header>
<ul class="list-menu">
<li *ngFor="let category of categories" [routerLink]="['/bycategory/', category.categoryId]">{{category.categoryName}}</li>
</ul>
</div>
</article>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.card-block {
font-size: 1em;
position: relative;
margin: 0;
padding: 1em;
border: none;
border-top: 1px solid rgba(34, 36, 38, .1);
box-shadow: none;
}
.card {
font-size: 1em;
overflow: hidden;
padding: 5;
border: none;
border-radius: .28571429rem;
box-shadow: 0 1px 3px 0 #d4d4d5, 0 0 0 1px #d4d4d5;
margin-top:20px;
}
.btn {
margin-top: auto;
}
.filter-group {
border-bottom: 1px solid #e4e4e4
}
.card-header {
padding: 0.75rem 1.25rem;
margin-bottom: 0;
background-color: #fff;
border-bottom: 1px solid rgba(0, 0, 0, 0.1)
}
.filter-group .card-header {
border-bottom: 0
}
.icon-control {
margin-top: 6px;
float: right;
font-size: 80%
}
.list-menu {
list-style: none;
margin: 0;
padding-left: 0
}
.list-menu a {
color: #343a40
}
a {
text-decoration: none !important;
background-color: transparent
}

I hope this works for you :
<div class="container">
<div class="row col col-md-12 mx-auto" style="text-align:center; font-size:22px">All Blogs
<br>
<br>
<br>
<br>
</div>
<div class="row">
<div class="col-12 col-md-9 order-2 order-md-1">
<div class="row" *ngIf="allBlogs.length>0">
<div class="col-md-12 card" *ngFor="let blog of allBlogs">
<div class="row">
<div class="col-md-4 p-0">
<a href="#">
<div class="card-img-top card-img-size" style="height: 100%; background-image: url('https://images.pexels.com/photos/1804035/pexels-photo-1804035.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500'); background-size: cover; background-position: center;" alt="blog1"></div>
</a>
</div>
<div class="col-md-8 px-3">
<div class="card-block px-3">
<h4 class="card-title">{{blog.title}}</h4>
<p class="card-text">{{blog.description}}</p>
<br>
Read More
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-12 col-md-3 order-1 order-md-2" style="margin-top: 1.1%;">
<app-blog-category></app-blog-category>
</div>
</div>
</div>

Related

Icon and Text Vertical alignment css

<div class="container-fluid" >
<section id="current-weather">
<div class="card text-center text-white bg-dark mb-3 " style="width: 60%;">
<div class="card-header">
weather
</div>
<div class="card-body">
<h2>{{location}}</h2>
<hr style="width: 30%;height: 2px; margin: 20px auto 20px auto;color: black;">
<h5 class="card-title"><i class="wi wi-owm-{{weather_current['weather'][0]['id']}}" style="font-size: 2.2em;"></i>{{weather_current['temp']}}°C</h5>
</div>
</div>
</section>
</div>
I have a problem with alignment text and icon. Look at screenshot
I've already tried to use vertical-align: middle and baseline. Maybe somebody can resolve my problem.
Here I have aligned it vertically and horizontally.
.container-fluid{
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
width: 60%;
}
<div class="container-fluid" >
<section id="current-weather">
<div class="card text-center text-white bg-dark mb-3">
<div class="card-header">
weather
</div>
<div class="card-body">
<h2>{{location}}</h2>
<hr style="width: 30%;height: 2px; margin: 20px auto 20px auto;color: black;">
<h5 class="card-title"><i class="wi wi-owm-{{weather_current['weather'][0]['id']}}" style="font-size: 2.2em;"></i>{{weather_current['temp']}}°C</h5>
</div>
</div>
</section>
</div>
Thanks and best regards!
I really appreciate your work, but I was asking to align icon and text in one line not the whole container on web page.
Check this image
Finally I coped with that. Here is my solution:
.align-inline {
display: flex;
align-items: center;
justify-content: center;
}
<div class="container-fluid" >
<section id="current-weather">
<div class="card text-center text-white bg-dark mb-3">
<div class="card-header">
weather
</div>
<div class="card-body">
<h2>{{location}}</h2>
<hr style="width: 30%;height: 2px; margin: 20px auto 20px auto;color: black;">
<h5 class="card-title align-inline"><i class="wi wi-owm-{{weather_current['weather'][0]['id']}}" style="font-size: 2.2em;"></i>{{weather_current['temp']}}°C</h5>
</div>
</div>
</section>
</div>
This is how result looks like

boostrap 4 Equal heights not working

What is the way of making div's have equal heights within the row?
it says everywhere that bootstrap4 is flex by default, but it doesn't work for some unknown reason
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="content" >
<div class="sub_title"> HISTORY </div>
<div class="desc"> Sometext </div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-6 col-md-6 col-lg">
<div class="content">
<div class="sub_title">
<div class="number"> 2012 </div>
</div>
<div class="desc"> some other text </div>
</div>
</div>
<div class="col-12 col-sm-6 col-md-6 col-lg ">
<div class="content">
<div class="sub_title">
<div class="number"> 2014 </div>
</div>
<div class="desc"> More text </div>
</div>
</div>
<div class="col-12 col-sm-6 col-md-6 col-lg ">
<div class="content">
<div class="sub_title">
<div class="number"> 2017 </div>
</div>
<div class="desc"> Text here too </div>
</div>
</div>
</div>
the scss
.content {
#extend .effect8;
background: white;
margin: 10px;
padding: 10px 30px 20px;
span {
display: block;
p {
font-weight: bold;
}
}
}
.sub_title {
font-size: 1.5em;
font-weight: 700;
text-transform: uppercase;
display: block;
color: $blue;
margin: 10px auto;
}
this is the scss for the content and the sub_title class
If you want .content to be full height on each .col, the content should have height:100%;. I don't know the CSS def of .effect8.
.content {
background: white;
margin: 10px;
padding: 10px 30px 20px;
height: 100%;
span {
display: block;
p {
font-weight: bold;
}
}
}
https://www.codeply.com/go/B4g6TlSDkA
Actually it depend of browser, e.g In Safari it may not work, and also in Internet Explorer may have unwanted behaviors.
If you're really want equal and avoid cross browser issue try JS solution e.g http://brm.io/jquery-match-height/

heading not extending to the end of the div

I have a heading banner that overlays across a background image for a tile. To make it responsive, I set the width to auto and it looks great on a collapsed screen (see capture below). Also, I'm using Bootstrap 4.
However, on full screen resolution, the heading background doesn't extend to the end of the div. I've tried to eliminate any padding, but I can't seem to get it to go to the end. See image.
Here's my HTML:
<!--browse by category section-->
<section id="category">
<div class="card-header text-center">
<h4 class="card-title">Browse Workouts by Category</h1>
</div>
<div class="row btn-warning">
<div class="col-sm-2 bg-primary" id="cardio">
<h1 class="text-center">Cardio</h1>
</div>
<div class="col-sm-2 bg-primary">
Hi
</div>
<div class="col-sm-2 bg-primary">
Hi
</div>
<div class="col-sm-2 bg-primary">
Hi
</div>
<div class="col-sm-2 bg-primary">
Hi
</div>
<div class="col-sm-2 bg-primary">
Hi
</div>
</div>
</section>
and my CSS:
/*--------------*/
/*---CATEGORIES-----*/
/*--------------*/
#cardio {
background: linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7)), url('../img/users/pexels-photo-460520.jpeg') no-repeat;
background-size: cover;
height: 300px;
}
#cardio h1 {
margin-top: 100px;
height: 100px;
width: auto;
padding-top: 25px;
color: #fff;
background: linear-gradient(rgba(93,139,229,0.7), rgba(93,139,229,0.7));
}
First you are missing the container div before the row. then, to force the title to be full width you need to add negative margin in order to override the padding of the outer class col-sm-2.
Avoid changing styles of bootstrap classes as I saw in other answers, this can break some of your other layout.
/*--------------*/
/*---CATEGORIES-----*/
/*--------------*/
#cardio {
background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url('../img/users/pexels-photo-460520.jpeg') no-repeat;
background-size: cover;
height: 300px;
}
#cardio h1 {
margin-top: 100px;
height: 100px;
margin-left:-15px;
margin-right:-15px;
padding-top: 25px;
color: #fff;
background: linear-gradient(rgba(93, 139, 229, 0.7), rgba(93, 139, 229, 0.7));
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<!--browse by category section-->
<section id="category">
<div class="card-header text-center">
<h4 class="card-title">Browse Workouts by Category</h1>
</div>
<div class="container">
<div class="row btn-warning">
<div class="col-sm-2 bg-primary" id="cardio">
<h1 class="text-center">Cardio</h1>
</div>
<div class="col-sm-2 bg-primary">
Hi
</div>
<div class="col-sm-2 bg-primary">
Hi
</div>
<div class="col-sm-2 bg-primary">
Hi
</div>
<div class="col-sm-2 bg-primary">
Hi
</div>
<div class="col-sm-2 bg-primary">
Hi
</div>
</div>
</div>
</section>
This should do it:
.row, .col {
padding: 0;
margin: 0;
}
#cardio {
padding: 0;
}
#cardio h1 {
width: 100%;
}
Keep the rest as is

How to center align columns nested in a column

Having troubles aligning these columns inside a section column.
Here is a screenshot of what's happening: https://gyazo.com/cfe7bfa58e98226d8e1718792631c035
And here's jsfiddle with all the required code: https://jsfiddle.net/8xxgn8vr/
<!-- Testimonials Section -->
<section id="testimonials" class="testimonials-section">
<div class="container testimonials-container center-block">
<div class="row">
<div class="col-lg-12">
<h1 class="">Testimonials</h1>
<div class="col-lg-12">
<div class="col-lg-6 testimonials">
Review 1
</div>
<div class="col-lg-6 testimonials">
Review 2
</div>
<div class="col-lg-6 testimonials">
Review 3
</div>
<div class="col-lg-6 testimonials">
Review 4
</div>
</div>
</div>
</div>
</div>
</section>
.container.testimonials-container {
margin: 0 50px 0 50px;
width: auto;
}
.col-lg-6.testimonials {
background: #E5E4DF;
height: 500px;
padding: 25px;
width: 300px;
margin: 50px 25px 50px 25px;
}
.testimonials-section {
background: #F6F6F6;
height: 100%;
padding-top: 40px;
text-align: center;
}
It's basically a section for reviews in index.html page and inside the section there will be 4 reviews which I want to be aligned in the center.
Thanks for all the help in advance.
Since you're using bootstrap I would suggest not altering directly the width of the grid elements, when you get a col-lg-6 that is supposed to occupy half of a row and set it to be 300px, you will be throwing away bootstrap responsiveness and it will eventually give you a hard time adjusting to the other specifics of the col-lg-6 class.
Since you mentioned you wanted to have 4 reviews all centered you could perhaps change your code to use a col-lg-3 that divides the row into 4 equal parts. Check this updated fiddle, but it would go like this:
HTML:
<!-- Testimonials Section -->
<section id="testimonials" class="testimonials-section">
<div class="container testimonials-container center-block">
<div class="row">
<div class="col-md-12">
<h1 class="">Testimonials</h1>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="testimonials">
Review 1
</div>
</div>
<div class="col-md-3">
<div class="testimonials">
Review 2
</div>
</div>
<div class="col-md-3">
<div class="testimonials">
Review 3
</div>
</div>
<div class="col-md-3">
<div class="testimonials">
Review 4
</div>
</div>
</div>
</div>
</section>
Updated CSS:
.container.testimonials-container {
margin: 0 50px 0 50px;
width: auto;
}
.testimonials {
background: #E5E4DF;
height: 500px;
padding: 25px;
margin: 50px 25px 50px 25px;
}
.testimonials-section {
background: #F6F6F6;
height: 100%;
padding-top: 40px;
text-align: center;
}
You are trying to fit 4 sections of lg-6 into a row of lg-12. Bootstrap is a grid system based on 12 parts. If you want the parts to align you always need to think about the 12 sections.
If you have only 4 reviews, you have to make sure you are using 12 divide by 4 = 3, so you need lg-3.
If you have less than 4 parts but you still want them to take space of 4 parts you'll have to intervene with bootstrap. (there is a SO post about aligning a row)
Also in your css you are changing the width of the bootstraps' divs and that's not good. (also margin). Never do that ;)
Example with 4 divs:
(using inner div)
HTML:
<!-- Testimonials Section -->
<section id="testimonials" class="testimonials-section">
<div class="container testimonials-container center-block">
<div class="row">
<div class="col-lg-12">
<h1 class="">Testimonials</h1>
<div class="col-lg-12">
<div class="col-lg-3 testimonials">
<div>
Review 1
</div>
</div>
<div class="col-lg-3 testimonials">
<div>
Review 2
</div>
</div>
<div class="col-lg-3 testimonials">
<div>
Review 3
</div>
</div>
<div class="col-lg-3 testimonials">
<div>
Review 4
</div>
</div>
</div>
</div>
</div>
</div>
</section>
CSS:
.container.testimonials-container {
margin: 0 50px 0 50px;
width: auto;
}
.testimonials div {
height: 500px;
background: #E5E4DF;
padding: 25px;
margin: 50px 25px 50px 25px;
}
.testimonials-section {
background: #F6F6F6;
height: 100%;
padding-top: 40px;
text-align: center;
}
Fiddle
Use the following code:
.col-lg-6.testimonials {
background: #E5E4DF;
height: 500px;
padding: 25px;
width: 300px;
margin: 50px 25px 50px 25px;
display: inline-block;
float: none;
}
You can just add class "row" to the outer column? Works for me in your fiddle.
<div class="row">
<div class="col-lg-12 row">
<h1 class="">Testimonials</h1>
<div class="col-lg-12">
<div class="col-lg-6 testimonials">
Review 1
</div>
<div class="col-lg-6 testimonials">
Review 2
</div>
<div class="col-lg-6 testimonials">
Review 3
</div>
<div class="col-lg-6 testimonials">
Review 4
</div>
</div>
</div>
.testimonials-section {
background: #F6F6F6;
height: 100%;
padding-top: 40px;
text-align: center;
}
.testimonials {
background: #FFFFFF;
}
.testimonials_content{
width: 95%;
margin: 0 auto;
border: thin black solid;
height: 500px;
background: #F5F5F5;
padding: 25px;
text-align: center;
font-size: 16px;
}
<section id="testimonials">
<div class="container testimonials-container">
<div class="row">
<h1>Tetimonials</h1>
<div class="col-lg-3 testimonials">
<div class="testimonials_content">
Review 1
</div>
</div>
<div class="col-lg-3 testimonials">
<div class="testimonials_content">
Review 2
</div>
</div>
<div class="col-lg-3 testimonials">
<div class="testimonials_content">
Review 3
</div>
</div>
<div class="col-lg-3 testimonials">
<div class="testimonials_content">
Review 4
</div>
</div>
</div></div>
</section>
you can't fit 4 sections into lg-6 for that you have to take lg-3. and under it you can take div by giving margin or width as per your need.
hope this helps.

How can i achieve panel overlap in css/bootstrap?

I am trying to achieve this:
I want the three panels in the gray <div> to overlap with the white jumbotron above them. How can I do this in CSS or with Bootstrap?
HTML:
<div id="home-page">
<div class="container text-center">
<div class="row">
<div class="col-sm-4">
<div class="panel">
</div>
</div>
<div class="col-sm-4">
<div class="panel">
</div>
</div>
<div class="col-sm-4">
<div class="panel">
</div>
</div>
</div>
</div>
<div class="container">
<h3>Passionate About Technology?</h3>
<p>We make and effort to learn something everyday</p>
LEARN
</div>
</div>
CSS
#home-page { background: #EFEFEF; }
#home-page .panel { box-shadow: 0px 0px 10px gray; margin: 15px; }
Thanks!
I was able to replicate the pic you had with a few adjustments to your code:
here is the css:
#home-page {
background: #EFEFEF;
}
#home-page .panel {
box-shadow: 0px 0px 10px gray;
margin: 15px;
margin-top:-50px;
height:200px;
}
#jumbo{
height:100px;
}
I also added a div on top to get that effect
<div id="jumbo"></div>
please see my codepen
http://codepen.io/sammyb123/pen/dMJaRw
View below snippet in Full page. If you want the same effect on smaller devices then use col-xs instead.
#home-page .panel {
box-shadow: 0px 0px 10px gray;
height: 250px;
margin-top: -15px;
}
#home-page .jumbo-ctr {
background: #fff;
margin-bottom: 20px;
}
#home-page .panel-ctr {
background: #EFEFEF;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div id="home-page">
<div class="container jumbo-ctr">
<h3>Passionate About Technology?</h3>
<p>We make and effort to learn something everyday</p>
LEARN
</div>
<div class="container-fluid text-center panel-ctr">
<div class="row">
<div class=" col-sm-offset-3 col-sm-2 ">
<div class="panel">
</div>
</div>
<div class="col-sm-2 ">
<div class="panel">
</div>
</div>
<div class="col-sm-2 ">
<div class="panel"></div>
</div>
</div>
</div>
</div>