Bootstrap 3 Bleed left and right background images to edge of browser - css

This is what I'm trying to achieve. The top box with a background image that spans the whole browser width, and 2 content boxes inside centered. I've done that no problem.
I then need want 2 more boxes underneath, again centered, but each half needs a different backgkround image that should meet in the middle and bleed of to their respective edge. I am using bootstrap becuase I want these to stack on smaller screens. I can't figure out how this is possible. the black border represents the container. I can wrap the top bit in its own container which is fine, but I can't work out how to get the bottom bit to work, and I don't really want to use absolute positioning because it'll be a nightmare to get the responsive element to work.
Here is what I have so far
HTML:
<div class="fluid-full">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-6 left-half">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
<div class="col-md-6 right-half">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
</div>
</div>
CSS:
.example{
height: 200px;
border: 1px;
background-color: rgba(0,0,0,0.8);
padding: 30px;
border: 1px solid white;
color: white;
}
.fluid-full{
padding: 40px 0;
background-image: url(http://lorempixel.com/1920/400);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.left-half{
border-left: 25% solid transparent;
background-image: url(http://lorempixel.com/g/1000/400);
background-position: right;
background-repeat: no-repeat;
background-size: cover;
}
Checkout this Bootply
I need the top and bottom boxes to line up.
Any help appreciated.

I took you Bootply example and modified bottom bit to this:
<div class="col-md-6 fluid-half">
<div class="example col-md-6 pull-right">
<h1 class="text-center">LEFT</h1>
</div>
</div>
<div class="col-md-6 fluid-half">
<div class="example col-md-6 pull-left">
<h1 class="text-center">RIGHT</h1>
</div>
</div>
Here's the Bootply modification
Is this something you're trying to achieve?

OK, I've done it. Had to use some media queries.
HTML:
<div class="fluid-full">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid about-us">
<div class="row">
<div class="col-md-6">
<div class="sec-title text-center work-with-us">
<h2>Work With Us</h2>
</div>
</div>
<div class="col-md-6">
<div class="sec-title text-center what-we-do">
<h2>What We Do</h2>
</div>
</div>
</div>
</div>
CSS
.example{
height: 200px;
border: 1px;
background-color: rgba(0,0,0,0.8);
padding: 30px;
border: 1px solid white;
color: white;
}
.fluid-full{
padding: 40px 0;
background-image: url(http://lorempixel.com/1920/400);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.about-us .col-md-6 {
background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(http://lorempixel.com/g/1000/400);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
padding: 70px 0;
}
.about-us .col-md-6 .sec-title {
margin-bottom: 0;
margin: 0 15px;
background-color: rgba(0, 0, 0, 0.8);
border: 1px solid white;
}
.about-us .col-md-6 .sec-title h2 {
color: #FFFFFF;
}
.about-us .col-md-6 .sec-title h2::after {
width: 70px;
}
#media (min-width: 768px) {
.about-us .col-md-6 .sec-title {
width: 720px;
margin: 20px auto;
}
}
#media (min-width: 992px) {
.about-us .col-md-6 .sec-title {
width: 455px;
margin: 0 15px;
}
}
#media (min-width: 1200px) {
.about-us .col-md-6 .sec-title {
width: 555px;
}
}
#media (min-width: 992px) {
.about-us .col-md-6 .work-with-us {
float: right;
}
}
Here is the bootply
Hopefully this might be useful to someone else too.

Related

How do I get rid of this extra space below this column when using bootstrap 5?

