Add text to background image using CSS - html

I am using a background image on a section which covers the whole screen while the section is in view. Then it is covered up by subsequent sections as the page scrolls.
#section1{
background: URL(../SiteData/Images/SectionBackground.jpg) no-repeat center top fixed #f1ece2;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
min-height:800px;
}
I want to add text about half way down this image. This I can do, but I want it to stay in position, as if it was actually part of the image. So when the screen scrolls up, the text gets hidden rather than scrolls to the top - so it stays in position on the image.
How would I do this?
Thanks

Here is a demo answer for make them both image and text responsive Live On FIDDLE. Try this but not just copy paste. Try to understand the css how this text over the image. If you have any questions ask me in comment. Best of luck.
.img-reponsive {
display: block;
max-width: 100%;
height: auto;
margin: 0 auto;
}
.textoverimage {
position: relative;
}
p.title {
position: absolute;
top: 75px;
left: 0;
text-align: center;
font-size: 38px;
width: 100%;
color: #fff
}
#media only screen and (max-width: 767px) {
p.title {
font-size: 1.5em;
line-height: 1.5em;
}
}
#media only screen and (max-width: 479px) {
p.title {
font-size: 1.1em;
line-height: 1.1em;
}
}
<div class="textoverimage">
<img class="img-reponsive" src="http://cdn.shopify.com/s/files/1/0258/1101/t/2/assets/slideshow_3.jpg?5808719635421587686" alt="demo_img">
<p class="title"> TEXT </p>
</div>

bootstrap 4
<section class="vh-100" style="
background: url(public/images/aimage.png) no-repeat center center fixed;
background-size: 100%;
">
<div class="container h-100 d-flex ">
<div class="row my-auto ">
<div class="col-lg-3 col-sm-12">
<div class="jumbotron ">
<h1 class="display-3">Hello, world!</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Exercitationem fuga, molestiae illo pariatur praesentium nemo nam magnam molestias eius at! Cupiditate ratione natus veritatis eaque totam illo accusamus perferendis? Enim?</p>
</div>
</div>
<div class="col-lg-3 col-sm-12">
<div class="jumbotron ">
<h1 class="display-3">Hello, world!</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Exercitationem fuga, molestiae illo pariatur praesentium nemo nam magnam molestias eius at! Cupiditate ratione natus veritatis eaque totam illo accusamus perferendis? Enim?</p>
</div>
</div>
<div class="col-lg-3 col-sm-12">
<div class="jumbotron ">
<h1 class="display-3">Hello, world!</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Exercitationem fuga, molestiae illo pariatur praesentium nemo nam magnam molestias eius at! Cupiditate ratione natus veritatis eaque totam illo accusamus perferendis? Enim?</p>
</div>
</div>
<div class="col-lg-3 col-sm-12">
<div class="jumbotron ">
<h1 class="display-3">Hello, world!</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Exercitationem fuga, molestiae illo pariatur praesentium nemo nam magnam molestias eius at! Cupiditate ratione natus veritatis eaque totam illo accusamus perferendis? Enim?</p>
</div>
</div>
</div>
</div>
</section>

Related

Bootstrap section stacking with above section on mobile screen size

