I have a jumbotron with background image and text. I need to have the image adjust so that the text does not collide with any part of the background image.
HTML:
<div class="jumbotron">
<div class="container">
<h1>Header title text</h1>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. </p>
</div>
</div>
CSS:
.jumbotron {
position: relative;
background: #fff url("https://s3.us-east-2.amazonaws.com/ftp-assets/family.png") center center;
width: 100%;
height: 400px;
background-size: cover;
}
h1 {
margin-top: -30px;
margin-left: -20px;
}
p {
margin-left: -2%;
}
JSFIDDLE:https://jsfiddle.net/2ek2e2rf/
Try converting to something like this:
<div class="jumbotron jumbotron-fluid bg-dark">
<div class="jumbotron-background">
<img src="assets/background_img4.jpg" class="blur ">
</div>
<div class="container text-white" style="background-color: transparent; border: none;">
<h1>Some text</h1>
</div>
</div>
Then, you can adjust the background by changing the following properties:
.jumbotron-background {
top: 50px;
bottom: 50px;
left: 50px;
right: 50px;
}
Related
How do I add all the texts and buttons to display on the background img not below it?
Using Bootstrap 5.
<div class="container-fluid">
<div class="row landingPageBack img-responsive">
<img src="img/Landing.jpg" alt="">
<div class="text-center">
<h1>WELCOME</h1>
<h2>write me a msg</h2>
CONTACT ME
</div>
</div>
</div>
CUSTOM CSS
/* BG IMAGE*/
body html {
margin: 0;
padding: 0;
}
.landingPageBack {
background-image: url('img/Landing.jpg');
min-height : 100%;
min-width : 100%;
background-size: 100% 100%;
background-repeat:no-repeat;
overflow-y: hidden;
overflow-x: hidden;
}
/* BG IMAGE*/
.landingPageBack {
background-image: url('https://images.unsplash.com/photo-1637593755675-c38c18661a86?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1935&q=80');
background-size: cover;
background-repeat: no-repeat;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<section class="landingPageBack">
<div class="vh-100 vw-100 d-flex justify-content-center align-items-center">
<div class="text-center text-white">
<h1>WELCOME</h1>
<h2>write me a msg</h2>
CONTACT ME
</div>
</div>
</section>
<!-- begin snippet: js hide: false console: true babel: false -->
Please check the code, Hope it will help you.
Here are some links you should go through:
https://getbootstrap.com/docs/5.1/utilities/flex/
https://getbootstrap.com/docs/5.1/utilities/sizing/#relative-to-the-viewport
Make the wrapped container div position: relative. Then you can place the image inside and a text Block element. The text-blockelöement must be position: absolute. With the css attribute top and left, bottom, right you can position the text on the image.
/* Container holding the image and the text */
.container {
position: relative;
text-align: center;
color: red;
font-size: 5rem;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="container">
<img src="https://via.placeholder.com/500/green" alt="Snow" style="width:100%;">
<div class="centered">Centered</div>
</div>
And for your example, you would only have to adjust your two classes a bit.
/* BG IMAGE*/
body html {
margin: 0;
padding: 0;
}
.landingPageBack {
position: relative;
}
.text-center {
position: absolute;
top: 50%;
left: 40%
}
.landingPageBack {
background-image: url('https://via.placeholder.com/500/green');
background-repeat: no-repeat;
background-size: 100%;
}
<div class="container-fluid">
<div class="row landingPageBack img-responsive">
<img src="https://via.placeholder.com/500/green" alt="">
<div class="text-center">
<h1>WELCOME</h1>
<h2>write me a msg</h2>
CONTACT ME
</div>
</div>
</div>
I've been using bootstrap framework recently. I'm new to this framework.
so I'm trying to position an image next to some text in landing page. I use grid system of the bootstrap and it work. but when I come to push the image using position: absolute, and left:somePX, it make horizontal scroll and get out of the body of the page. what should I do to prevent this scrolling. I just want to cut the image and position it as I want.
Note: I've applied so many templates using only CSS with out bootstrap and I never get across on same problem.
thank you
here is my html code:
/* landing */
/*this is the image style*/
.landing {
padding-bottom: 100px;
margin-right: 0;
}
.landing .right .image {
position: relative;
}
.landing .right .image .back img {
position: absolute;
left: 100px;
}
.landing .right .image .mockups {
position: absolute;
top: -100px;
left: 100px;
}
/*this is text style I don't think the problem is here but I put it*/
.landing .left {
padding-top: 80px;
padding-left: 80px;
}
.landing .left h1 {
line-height: 1.3;
margin-bottom: 20px;
}
.landing .left p {
font-size: 15px;
margin-bottom: 20px;
}
.landing .left button {}
<div class="landing row">
<div class="col-md-6 left">
<div class="container">
<h1>Next generation digital banking</h1>
<p>Take your financial life online. Your Easybank account<br> will be a one-stop-shop for spending, saving,<br> budgeting, investing, and much more.</p>
<button class="btn linear" type="button">Request Invite</button>
</div>
</div>
<div class="col-md-6 right">
<div class="image">
<div class="back">
<img class="back-image img-fluid" src="images\bg-intro-desktop.svg" alt="">
</div>
<div class="front">
<img class="img-fluid mockups" src="images\image-mockups.png" alt="">
</div>
</div>
</div>
</div>
you can simply add to your body:
<style>
body{
overflow-x: hidden;
}
</style>
I am using Bootstrap and have a layout similar to this:
<div class="container stamp">
<div class="row">
Some header text
</div>
<div class="row" style="background-color:black">
More header text here
</div>
<div class="row">
More text
</div>
</div>
I've set the background image that overlaps all the three rows
.stamp {
background-image: url('img/hugestamp.gif');
background-repeat: no-repeat;
background-position: left top;
}
The hugestamp.gif spans across all the three rows but the second row has the background color of black, so part of the image is cut off. How do I make the image show up on top of the background color (maybe z-index?) on the 2nd row?
EDIT: I cannot make the colored row transparent. I am trying to achieve the styling here:
In the image, you can see the 3 rows and how the image is shown on top of the colored row
Try this code
Image over colored row
.stamp {
background-image: url('http://imgh.us/new-google-logo-knockoff.png');
background-repeat: no-repeat;
background-position: 0 -69px;
background-size: 100% auto;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
.container{
position:relative
}
<div class="container">
<div class="row">
Some header text
</div>
<div class="row" style="background-color:black">
More header text here
</div>
<div class="row">
More text
</div>
<div class="stamp"></div>
</div>
Image over colored row containing text
.stamp {
background-image: url('http://imgh.us/new-google-logo-knockoff.png');
background-repeat: no-repeat;
background-position: 0 -69px;
background-size: 100% auto;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 15;
}
.container{
position:relative
}
.row:nth-child(2):after {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: #000;
z-index: -20;
}
.row:nth-child(2) {
position: relative;
z-index: 10;
color: #fff;
}
<div class="container">
<div class="row">
Some header text
</div>
<div class="row">
More header text here
</div>
<div class="row">
More text
</div>
<div class="stamp"></div>
</div>
Image over colored row and below text
.stamp {
background-image: url('http://imgh.us/new-google-logo-knockoff.png');
background-repeat: no-repeat;
background-position: 0 -69px;
background-size: 100% auto;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -10;
}
.container{
position:relative
}
.row:nth-child(2):after {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: #000;
z-index: -20;
}
.row:nth-child(2) {
position: relative;
color: #fff;
}
<div class="container">
<div class="row">
Some header text
</div>
<div class="row">
More header text here
</div>
<div class="row">
More text
</div>
<div class="stamp"></div>
</div>
Avoid using inline css. You can do it by using transparent background color.
The transparency can be regulated by changing the last number of background-color property--
background-color: rgba(255, 0, 0, *0.4*);
Example snippet
.stamp {
background-image: url('https://www.w3schools.com/css/trolltunga.jpg');
background-repeat: no-repeat;
background-position: left top;
}
#blck {
background-color: rgba(0, 0, 0, 0.4);
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container stamp">
<div class="row">
Some header text
</div>
<div id="blck" class="row">
More header text here
</div>
<div class="row">
More text
</div>
</div>
Try this :
.container {
background: #EBEBEB;
padding: 10px;
}
.row {
background: white;
min-height: 100px;
background-image: url(http://www.clker.com/cliparts/T/j/X/6/y/m/grey-approved-stamp-hi.png);
background-position: left top;
background-repeat: no-repeat;
margin-bottom: 20px;
padding: 10px;
}
#top {
padding: 10px;
}
#second {
background-position: left calc(-180px + 20px + 20px);
/* left (-image height + middle row height + paddings) */
}
#third {
background-position: left calc(-180px - 30px);
/* left (-image height + middle row height + paddings) */
}
<div class="container stamp">
<div id = "first" class="row">
Some header text
</div>
<div id = "second" class="row" style="background-color:#3d3d3d; color: white; min-height: 50px;margin-bottom:0px;">
More header text here
</div>
<div id = "third" class="row">
More text
</div>
</div>
Here is a solution for your issue. Below i have added 2 inline style to your background color
<div class="container stamp">
<div class="row">
Some header text
</div>
<div class="row" style="background-color:black;z-index: -1;position: relative;">
More header text here
</div>
<div class="row">
More text
</div>
If want the text over the image and the background-color below it then its impossible because its a single component.
if want that row transparent just remove the inline css part
explain more the result you want to get please
If you don't want to change your HTML layout and do this just by altering css, you can set background image to pseudo elements :before of .stamp instead.
.stamp:before {
content: "";
position: absolute;
background-image: url(http://placehold.it/300);
background-repeat: no-repeat;
width: 100%;
height: 100%;
}
<div class="container stamp">
<div class="row">
Some header text
</div>
<div class="row" style="background-color:black">
More header text here
</div>
<div class="row">
More text
</div>
</div>
The z-index property specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order. Note: z-index only works on positioned elements (position:absolute, position:relative, or position:fixed).
I have a site that is a 1 page with different sections. On the first section I am adding a blue overlay over the first section using the below code:
<header class="text-center" name="home">
<div class="cover blue" data-color="blue"></div>
<div class="intro-text">
<h1 class="wow fadeInDown">Site Header</h1>
</header>
Here is the css for .cover.blue:
.cover{
position: fixed;
opacity: 1;
background-color: rgba(0,0,0,.6);
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 0;}
.cover.blue{
background-color: rgba(5, 31, 60, 0.6);
In the 2nd section I want to use an orange overlay but when I apply the div for the overlay the overlay on the 1st section is going in front of my text, buttons, etc and the color is changing to orange.
2nd section html:
<div id="about-section">
<div class="container">
<div class="cover orange" data-color="orange"></div>
<div class="section-title text-center wow fadeInDown">
<h2>Section 2</h2>
<hr>
<div class="clearfix"></div>
<h4>Choose</h4>
</div>
</div>
</div>
</div>
Css for .cover.orange
.cover{
position: fixed;
opacity: 1;
background-color: rgba(0,0,0,.6);
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 0;}
.cover.orange{
background-color: rgba(37, 28, 5, 0.6);}
What am I doing wrong?
Thanks for any input.
If i corectly understand what you want to do, you try to add 1 overlay by section, which you want to cover only his own section.
To do taht, I would choose to add a container for each section (to help standardize behaviour with classes) a use "absolute" positionning rather than "fixed".
.container {
position: relative;
z-index: 1;
}
.cover{
position: absolute;
opacity: 0.5;
background-color: grey;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 3;
}
.cover.blue{
background-color: blue;
}
.cover.orange{
background-color: orange;
}
<header class="text-center" name="home">
<div class="container">
<div class="cover blue" data-color="blue"></div>
<div class="intro-text">
<h1 class="wow fadeInDown">Site Header</h1>
</div>
</div>
</header>
<div id="about-section">
<div class="container">
<div class="cover orange" data-color="orange"></div>
<div class="section-title text-center wow fadeInDown">
<h2>Section 2</h2>
<hr>
<div class="clearfix"></div>
<h4>Choose</h4>
</div>
</div>
</div>
Note: your HTML snippets have issues : in the first, you forgot to close div, and in the second you close the last div twice.
What I need is simple, but I'm striking out.
I need to create three divs that are a perfect responsive square using vws.
Inside those div's I need div's with a background image that are also perfect squares when you scale your browser.
The catch is that I need the background image to always be a square as well, and resize accordingly so that none of the image is clipped off.
Here's a fiddle:
http://jsfiddle.net/Lm7qd/2/
<div class="image-wrapper">
<div class="image">
</div>
</div>
<div class="image-wrapper">
<div class="image">
</div>
</div>
<div class="image-wrapper">
<div class="image">
</div>
</div>
.image-wrapper {
width: 90vw;
height: 90vw;
border: 1px solid #ccc;
}
.image {
background-image: url('http://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Square_on_plane.svg/200px-Square_on_plane.svg.png');
background-repeat: no-repeat;
background-size:contain;
background-position:center;
background-size: 100%;
margin-bottom: 30px;
padding: 100px;
}
html
<div class="image-wrapper">
<div class="image">
<img src="http://3.bp.blogspot.com/--7gtJQo5mHE/UGMKHZapqmI/AAAAAAAAWGU/5X26Pgj_St4/s1600/funny-cat-pictures-017-005.jpg"/>
</div>
<div class="image">
<img src="http://3.bp.blogspot.com/--7gtJQo5mHE/UGMKHZapqmI/AAAAAAAAWGU/5X26Pgj_St4/s1600/funny-cat-pictures-017-005.jpg"/>
</div>
<div class="image">
<img src="http://3.bp.blogspot.com/--7gtJQo5mHE/UGMKHZapqmI/AAAAAAAAWGU/5X26Pgj_St4/s1600/funny-cat-pictures-017-005.jpg"/>
</div>
css
.image-wrapper {
width: 90vw;
height: 90vw;
border: 1px solid #ccc;
}
.image {
margin-bottom: 30px;
width: 100%;
}
.image img {
width: 100%;
}
http://jsfiddle.net/Lm7qd/12/
I'm not sure if this is what you are looking for because the only square i see here is the image-wrapper. Please check this out.
Fiddle
if this is not what you are looking for, can you post some of the images of your desired output.