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
Related
I'm having difficulty making the background images on my site responsive. I've added media queries to my page but they don't work and I'm not sure what else to do. Below, I've listed the html & css for the three images. Please advise any suggestions, thank you!
body {
background: url(/img/sect-bkgrd.jpg) center/cover fixed no-repeat;
font-family: 'Roboto', sans-serif;
color: #000;
}
#header {
min-height: calc(100vh - 94px);
background: linear-gradient(to right, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url(/img/sushi-main.jpg);
background-position: center center;
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
background-color: #000;
}
#menu {
background: linear-gradient(rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.2)), url(/img/menu-bkgrd.jpg) center/cover fixed no-repeat;
}
<header id="header">
<div class="container">
<div class="row height-90 align-items-center justify-content-center">
<div class="col">
<div class="banner text-center">
<h1 class="display-1 text-capitalize underline w-50 mx-auto">
<strong class="primary-color">Title</strong>
<img src="/img/sushi-logo2.png" class="img-fluid" alt="" />
</h1>
</div>
</div>
</div>
</div>
<section id="menu" class="py-5 my-5">
<div class="container">
<div class="row">
<div class="col-md-6">
<!-- title-->
<div class="row">
<div class="col">
<h1 class="primary-color text-uppercase">sushi</h1>
</div>
</div>
<!-- title-->
<!-- single item-->
<div class="single-item d-flex justify-content-between my-3 p-3">
<div class="single-item-text">
<h2 class="text-uppercase text-black">sushi</h2>
<h4 class="text-white">Lorem ipsum dolor sit amet.</h4>
</div>
<div class="single-item-price align-self-end">
<h1 class="text-uppercase text-black">$10</h1>
</div>
</div>
</div>
</div>
</div>
</section>
</header>
you can use max-width or min-width property to resize your background image for multiple devices. For example, for small devices, the media query will be
#media screen & (max-width:768px){
#img{
max-width: 100%;
}
}
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>
I am working on a budgeting app, and I am trying to make something that looks like a bunch of tiles (below). However I am getting stuck, because when I go to put content in the tiles, the content sticks to the bottom.
I am using bootstrap 4, and I have been able to make some square divs, and style them to my liking (thanks SO), but I just can't add anything to them. How would I solve this?
(also on a related/unrelated note when I put m-2 on the divs it bumps the rightmost div down a row)
.squareBox:before{
padding-top: 100%;
/* makes expand to a square */
content: '';
width: 0;
white-space: normal;
display: inline-block;
vertical-align: middle;
max-width: 100%;
}
.icon {
font-family: lato;
background: #1A3967;
border-radius: 10px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-6 mt-4">
<div class="row">
<div class="col-sm-4 squareBox icon m-2">
<div class="row">
<div class="col-xs-6">
<img src="https://s3.amazonaws.com/rkersey-test-assets/netflix.png" height="20px" />
</div>
</div>
</div>
<div class="col-sm-4 squareBox m-2">
first square box.
</div>
<div class="col-sm-4 squareBox m-2">
first square box.
</div>
</div>
</div>
<div class="col-md-6 mt-4"></div>
</div>
</div>
What it currently looks like:
What it needs to look like:
I would use a different method to make the boxes square. Use a margin "dummy" div, and place the squareBox inside the columns...
.dummy {
margin-top: 100%;
}
.squareBox {
background: #1A3967;
color: #fff;
border-radius: 10px;
position: absolute;
top: 30px;
bottom: 0;
left: 30px;
right: 0;
}
Then you can put whatever is needed inside each box, using Bootstrap 4 flexbox utils to position it.
Demo: https://www.codeply.com/go/MZrc2ELjIG
You could try the flexbox approach :)
.squareBox{
/* makes expand to a square */
width: 200px;
height: 200px;
white-space: normal;
display: inline-block;
vertical-align: middle;
max-width: 100%;
}
.icon {
font-family: lato;
background: #1A3967;
border-radius: 10px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
max-width: 200px;
}
.justify-start {
align-self: flex-start !important;
}
.t-1 {
font-size: 1.2rem;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<div class="m-5 d-flex justify-content-center align-items-center">
<div class="squareBox icon d-flex flex-column justify-content-between align-items-center m-2">
<div class="d-flex align-self-start justify-content-between w-100 p-2">
<img src="https://s3.amazonaws.com/rkersey-test-assets/netflix.png" height="20px" />
<p class="font-weight-bold text-muted">$XX.X</p>
</div>
<div class="d-flex justify-content-center align-items-center text-white text-center">
<p class="font-weight-bold t-1">Netflix & Hulu With roommcomm</p>
</div>
<div class="d-flex align-self-start justify-content-around w-100 text-white">
<p>Sorted</p>
<p>3</p>
</div>
</div>
<div class="squareBox icon d-flex flex-column justify-content-between align-items-center m-2">
<div class="d-flex align-self-start justify-content-between w-100 p-2">
<img src="https://s3.amazonaws.com/rkersey-test-assets/netflix.png" height="20px" />
<p class="font-weight-bold text-muted">$XX.X</p>
</div>
<div class="d-flex justify-content-center align-items-center text-white text-center">
<p class="font-weight-bold t-1">End of The F****** World</p>
</div>
<div class="d-flex align-self-start justify-content-around w-100 text-white">
<p>Sorted</p>
<p>5</p>
</div>
</div>
</div>
also, here's a working example :)
On a side note, I modified your squareBox class's width and height to give it dimensions :)
On the other hand, you can apply the flex-wrap class on the parent container so the stuff inside it that doesn't fit in a given row will go to the next row instead
You would want to set the icon to absolute and set to top with a bit of left and top offset.
If you're not gonna make these 'icon'-looking-things as image. then you have to rely heavily on absolute positioning.
.squareBox:before {
padding-top: 100%;
/* makes expand to a square */
content: '';
width: 0;
white-space: normal;
display: inline-block;
vertical-align: middle;
max-width: 100%;
}
.icon {
font-family: lato;
background: #1A3967;
border-radius: 10px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.icon .row {
position: absolute;
top: 5px;
left: 20px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-6 mt-4">
<div class="row">
<div class="col-sm-4 squareBox icon m-2">
<div class="row">
<div class="col-xs-6">
<img src="https://s3.amazonaws.com/rkersey-test-assets/netflix.png" height="20px" />
</div>
</div>
</div>
<div class="col-sm-4 squareBox m-2">
first square box.
</div>
<div class="col-sm-4 squareBox m-2">
first square box.
</div>
</div>
</div>
<div class="col-md-6 mt-4"></div>
</div>
</div>
Rather than using padding-top: 100%; to define the dimensions of square box
, add height and width.
.squareBox{
width: 100px;
height: 100px;
padding: 5px;
}
.icon {
font-family: lato;
background: #1A3967;
border-radius: 10px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-6 mt-4">
<div class="row">
<div class="col-sm-4 squareBox icon m-2">
<div class="row">
<div class="col-xs-6">
<img src="https://s3.amazonaws.com/rkersey-test-assets/netflix.png" height="20px" />
</div>
</div>
</div>
<div class="col-sm-4 squareBox m-2">
first square box.
</div>
<div class="col-sm-4 squareBox m-2">
first square box.
</div>
</div>
</div>
<div class="col-md-6 mt-4"></div>
</div>
</div>
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>
I want to draw a backround colour that fills an entire Bootstrap column and row. Currently the coloured area (element with id of html_overlay below) exactly matches the specified text width, not column width. Any ideas?
html:
<div class="container">
<div class="row">
<div class="col-sm-2 col-lg-1">.col-sm-2
<a class="btn btn-primary pull-left" id="br_button" href="do_something">Button</a>
</div>
<div class="col-sm-10 col-lg-11">outer .col-sm-10
<div class="col-sm-12 col-md-11">inner .col-sm-10
<div id='html_overlay'>
<div id="heading_area">
<h3>This entire column should have the background colour</h3>
</div>
<div class="wrapper" id="my_title"></div>
<div class="row">
<div class="col-xs-2 col-sm-2 col-md-3">
<div class="wrapper" id="l_space_area"></div>
</div>
<div class="col-xs-8 col-sm-8 col-md-7">
<div class="wrapper" id="text_area">
<h1 id="my_text"></h1>
</div>
</div>
<div class="col-xs-2 col-sm-2 col-md-3">
<div class="wrapper" id="r_space_area"></div>
</div>
</div>
</div>
<!-- overlay -->
</div>
<div class="col-sm-0 col-md-1">inner .col-sm-2</div>
</div>
<!-- outer second column -->
</div>
</div>
<!-- container -->
css:
body {
font-family: sans-serif;
background-color: #B3E5FC;
font-size: 100%
}
#container {
position: relative
}
#html_overlay {
position: absolute;
top: 0;
z-index: 100;
background-color: rgba(246, 250, 251, 0.9);
border: 1px solid;
border-color: rgba(0, 0, 0, 0.5);
}
#text_area {
z-index: 10;
bottom: 0;
}
Add left:0 and right:0 in class #html_overlay