I made the changes as you described but when I check to see how it would look on the phone the blue box and the pink box are separated which I want to be together. I have attached a screenshot of how it looks and I want it to look similar to the desktop version.
I am not sure which entity might be causing this issue.
--EDIT--
Just to provide more clarity here is a screenshot of how the container_tag and container_box should look in the mobile screen (365px).
Should look like this
Is looking like this
.side_feedback{
background-color: pink;
padding: 10px;
height: 300px;
width: 180px;
border-radius: 10%;
margin-left: 17px;
}
.container_tag{
background-color: royalblue;
min-height: 200px;
max-width: 2rem;
border: 6px solid royalblue;
float: left;
}
.tag{
transform: rotate(-90deg);
position: relative;
top: 8rem;
}
.container_box{
background-color: pink;
min-height: 200px;
border-left: 6px solid white;
width: 95%;
position: relative;
float: left;
}
<div class="container-fluid">
<div class="row mb-4 g-5">
<div class="order-2 order-sm-1 col-lg-2 col-md-2 col-xs-10">
<div class="col-md">
<div class="side_feedback">
<p>Give us feedback!</p>
</div>
</div>
</div>
<div class="order-1 order-sm-2 col-10">
<div class="row row-cols-1 row-cols-sm-1 row-cols-md-1 row-cols-lg-1 row-cols-auto g-4">
<div class="col-12">
<div class="container_tag">
<h3 class="tag">TEXT</h3>
</div>
<div class="container_box">
</div>
</div>
<div class="col-12">
<div class="container_tag">
<h3 class="tag">TEXT</h3>
</div>
<div class="container_box">
</div>
</div>
<div class="col-12">
<div class="container_tag">
<h3 class="tag">TEXT</h3>
</div>
<div class="container_box">
</div>
</div>
</div>
</div>
</div>
If you’re referencing the large vertical white space below the two pink blocks, that’s there because you’re using position: relative on the pink container_box. position: relative positions the element normally (below your container_tag div) and then moves the element to the new position — the original space remains.
To get rid of the white space, add float: left to the styles for both of your containers.
.container_tag {
background-color: royalblue;
min-height: 180px;
width: 9%;
max-width: 3.2rem;
float: left;
position: relative;
}
.tag {
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%) rotate(-90deg)
}
.container_box {
background-color: pink;
min-height: 180px;
border-left: 6px solid white;
width: 91%;
position: relative;
float: left;
}
#media (min-width:768px) {
.container_box {
width: calc(100% - 3.2rem);
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-12 col-sm-10 px-0">
<div class="row gx-0">
<div class="col-12 mb-3">
<div class="container_tag">
<h3 class="tag">Text</h3>
</div>
<div class="container_box">
</div>
</div>
<div class="col-12 mb-3">
<div class="container_tag">
<h3 class="tag">Text</h3>
</div>
<div class="container_box">
</div>
</div>
</div>
</div>
</div>
</div>
One other note - you don't need to give the same column class for different breakpoints (col-lg-10 col-md-10 col-xs-10). Just use col-10 and that will apply to all of the following breakpoints. And BS-5 doesn't use xs - that was for Bootstrap 3.

How to make a gradient continue in other divs

I would like my gradient to pass on to the next div. Putting one div behind them with the gradient would probably work, but on my website the elements are not exactly next to eachother
.row {
clear: both;
}
.portrait {
width: 200px;
height: 200px;
background-color: red;
float: left;
}
.photo {
width: 200px;
height: 150px;
background-color: blue;
}
.gradient {
width: 200px;
height: 50px;
background-color: green;
}
<div class="row">
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
</div>
<div class="row">
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
</div>
Codepen:
https://codepen.io/chingwai/pen/poEGxBe
To explain my structure:
.portrait = is the container, this is dynamically created based on my database.
.photo = will be a profile photo
.gradient = This is where the gradient should come and continue to the other divs that contain .gradient As you can see .photo will be between the divs, so they are not postioned under eachother.
Give all the divs you want to be with the gradient BG:
background-image: linear-gradient(your choice);
background-repeat: no-repeat;
background-attachment: fixed;
.child{
height:120px;
width:120px;
border:solid 2px white;
background-image: linear-gradient(to right,pink,green);
background-repeat: no-repeat;
background-attachment: fixed;
}
.parent{
display:flex;
width: 250px;
}
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
EDIT
After your explanations on the comments and post edits. Do this:
.gradient{
width: 200px;
height: 50px;
background-image:linear-gradient(to right, blue, lightblue);
background-attachment:fixed;
}

Banner image not shown in angular page

I am still learning about angular so I might not have the best design, but anyways I get confused not being so sure where my css should be. I have src/index.html, styles.css and src/app/app.component.html, app.component.html. I am trying to customize home.component.html, no home.component.css has been implemented. On .parallax-container I am trying to show an image, but not showing as a background image.
src/styles.css
div.sm-jumbotron {
padding: 2rem;
background-color: #38547b;
color: #ffffff;
}
button.btn-submit {
background-color: #38547b;
color: #ffffff;
width: 100%;
}
button.btn-submit:focus, button.btn-submit:hover {
background-color: #38547b;
}
input.ng-invalid.ng-dirty {
border-bottom-color: #e91e63 !important;
box-shadow: 0 1px 0 0 #e91e63 !important;
}
nav ul a,
nav .brand-logo {
color: #444;
}
p {
line-height: 2rem;
}
.sidenav-trigger {
color: #26a69a;
}
.parallax-container {
min-height: 380px;
line-height: 0;
height: auto;
color: rgba(0, 0, 0, 0.9);
}
.parallax-container .section {
width: 100%;
}
#media only screen and (max-width : 992px) {
.parallax-container .section {
position: absolute;
top: 40%;
}
#index-banner .section {
top: 10%;
}
}
#media only screen and (max-width : 600px) {
#index-banner .section {
top: 0;
}
}
.icon-block {
padding: 0 15px;
}
.icon-block .material-icons {
font-size: inherit;
}
footer.page-footer {
margin: 0;
}
app.component.html
<div class="container" [style.margin-top.px]="navbarTopMargin">
<app-nav (navHeight)="onNavHeight($event)"></app-nav>
</div>
<div id="container">
<div class="my-custom-container" [style.margin-top.px]="routerOutput">
<router-outlet></router-outlet>
</div>
</div>
home.component.html
<div id="index-banner" class="parallax-container">
<div class="section no-pad-bot">
<div class="container">
<br><br>
<h1 class="header center teal-text text-lighten-2">Join Us</h1>
<div class="row center">
<h3 class="header col s12 light">We sell and deliver products to customers that will improve health.</h3>
</div>
<div class="row center">
Get Started
</div>
</div>
</div>
<!--Show this image-->
<div class="parallax"><img src="https://mdbootstrap.com/img/Photos/Others/architecture.jpg" alt=""></div>
</div>
<div class="container">
<div class="section">
<div class="row">
<div class="col s12 m4">
<div class="icon-block">
<h2 class="center brown-text"><i class="material-icons">flash_on</i></h2>
<h3 class="center">Fast delivery</h3>
<p class="light">
We are the fastest delivery service in America.
</p>
</div>
</div>
<div class="col s12 m4">
<div class="icon-block">
<h2 class="center brown-text"><i class="material-icons">group</i></h2>
<h3 class="center">Top quality</h3>
<p class="light">
We make sure the quality is great.
</p>
</div>
</div>
<div class="col s12 m4">
<div class="icon-block">
<h2 class="center brown-text"><i class="material-icons">location_city</i></h2>
<h3 class="center">Trusted company</h3>
<p class="light">
This company has received 98% satisfaction.
</p>
</div>
</div>
</div>
Please try this css in your style.css:
.parallax-container .parallax{
position: static;
}
.parallax-container .parallax img{
position: static;
transform: none;
display: block;
max-width: 100%;
}

