The svg i have position is inside a container that occupies the bottom 40% of the page. This is because the lower half of the image is undesirable. However, as a side effect, the svg gets cut off near the text. I have tried overflow: visible; but hasn't worked. What else can I try? This is the code:
HTML (Bootstrap Used):
<header class="h-60 w-100 text-white hidden">
<div class="container-fluid h-100 w-100">
<div class="row h-100">
<div class="container d-flex align-items-center justify-content-center w-100 h-100">
<div class="col text-center w-100 heading">
<h1 class="reveal0">Ambrosia<h1>
<h3 class="reveal5">An Open-Source Website Theme</h3>
<br>
See My Other Work!
</div>
</div>
</div>
</div>
</header>
<div class="container-fluid h-40">
<div class="row h-100">
<div class="container d-flex align-items-center justify-content-center h-100">
<div class="col h-100 w-100 pic1">
</div>
<div class="col">
</div>
</div>
</div>
</div>
CSS:
.hidden {
overflow: hidden;
}
.pic1 {
position: fixed;
background: url("../img/pic1.svg");
background-position: center;
background-repeat: no-repeat;
background-attachment: scroll;
background-size: cover;
display: block;
margin: auto;
overflow: visible!important;
}
you can either use:
background-size: contain
which will make your image smaller, but without cutting it.
Or use:
background-position: top
to let it cut the bottom instead of the top
Related
I am working on writing the html for the above image with responsiveness. Below is my code for the design so far
HTML:
<div class="container-fluid">
<div
class="row low-height box border bg-light justify-content-start align-content-start overflow-box"
>
<div class="col-1 border bg-primary small-box m-2"></div>
<div class="col-1 border bg-primary small-box m-2"></div>
</div>
<div
class="row low-height box border bg-light justify-content-end align-content-end"
>
<div class="col-1 border small-box bg-success m-1"></div>
</div>
<div
class="row low-height box border bg-light justify-content-center align-content-center"
>
<div class="col-lg-12 text-center"><h4>Title</h4></div>
</div>
</div>
CSS:
.box {
height: 200px;
margin-bottom: 10px;
}
.small-box {
height: 100px;
}
.overflow-box {
overflow: auto;
}
Problem:
For the browser height lower than 600px, the 3 main sections should become horizontally arranged as shown in the below image.
This is the part I am unable to solve and cant find anything on the bootstrap site as well. May be I am doing something wrong fundamentally. Please help.
You can add a media query in your css,
#media(max-height:600px) {
//here you can write your custom css for that condition
//in this case,
[class*="col"]{
width:33%!important;
}
}
Here's an example
#media(max-height:600px) {
[class*="col"]{
width:33%!important;
}
}
.box {
text-align:center;
padding:5rem;
background-color: #22ccff;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<div class="container-fluid">
<div class="px-lg-12 px-md-12 px-sm-12">
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 mb-4">
<div class="box">Box-1
</div>
</div>
<div class="col-xl-12 col-lg-12 col-md-12 mb-4">
<div class="box">Box-2
</div>
</div>
<div class="col-xl-12 col-lg-12 col-md-12 mb-4">
<div class="box">Box-3
</div>
</div>
</div>
</div>
</div>
Instead of putting each of the three grey boxes in its own row, they should be cols within a responsive Boostrap grid.
I've updated your code to put each of those grey boxes in a <div class="col-4 col-sm-12" ...> to make them format to 3 columns on XS screens, and 1 column on all larger size screens per your request. (Although that's backwards from how responsive sites usually work: usually on the smallest screen size the grid collapses to one column, and on larger sizes the grid expands to more columns.)
.box {
height: 200px;
margin-bottom: 10px;
}
.small-box {
height: 100px;
}
.overflow-box {
overflow: auto;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="col-4 col-sm-12 low-height box border bg-light justify-content-start align-content-start overflow-box">
<div class="row">
<div class="col-1 border bg-primary small-box m-2"></div>
<div class="col-1 border bg-primary small-box m-2"></div>
</div>
</div>
<div class="col-4 col-sm-12 low-height box border bg-light">
<div class="row justify-content-end align-content-end">
<div class="col-1 border small-box bg-success m-1"></div>
</div>
</div>
<div class="col-4 col-sm-12 low-height box border bg-light justify-content-center align-content-center">
<div class="row">
<div class="col-lg-12 text-center">
<h4>Title</h4>
</div>
</div>
</div>
</div>
</div>
So I am trying to figure out, how I can set the size of the second Box (see screenshot) to the size of the background image. I am using bootstrap and it's build flex classes. Maybe you guys can help me out here.
Essentially what I would like to have is the purple box to be the same size of the background image and keep being the same size on resizing the screen.
To test things out, I provided a prepared Stackblitz environment: https://stackblitz.com/edit/javascript-rs3ykl?file=index.html
.page-container {
width: 100vw;
height: 50vh;
}
.background-image {
background: url('https://dummyimage.com/258x362/007aa5?text=Banner-Desktop-Large') center center / contain no-repeat;
height: 100%;
width: auto;
background-origin: content-box;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="page-container">
<div class="row w-100 h-100">
<div class="col-4 bg-primary">
<p>Box 1</p>
</div>
<div class="col-4">
<div class="background-image">
<div style="background: purple">
<div class="d-flex justify-content-around" style="color: rgb(255, 255, 255)">
<div class="d-flex flex-column">
<div>Tage</div>
<div>16086</div>
</div>
<div class="d-flex flex-column">
<div>Stunden</div>
<div class="">6</div>
</div>
<div class="d-flex flex-column">
<div>Minuten</div>
<div>13</div>
</div>
<div class="d-flex flex-column">
<div>Sekunden</div>
<div>34</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-4 bg-secondary">
<p>Box 3</p>
</div>
</div>
</div>
I think it's better to use image tag instead of url with div. so I changed it like this
<link
href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<style>
.page-container {
width: 100vw;
height: 50vh;
}
.background-image {
height: 100%;
width: auto;
background-origin: content-box;
}
.bk-image {
object-fit: cover;
width: 100%;
height: 100%;
}
</style>
<div class="page-container">
<div class="row w-100 h-100">
<div class="col-4 bg-primary"><p>Box 1</p></div>
<div class="col-4">
<div class="background-image">
<div style="background: purple">
<div class="d-flex justify-content-around" style="color: rgb(255, 255, 255)">
<div class="d-flex flex-column">
<div>Tage</div>
<div>16086</div>
</div>
<div class="d-flex flex-column">
<div>Stunden</div>
<div class="">6</div>
</div>
<div class="d-flex flex-column">
<div>Minuten</div>
<div>13</div>
</div>
<div class="d-flex flex-column">
<div>Sekunden</div>
<div>34</div>
</div>
</div>
</div>
<img class="bk-image" src = "https://dummyimage.com/258x362/007aa5?text=Banner-Desktop-Large">
</div>
</div>
<div class="col-4 bg-secondary"><p>Box 3</p></div>
</div>
</div>
and now the purple bar stays with the background picture, also since you used height 100% I did it too but if you want it to stay inline with the row you can set the height as the same as row height.
My example:
<div class="container">
<div class="d-flex justify-content-between">
<div class="col justify-content-center flex-column d-flex">
left
</div>
<div class="col justify-content-center flex-column d-flex right">
right
</div>
</div>
</div>
.container div {
height: 100px;
background-color: red;
}
a {
background-color: blue;
}
.right {
text-align: right;
}
Fiddle: https://jsfiddle.net/lawagabi/f7tp3x26/1/
How can I make text-align right in box with right without expanding it to the entire width?
Your .container div class is having an affect here. Wrap your anchor tag with a span with the right class to easily fix this.
<div class="container">
<div class="d-flex justify-content-between my-auto">
<div class="col justify-content-center flex-column d-flex">
left
</div>
<div class="col justify-content-center flex-column d-flex">
<span class="right">right</span>
</div>
</div>
</div>
Fiddle
I'm struggling to make the a row stretch to fill the rest of the available height. I tried adding h-100 to the row class but that causes a white space at the bottom of the screen. There must be a way to do it but I'm totally stumped.. Here is my code:
<div class="container-fluid h-100">
<div class="row justify-content-center h-100">
<div class="col-4 bg-red">
<div class="h-100">
<div class="row justify-content-center bg-purple">
<div class="text-white">
<div style="height:200px">ROW 1</div>
</div>
</div>
<div class="row justify-content-center bg-blue">
<div class="text-white">ROW 2</div>
</div>
</div>
</div>
<div class="col-8 bg-gray"></div>
</div>
</div>
codepen: https://codepen.io/ee92/pen/zjpjXW/?editors=1100
I'd like to make the the blue row (ROW 2) fill all the red space. Any suggestions?
Thanks
Use the Bootstrap 4.1 flex-grow-1 class...
https://codeply.com/go/Iyjsd8djnz
html,body{height:100%;}
.bg-purple {
background: rgb(48,0,50);
}
.bg-gray {
background: rgb(74,74,74);
}
.bg-blue {
background: rgb(50,101,196);
}
.bg-red {
background: rgb(196,50,53);
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container-fluid h-100">
<div class="row justify-content-center h-100">
<div class="col-4 bg-red">
<div class="h-100 d-flex flex-column">
<div class="row justify-content-center bg-purple">
<div class="text-white">
<div style="height:150px">ROW 1 - fixed height</div>
</div>
</div>
<div class="row justify-content-center bg-blue flex-grow-1">
<div class="text-white">ROW 2 - grow remaining height</div>
</div>
</div>
</div>
<div class="col-8 bg-gray"></div>
</div>
</div>
Update 4.3.1: Another example using the vh-100 utility class
https://codeply.com/go/h3bZbM6eSS
.bg-purple {
background: rgb(48,0,50);
}
.bg-gray {
background: rgb(74,74,74);
}
.bg-blue {
background: rgb(50,101,196);
}
.bg-red {
background: rgb(196,50,53);
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container-fluid">
<div class="row justify-content-center min-vh-100">
<div class="col-4 bg-red">
<div class="d-flex flex-column h-100">
<div class="row justify-content-center bg-purple">
<div class="text-white">
<div style="height:150px">ROW 1 - fixed height</div>
</div>
</div>
<div class="row justify-content-center bg-blue flex-grow-1">
<div class="text-white">ROW 2 - grow remaining height</div>
</div>
</div>
</div>
<div class="col-8 bg-gray"></div>
</div>
</div>
Related: How to make the row stretch remaining height
This is a solution. The wrapper div has to have h-100, the div that adapts to height has to have flex-grow-1 and overflow-auto. This way, the div will grow to fill the space when its content is minor than the available space and will show the scrollbar when its content is higher than the available space.
Demo jsfiddle
<div class="h-100 d-flex flex-column bg-yellow px-2">
<div class="flex-column justify-content-center bg-purple px-2">
<div class="text-white p-0" style="height:50px">HEADER</div>
</div>
<div class="flex-column justify-content-center bg-red text-white px-2 flex-grow-1 overflow-auto">
<div>Item1</div>
<div>Item2</div>
INNER text 1<br>
INNER text 2<br>
</div>
<div class="flex-column justify-content-center bg-darkblue px-2">
<div class="text-white p-0" style="height:50px">FOOTER</div>
</div>
If anyone has tired of getting this to work, here is a super easy solution which will work in most scenarios. Just add the below class to the div for which you are trying to fill the remaining height:
Please note that 100vh is 100% of visible height and 200px is the total fixed height of the remainging divs above.
.fillRemaining {
height: calc(100vh - 200px);
}
I cannot figure out why these column classes are not acting properly. They are vertically stacking. I am fairly new to boostrap, so I could be missing something obvious.
Any help would be appreciated. Thanks ahead of time.
HTML-
<div class="row content-container">
<div class="row top-nav">
<div class="row header">
<div class="col-lg-4 logo">
<img src="images/logo.png">
</div>
<div class="col-lg-8 nav-area">
<div class="row number">
888.888.8888
</div>
<div class="row navigation">
</div>
<div class="row heading">
</div>
</div>
</div>
<div class="row sub-nav">
</div>
</div>
<div class="row content-footer"></div>
</div>
SCSS-
.content-container{
position: relative;
background-image:url("images/border-vertical.png"), url("images/parchment-bg.jpg"), url("images/border-vertical.png");
background-position: top left, top center, top right;
background-origin: border-box, content-box, border-box;
background-repeat: repeat-y, repeat-y, repeat-y;
height: 1500px;
width: 972px;
margin: auto;
padding: 20px 56px 0 56px;
.nav-area{
position: relative;
.number{
background-image:url("images/phone-number-bg.png")
}
}
.content-footer{
background-image: url("images/border-horizontal.png");
background-repeat: repeat-x;
background-origin:content-box;
height: 31px;
width: 892px;
position: absolute;
bottom: 0px;
left: 40px;
}
}
First off, you don't need to put the class row in every div that contained your col-lg-*
But you can still stack them however you want though.
Example :
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-4">
...
</div>
</div>
</div>
</div>
As for your problem, you were right about the columns breaking up when you reach the min-width of col-lg-*. This is a feature of bootstrap. This prevents your columns shrinking so much that it becomes unreadable.
You could however, add the grid classes for smaller views. Like this:
<div class="row header">
<div class="col-md-4 col-lg-4 logo">
<img src="images/logo.png">
</div>
<div class="col-md-8 col-lg-8 nav-area">
<div class="row number">
888.888.8888
</div>
<div class="row navigation">
</div>
<div class="row heading">
</div>
</div>
</div>