I am having a problem. Everything seemed perfect when I finished section-3, but when I started coding section-4, it started stacking on section-3's content.
Code
HTML
<!-- Start Of SECTİON TREE !-->
<section class="section-3" id="sec3">
<div class="tribg">
<img src="Parts/triangles.png" alt="" class="img-fluid">
</div>
<div class="container-fluid">
<div class="row">
<div class="card-deck">
<div class="col-md-4">
<div class="card mycards">
<img src="Parts/shield.png" alt="" class="img-fluid" width="50px">
<div class="card-body">
<h3 class="card-title">DENEME</h3>
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint expedita alias, dolorem sapiente culpa distinctio libero saepe. Recusandae numquam aut aliquam, ullam voluptatum placeat quis omnis perspiciatis, distinctio quae eaque nemo consequatur ratione mollitia beatae alias molestiae quod optio ipsa. Totam assumenda, aperiam quae!</p>
<div class="btn btn-primary">DENEME</div>
</div>
</div>
<div class="col-md-4">
<div class="card mycards">
<img src="Parts/shield.png" alt="" class="img-fluid" width="50px">
<div class="card-body">
<h3 class="card-title">DENEME</h3>
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint expedita alias, dolorem sapiente culpa distinctio libero saepe. Recusandae numquam aut aliquam, ullam voluptatum placeat quis omnis perspiciatis, distinctio quae eaque nemo consequatur ratione mollitia beatae alias molestiae quod optio ipsa. Totam assumenda, aperiam quae!</p>
<div class="btn btn-primary">DENEME</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card mycards">
<img src="Parts/shield.png" alt="" class="img-fluid" width="50px">
<div class="card-body">
<h3 class="card-title">DENEME</h3>
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint expedita alias, dolorem sapiente culpa distinctio libero saepe. Recusandae numquam aut aliquam, ullam voluptatum placeat quis omnis perspiciatis, distinctio quae eaque nemo consequatur ratione mollitia beatae alias molestiae quod optio ipsa. Totam assumenda, aperiam quae!</p>
<div class="btn btn-primary">DENEME</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- End Of SECTİON TREE !-->
<!-- Start Of SECTİON FOUR !-->
<section class="section-4">
<div class="holder"><img src="Parts/shape9.png" alt="" class="img-fluid"></div>
</section>
<!-- End Of SECTİON FOUR !-->
CSS
/* SECTİON TREE */
.section-3 {
position: relative;
height: 100vh;
}
.tribg {
position: absolute;
top: 30%;
left: 20%;
z-index: 0;
}
.mycards {
padding: 60px 100px;
margin-top: 8rem;
border-radius: 63px;
box-shadow: 6px 7px 100px rgba(0, 0, 0, 0.16);
transition: .3s;
}
.mycards p {
margin-bottom: 6rem;
}
.cardimg {
margin-bottom: 30px;
}
.mycards:hover {
transform: translateY(-30px);
}
.gotopanel {
font-size: 20px;
}
/* End Of SECTİON TREE */
/* SECTİON FOUR */
.section-4 {
height: 100vh;
}
The problem is in your css, remove or change height property here:
.section-3 {
position: relative;
height: 100vh;
}
.section-4 {
height: 100vh;
}

3 columns overlapping the footer on mobile browser

Footer is on right place but the columns in section are overlapping the footer
.columns {
float:left;
width: 22%;
height: 30%;
margin-left:8%;
}
Instead of float:left; I have used display:inline-block; but issue
not resolved this problem is occurring when website displayed on
mobile. When viewed on desktop it's working fine.
Try adding this to your CSS
box-sizing: border-box;
.container {
background: #f4f4f4;
padding: 5%;
margin: 5%;
}
.column1 {
background: #b40404;
padding: 5%;
color: #fff;
}
.column2 {
background: #000;
padding: 5%;
color: #fff;
}
.column3 {
background: #b40404;
padding: 5%;
color: #fff;
}
<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-4">
<div class="column1">
This is column 1<br><br> Lorem ipsum, dolor sit amet consectetur adipisicing elit. Doloribus vero labore obcaecati illum reprehenderit incidunt consequatur quidem, id repellendus impedit, quaerat, mollitia ea culpa sint? Totam sunt omnis quis
eaque.
</div>
</div>
<div class="col-md-4">
<div class="column2">
This is column 2<br><br> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Laudantium mollitia, incidunt accusantium iure eius suscipit fugit tempore veniam deleniti, nulla dolore repudiandae voluptas, eaque architecto ratione recusandae
consectetur officia. Saepe.
</div>
</div>
<div class="col-md-4">
<div class="column3">
This is column 3<br><br> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quis vitae nulla, beatae tenetur ea eaque obcaecati perspiciatis, architecto nemo culpa id non facilis distinctio aliquam. Accusamus voluptatum mollitia perferendis
libero.
</div>
</div>
</div>
</div>
you can use Bootstrap. Use the class container then row and define columns inside it. Like this:

Remove gap between <h1> and <p>?

How would I remove a gap between a h1 and p element? I've tried removing the padding and margins with no luck. I'm using the default bootstrap css. Any ideas?
.section1{
background-color: bisque;
}
p, h1 {
margin: 0px;
padding: 0px;
}
<div class="section1">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1 class="page-header">About</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, explicabo dolores ipsam aliquam inventore corrupti eveniet quisquam quod totam laudantium repudiandae obcaecati ea consectetur debitis velit facere nisi expedita vel?</p>
</div>
</div>
</div>
</div>
I've attached a screenshot to this post as it appears correctly when I run the code using stackoverflows 'run snippet' feature.
The page-header bootstrap class is causing the space reset it using:
h1.page-header {
margin: 0;
padding: 0;
}
See demo below:
.section1 {
background-color: bisque;
}
p,
h1 {
margin: 0px;
padding: 0px;
}
h1.page-header {
margin: 0;
padding: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div class="section1">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1 class="page-header">About</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, explicabo dolores ipsam aliquam inventore corrupti eveniet quisquam quod totam laudantium repudiandae obcaecati ea consectetur debitis velit facere nisi expedita vel?</p>
</div>
</div>
</div>
</div>
Add line-height to h1 class in your CSS. If font size is 26px, just ad 26px line height.
like:
h1.page-header{
font-size:26px;
line-height:26px;
}
Try line-height to it
.section1 {
background-color: bisque;
line-height: 15px;
}
p,
h1 {
margin: 0px;
padding: 0px;
}
.page-header{
margin:0 !important;
padding:0 !important;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="section1">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1 class="page-header">About</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, explicabo dolores ipsam aliquam inventore corrupti eveniet quisquam quod totam laudantium repudiandae obcaecati ea consectetur debitis velit facere nisi expedita vel?</p>
</div>
</div>
</div>
</div>
You need to reset css first. Because Browser has format CSS itself
{
margin: 0px;
padding: 0px;}
Add this above your css file

CSS : Scroll two div side by side independently

I have two columns and certain contents in both the columns.
I want a scroll to the each div when content is bigger.
I have fixed header and when I scroll then two divs is also scrolling.
I want only one div to be scrolled whenever I want to do so.
.b-r{
border-right: thin black solid;
}
.margin_top_600px{
margin-top:600px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 b-r padding_bottom_70" >
<p class="margin_top_600px">
Left side Data
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 b-r padding_bottom_70" >
<p class="margin_top_600px">
Right side Data
</p>
</div>
</div>
If I want to scroll for only left side data then only that div should scroll.
Any help would be great.
Thank you.
You need to set height and overflow: auto; to .b-r:
.b-r{
border-right: thin black solid;
height: 100vh;
overflow: auto;
}
.margin_top_600px{
margin-top:600px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 b-r padding_bottom_70" >
<p class="margin_top_600px">
Left side Data
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 b-r padding_bottom_70" >
<p class="margin_top_600px">
Right side Data
</p>
</div>
</div>
To hide scrollbar you need to define one more wrapping div with overflow-y: scroll;. Outer div should have overflow: hidden;
scroll available with hidden scrollbars
.b-r{
border-right: thin black solid;
height: 100vh;
overflow: hidden;
}
.margin_top_600px{
margin-top:600px;
}
.scrll_hide {
float: right;
height: 100%;
width: calc(100% + 48px);
overflow-y: scroll;
margin: 0 -32px 0 0 !important;
box-sizing: border-box;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 b-r padding_bottom_70" >
<div class="scrll_hide">
<p class="margin_top_600px">
Left side Data
</p>
</div>
</div>
<div class="col-xs-6 b-r padding_bottom_70" >
<div class="scrll_hide">
<p class="margin_top_600px">
Right side Data
</p>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 my-content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam neque repellat libero facere, inventore natus! Laudantium laborum unde veritatis, nemo commodi ducimus quasi quam incidunt accusamus dolore asperiores optio repellendus!
</div>
<div class=" col-lg-6 col-md-6 col-sm-6 col-xs-6 my-content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem soluta corrupti, veniam sit, delectus sunt ipsum placeat recusandae eaque, voluptatum nemo optio cumque omnis veritatis quam itaque ab. Cupiditate, exercitationem?Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quo dolorem adipisci sint ducimus voluptates eveniet qui nisi error reiciendis laborum sed, neque officia aspernatur omnis dolore consequuntur, natus optio, mollitia!Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa dignissimos enim expedita temporibus iure. Quam vitae autem laborum magnam optio nihil quisquam, est aliquid perspiciatis quia tempora cumque, enim vel.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vero quis veritatis, alias dicta, commodi adipisci sint natus reiciendis. Atque eius labore alias cum ratione beatae provident voluptatum eum id mollitia.
</div>
</div>
.my-content{
height: 200px;
overflow: auto;
border: 1px solid #000;
}
Working Fiddle https://jsfiddle.net/DTcHh/29480/
For all the React/Next JS and Tailwind Devs.
<div className="flex overflow-auto">
<div className="overflow-auto w-1/4">
<div className="flex flex-col w-full bg-red-200 h-[1000px]">
a
</div>
</div>
<div className="overflow-auto w-3/4">
<div className="flex flex-col w-full bg-blue-200 h-[1000px]">
a
</div>
</div>
</div>

Pushing a Div Below Another

I have a div section (#section1) that I want to remain 100% height, but to expand if need be to fit other content. The width is 100%. I have another div below that one as you scroll down the page (#section2), same principle 100% height and width, with the height expanding as needed. My problem is, the second one won't push all the way down, due to the first div being absolute. Instead it is has the first section on top of it. Does anyone have any advice? I'm using Bootstrap 4 for this project.
header {
line-height: 100px;
height: 100px;
width: 100%;
background: #f3f3f3;
position: fixed;
top: 0;
z-index: 2;
}
html {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
min-height: 100%;
height: 100%;
}
body {
background: none;
height: 100%;
}
p {
font-size: 20px;
margin: 0;
}
#section1 {
padding: 0;
margin: 0;
background-color: #292929;
margin: 0 auto;
min-height: 100%;
width: 100%;
position: absolute;
}
#section2 {
padding: 0;
margin: 0;
background-color: red;
margin: 0 auto;
min-height: 100%;
width: 100%;
}
#section2 p {
background-color: inherit;
max-width: 600px;
margin: 0 auto;
}
#section2 a {
background-color: #2eb233;
color: #ffffff;
font-weight: 700;
font-size: 20px;
padding: 15px 40px;
}
#section2 a:hover {
text-decoration: none;
background-color: hsl(122, 79%, 38%);
}
<!--Header-->
<header></header>
<!--Section 1-->
<div id="section1">
<div class="container">
<div class="row">
<div class="col-md-6 push-md-6">
<div id="quote-section">
<h1>What our customers <br> have to say...</h1>
<div id="quote-box">
<p><em>"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore repellat eos quas, similique tempora at magni ab cumque blanditiis labore provident quae dolorem optio nobis vel debitis quasi, rem recusandae!"</em>
</p>
<p id="quote-location">(Location)</p>
</div>
<a class="call-to-action" href="#">Find A Location</a>
<div id="border-section-off"></div>
<a class="call-to-action" href="#">Order Our Home Study Course</a>
</div>
</div>
</div>
</div>
</div>
<!--Section 2-->
<div id="section2">
<h1>Who We Are...</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nemo quaerat odit cumque assumenda voluptates ipsum nisi, aliquid consequuntur obcaecati commodi aperiam sequi officiis illo adipisci inventore, beatae, ex ab eveniet.Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Nemo quaerat odit cumque assumenda voluptates ipsum nisi, aliquid consequuntur obcaecati commodi aperiam sequi officiis illo adipisci inventore, beatae, ex ab eveniet. Lorem ipsum dolor sit amet, consectetur adipisicing
elit. Consequuntur iste suscipit deserunt ipsum officia, rerum. Aliquam distinctio, quia placeat praesentium, nesciunt fugiat, provident assumenda voluptates voluptate esse totam, nam vero!Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Magni quia officia quasi voluptas animi ex delectus reiciendis, commodi, voluptatum nemo, ullam sequi saepe! Ut dicta quidem odit cupiditate. Reprehenderit, id.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vero quibusdam in laborum nobis
harum aspernatur, quidem repellat non nostrum, error dolore beatae saepe deserunt atque nemo repudiandae praesentium dolorem. Autem?</p>
</div>
Why you need section 1 to be absolute, if you remove that attribute everything will work fine run this code below:
header {
line-height: 100px;
height: 100px;
width: 100%;
background: #f3f3f3;
position: fixed;
top: 0;
z-index: 2;
}
html {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
min-height: 100%;
height: 100%;
}
body {
background: none;
height: 100%;
}
p {
font-size: 20px;
margin: 0;
}
#section1 {
padding: 0;
margin: 0;
background-color: #292929;
margin: 0 auto;
min-height: 100%;
width: 100%;
//position: absolute;
}
#section2 {
padding: 0;
margin: 0;
background-color: red;
margin: 0 auto;
min-height: 100%;
width: 100%;
}
#section2 p {
background-color: inherit;
max-width: 600px;
margin: 0 auto;
}
#section2 a {
background-color: #2eb233;
color: #ffffff;
font-weight: 700;
font-size: 20px;
padding: 15px 40px;
}
#section2 a:hover {
text-decoration: none;
background-color: hsl(122, 79%, 38%);
}
<!--Header-->
<header></header>
<!--Section 1-->
<div id="section1">
<div class="container">
<div class="row">
<div class="col-md-6 push-md-6">
<div id="quote-section">
<h1>What our customers <br> have to say...</h1>
<div id="quote-box">
<p><em>"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore repellat eos quas, similique tempora at magni ab cumque blanditiis labore provident quae dolorem optio nobis vel debitis quasi, rem recusandae!"</em>
</p>
<p id="quote-location">(Location)</p>
</div>
<a class="call-to-action" href="#">Find A Location</a>
<div id="border-section-off"></div>
<a class="call-to-action" href="#">Order Our Home Study Course</a>
</div>
</div>
</div>
</div>
</div>
<!--Section 2-->
<div id="section2">
<h1>Who We Are...</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nemo quaerat odit cumque assumenda voluptates ipsum nisi, aliquid consequuntur obcaecati commodi aperiam sequi officiis illo adipisci inventore, beatae, ex ab eveniet.Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Nemo quaerat odit cumque assumenda voluptates ipsum nisi, aliquid consequuntur obcaecati commodi aperiam sequi officiis illo adipisci inventore, beatae, ex ab eveniet. Lorem ipsum dolor sit amet, consectetur adipisicing
elit. Consequuntur iste suscipit deserunt ipsum officia, rerum. Aliquam distinctio, quia placeat praesentium, nesciunt fugiat, provident assumenda voluptates voluptate esse totam, nam vero!Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Magni quia officia quasi voluptas animi ex delectus reiciendis, commodi, voluptatum nemo, ullam sequi saepe! Ut dicta quidem odit cupiditate. Reprehenderit, id.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vero quibusdam in laborum nobis
harum aspernatur, quidem repellat non nostrum, error dolore beatae saepe deserunt atque nemo repudiandae praesentium dolorem. Autem?</p>
</div>
Depending on which browsers you need to support, you could ditch position absolute and min-height from the sections and use:
height: 100vh;
Which would set the sections to 100% of the browser viewport's height.
It's a fairly recent addition though, so check http://caniuse.com/viewport-units/