Center text over a flex element

I am trying to build a custom stepper with CSS and I am hitting a wall to center the label on top of each step.
I've build a quick and simplified version of my current implementation :
.wrapper {
display: flex;
}
.circle-wrapper {
flex: 1;
}
.circle-wrapper.active>.circle {
background-color: #3490DC;
transform: scaleX(1.2) scaleY(1.2)
}
.circle-wrapper.complete>.circle {
background-color: #38C172;
}
.circle {
width: 34px;
height: 34px;
background-color: #B8C2CC;
border-radius: 100%;
}
.label {
margin-bottom: 10px;
}
.wrapper> :last-child {
flex: none;
}
.line {
height: 4px;
width: 100%;
background-color: #1F9D55;
position: relative;
bottom: 19px;
}
<div class="wrapper">
<div class="circle-wrapper complete">
<div class="label">Label 1</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper active">
<div class="label">Label 2 with a longer name</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper">
<div class="label">Label 3</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper">
<div class="label">Label 4</div>
<div class="circle"></div>
</div>
</div>
You can see it here in this codepen
So far so good, but I want to center the label over the circle div without impacting the flex size between each circle and I can't manage to do it.
Any advice ?
You can use a left and a transform to move it into the centre:
.wrapper {
display: flex;
}
.circle-wrapper {
flex: 1;
position:relative;
}
.circle-wrapper.active>.circle {
background-color: #3490DC;
transform: scaleX(1.2) scaleY(1.2)
}
.circle-wrapper.complete>.circle {
background-color: #38C172;
}
.circle {
width: 34px;
height: 34px;
background-color: #B8C2CC;
border-radius: 100%;
}
.label {
position:relative;
left: 17px; /* move left 17px (half of circle width) */
margin-bottom: 10px;
transform: translateX(-50%); /* move it backwards 50% of itself */
text-align: center; /* align text in centre */
}
.wrapper> :last-child {
flex: none;
}
.line {
height: 4px;
width: 100%;
background-color: #1F9D55;
position: relative;
bottom: 19px;
}
<div class="wrapper">
<div class="circle-wrapper complete">
<div class="label">Label 1</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper active">
<div class="label">Label 2 with a longer name</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper">
<div class="label">Label 3</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper">
<div class="label">Label 4</div>
<div class="circle"></div>
</div>
</div>
If you want to center it always above the circle, I would use the following: put the label inside the circle and use the following CSS properties:
.circle {
position: relative;
width: 34px;
height: 34px;
background-color: #B8C2CC;
border-radius: 100%;
margin: 50px 100px; /* remove this */
}
.circle .label {
position: absolute;
left: 50%;
bottom: 100%;
transform: translateX(-50%);
white-space: nowrap;
}
<div class="circle">
<div class="label">Small One</div>
</div>
<div class="circle">
<div class="label">Very long label with long text</div>
</div>
The percentage values of left and bottom reference to the width of the parent element and the percentage value of transform: translate references to the element's size. This allows you to position it in the center of the parent with left: 50% and then moving it to the left again by the half of the width of the element itself.

Place float elements in a row in div container

I'm trying to place a calender inside a transparent div container, however I'm having some issues, i want each calender box to form a row that takes up 100% in width in the transparent box. So basically at the moment the page looks like this:
screenshot.
What you probably noticed is if you look at container with the "click on the images text" is that the box is wider than the rows under it.
This is the CSS code for the calender: Basically everything relating to .transbox has something to do with the transparent box. The calender days are the classes .weekdayssttart and weekdays. The remaining classes are the calender days with numbering. So since there is 7 days a week i just thought that I had to divide 100/7 which is 14.2857142857 and set each box type to that width in percentage. However this is the result i get: screenshot2. What I obviously notice is that the row is to small to contain the calender boxes, does anyone have an idea to fix this? Sorry for my bad english.
.transbox {
background: #fff;
padding: 2%;
width: 70%;
margin-left: 15%;
margin-bottom: 1%;
position: relative;
background-color:rgba(255,255,255,.9);
border-radius: 5px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,.9);
overflow: auto;
}
.transbox p {
color: darkslategray;
margin-bottom: 2%;
font-size:13px;
}
.transbox img {
width:100%;
height: 100%;
}
.weekdaysstart {
width: 14%;
height: 20px;
background-color:floralwhite;
border: 1px solid darkslategrey;
text-align:center;
float: left;
}
.weekdays {
width: 14%;
height: 20px;
background-color:floralwhite;
border: 1px solid darkslategrey;
text-align:center;
float: left;
}
.hint {
width: 99%;
height: 20px;
background-color:floralwhite;
border: 1px solid darkslategrey;
text-align:center;
padding-top: 5px;
}
.one {
background-color: floralwhite;
width: 14%;
height: 100px;
float: left;
border: 1px solid darkslategrey;
color: darkslategrey;
}
.nextrow {
background-color: floralwhite;
width: 14%;
height: 100px;
float: left;
clear:left;
border: 1px solid darkslategrey;
color: darkslategrey;
}
.nextmonth {
background-color: floralwhite;
width: 14%;
height: 100px;
float: left;
border: 1px solid darkslategrey;
color: darkslategrey;
}
.lastrow {
width: 14%;
height: 100px;
float: left;
border: 1px solid darkslategrey;
color: darkslategrey;
background-color: floralwhite;
margin-bottom:2%;
}
.pancakes {
width: 14%;
height: 100px;
float:left;
background: url(images/pancakes.jpeg);
background-size: cover;
border: 1px solid darkslategrey;
}
.meatballs {
width: 14%;
height: 100px;
float:left;
border: 1px solid darkslategrey;
background: url(images/kotbulls.jpg);
background-size: cover;
}
<!DOCTYPE html>
<html>
<head>
<title>Tasty recipes</title>
<link href="reset.css" rel="stylesheet" type="text/css">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body>
<ul>
<li>HOME</li>
<li>RECIPES</li>
<li>CALENDAR</li>
<li class="tastyrecipes">Tasty Recipes</li>
</ul>
<h1>Calendar</h1>
<h3>November 2017</h3>
<div class = "transbox">
<div class="hint">
<p>Click on the image of a dish to go to its recipe-page.</p>
</div>
<div class="weekdaysstart">
<p>Monday</p>
</div>
<div class="weekdays">
<p>Tuesday</p>
</div>
<div class="weekdays">
<p>Wednesday</p>
</div>
<div class="weekdays">
<p>Thursday</p>
</div>
<div class="weekdays">
<p>Friday</p>
</div>
<div class="weekdays">
<p>Saturday</p>
</div>
<div class="weekdays">
<p>Sunday</p>
</div>
<div class="nextrow">
<p>30</p>
</div>
<div class="one">
<p>31</p>
</div>
<div class="one">
<p>1</p>
</div>
<div class="one">
<p>2</p>
</div>
<div class="one">
<p>3</p>
</div>
<div class="one">
<p>4</p>
</div>
<div class="one">
<p>5</p>
</div>
<div class="nextrow">
<p>6</p>
</div>
<a href="meatballs.html">
<div class="meatballs">
<p>7</p>
</div>
</a>
<div class="one">
<p>8</p>
</div>
<div class="one">
<p>9</p>
</div>
<div class="one">
<p>10</p>
</div>
<div class="one">
<p>11</p>
</div>
<div class="one">
<p>12</p>
</div>
<div class="nextrow">
<p>13</p>
</div>
<div class="one">
<p>14</p>
</div>
<div class="one">
<p>15</p>
</div>
<div class="one">
<p>16</p>
</div>
<div class="one">
<p>17</p>
</div>
<div class="one">
<p>18</p>
</div>
<div class="one">
<p>19</p>
</div>
<div class="nextrow">
<p>20</p>
</div>
<div class="one">
<p>21</p>
</div>
<div class="one">
<p>22</p>
</div>
<div class="one">
<p>23</p>
</div>
<div class="one">
<p>24</p>
</div>
<a href="pancakes.html">
<div class="pancakes">
<p>25</p>
</div>
</a>
<div class="one">
<p>26</p>
</div>
<div class="nextrow">
<p>27</p>
</div>
<div class="lastrow">
<p>28</p>
</div>
<div class="lastrow">
<p>29</p>
</div>
<div class="lastrow">
<p>30</p>
</div>
<div class="nextmonth">
<p>1</p>
</div>
<div class="nextmonth">
<p>2</p>
</div>
<div class="nextmonth">
<p>3</p>
</div>
</div>
</body>
</html>
Like Matthew JohnSon said, you could do this using flexbox. I'm not totally sure, but I believe the calc() function will let it fit.
.transbox {
width: 100%;
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
}
.weekdaysstart, .weekdays {
width: calc(100% / 7);
}
Edit
I changed the names of the classes to those of your html classes.
You should use a clearfix container per each row.
https://css-tricks.com/snippets/css/clear-fix, and try to use flex instead of float, set each .row display: flex, and then set flex-grow: 1; flex-shrink: 1; flex-basis: auto; to the elements inside the row.

Resources