overlaying an image with text in Materialize CSS - html

I've tried multiple ways to overlay the background image with text, to no avail. The template provided on the materializeCSS website involves parallax, which I don't want.
The aim is to have a 'card' sit on top of a large image stretching across the browser window. I actually aim to do this separately for several cards.
Here's my code (for a particular card):
<div class="row center">
<div class="col s12 l6 offset-l6">
<div class="card z-depth-5 teal darken-4">
<span class="card-title white-text text-darken-4">
</div>
</div>
</div>
</div>
I understand that the image tag is to be:
<img src="URL">
But wherever I put it, it doesn't place an image behind the card. I've tried all the obvious stuff such as adding a new div class, but perhaps I'm adding the wrong kind. really racking my brains on this one.
How do I place an image (spanning the width of the browser and around 700px in height) behind a card?

Thank you for your responses!
It was very simple in the end:
<div class = "iris">
<div class = "card transparent z-depth-5">
</div>
</div>
Basically you wrap a div around the card div and then for, in this case, iris, you set the background image using CSS.
.iris {
background-image: url("");
background-repeat: no-repeat;
height: 100vh;
background-size: cover;
}
By using card class 'transparent' you get this cool effect whereby the card is actually see-through and looks like glass, but you do need a high z-depth index so that the shadow of the card illuminates its edges.
Cheeeeers

You can do this in 2 ways
Use the background(background-image) css property. You can also set the background-size to help with the background size (ie keep the image contained in the parent, let it overflow, stretch to fit etc)
Set position css property of the img element to absolute, set the z-index of the card to some value higher than the z-index of the img element.
Do not know if Materialize CSS provides premade css classes for some of these settings you would have to check their documentation.
background css property
CSS
.cardbg {
background:url(URL) no-repeat 0% 0%;
background-size:cover;
}
HTML
<div class="cardbg">
<div class="card z-depth-5 teal darken-4">
<span class="card-title white-text text-darken-4">
</span>
</div>
</div>
Positioned img element
CSS
.container {
position:relative;
}
.card {
position:relative;
z-index:10;
}
.cardbg {
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
z-index:1;
}
HTML
<div class="container">
<img src="URL" class="cardbg" />
<div class="card z-depth-5 teal darken-4">
<span class="card-title white-text text-darken-4">
</span>
</div>
</div>
background css demo
.cardbg {
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
background:url(http://placehold.it/1024x768) no-repeat 0% 0%;
background-size:cover;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.95.3/js/materialize.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.95.3/css/materialize.min.css" rel="stylesheet" />
<div class="cardbg">
<div class="card z-depth-5 teal darken-4">
<span class="card-title white-text text-darken-4">
Some card
</span>
</div>
</div>
Positioned element demo
.container {
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
}
.card {
position:relative;
z-index:1;
}
.cardbg {
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
z-index:0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.95.3/js/materialize.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.95.3/css/materialize.min.css" rel="stylesheet" />
<div class="container">
<img src="http://placehold.it/1024x768" class="cardbg" />
<div class="card z-depth-5 teal darken-4">
<span class="card-title white-text text-darken-4">
Some text
</span>
</div>
</div>

You can add the image as background of some div, or even the whole body
body {
background-image: url('https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRLcjS59w8iUV6NqkYvcHOzlqS21rr13KyqGppuYJf5KI88AYB_IA');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.95.3/js/materialize.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.95.3/css/materialize.min.css" rel="stylesheet" />
<div class="row center">
<div class="col s12 l6 offset-l6">
<div class="card z-depth-5 teal darken-4">
<span class="card-title white-text text-darken-4">Title</span>
<p class="grey-text text-darken-1">Content sdfa sd fas dfa sdf</p>
<br>
<p class="grey-text text-darken-1">Content sdfa sd fas dfa sdf</p>
</div>
</div>
</div>

Related

How do i make text always appear together? Bootstrap

To illustrate the problem better, here's the video and jsfiddle.
<div class="container-fluid">
<div class="container">
<img src="https://image.com"/>
<h1>lorem ipsum dolor</h1>
</div>
While window has certain width, one part of text goes under the image and another stays next to it. How can i prevent text from dividing, so when window reaches this certain width, the whole phrase "lorem ipsum dolor" appears under the image and not just "dolor"? I'm using bootstrap, is there any special <div> class dedicated to this thing? putting text in container or content doesn't solve the problem.
I hope this is helpful.
body {
background-image: linear-gradient(to bottom right,#09845A, #8733DD);
}
.flex {
display:flex;
justify-content:center;
}
#media screen and (max-width:728px) {
.flex {
flex-direction:column;
align-items:center;
}
.img {
background:url("https://www.google.pl/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");
width:100px;
}
}
.img {
background:url("https://www.google.pl/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");
height:92px;
width:272px;
}
.container-fluid {
background: rgba(0,0,0,0.75);
}
.container {
display:block;
overflow:auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container-fluid">
<div class="flex">
<div class="img"></div>
<h1>
Ulecz się rozmową
</h1>
</div>
</div>
</body>
This should help.
https://www.w3schools.com/code/tryit.asp?filename=FY3DOVSFM4MZ
basically you need to give col-sm-12 this tells that at smalls screens make this item full width.
Why don't you try using columns instead like this.
<div class="container-fluid">
<div class="container">
<div class="col-md-6 col-sm-12 col-xs-12">
<img src="https://image.com"/>
</div>
<div class="col-md-6 col-sm-12 col-xs-12">
<h1>lorem ipsum dolor</h1>
</div>
</div>

text does not vertically align with image

Good day, as the title says, I am having issues with aligning the text in the exact center of my image. I tried adding a class with the css vertical-align:middle with no effect. Also, I tried using the span class to surround the text that will be centered. Both the image and the text are encased in a bootstrap grid. Any help will be appreciated thank you.
HTML/Bootstrap:
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<img src="img/mission-mywhitecard.jpg" class="img-responsive align_text">
</div>
<div class="col-md-9 justify_text">
<span>
<h2 class="med_bg">OUR MISSION</h2>
<p class="mv_font">“To provide a mutually-beneficial platform for partners through high-quality, lower cost and friendly access to health, wellness and beauty.”</p>
</span>
</div>
</div>
</div>
CSS:
.align_text {
vertical-align: middle;
}
Considering you are using bootstrap4, you can achieve that using the class .align-items-center, or use display:flex as stated by others :)
img {
background: gray;
height: 250px;
display: block;
max-width: 100%;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row align-items-center">
<div class="col-3">
<img src="img/mission-mywhitecard.jpg" class="img-responsive align_text">
</div>
<div class="col-9 justify_text">
<h2 class="med_bg">OUR MISSION</h2>
<p class="mv_font">“To provide a mutually-beneficial platform for partners through high-quality, lower cost and
friendly access to health, wellness and beauty.”</p>
</div>
</div>
</div>
I believe this produces what you ask for. It is using 2 flexboxes:
First one (.row) to put the image and text next to each other in a responsive way;
Second one (.col-md-9) to position the span in the center
html,
body {
width: 100%;
}
.row {
display: flex;
width: 100%;
}
.row>* {
flex: 1; /* Allow the flex items to grow and shrink */
}
.col-md-9 {
display: flex;
justify-content: center;
align-items: center;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<img src="https://via.placeholder.com/100x300" class="img-responsive align_text">
</div>
<div class="col-md-9">
<span>
<h2 class="med_bg">OUR MISSION</h2>
<p class="mv_font">“To provide a mutually-beneficial platform for partners through high-quality, lower cost and friendly access to health, wellness and beauty.”</p>
</span>
</div>
</div>
</div>
You can aslo use align-self-center in column div class without any height of image and other css also add larger image no design change when you use align-self-center in column div no need set image height
.align_text {
vertical-align: middle;
}
img {
max-width: 100%;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<img src="http://placekitten.com/1000/500" class="img-responsive align_text">
</div>
<div class="col-md-9 justify_text align-self-center">
<span>
<h2 class="med_bg">OUR MISSION</h2>
<p class="mv_font">“To provide a mutually-beneficial platform for partners through high-quality, lower cost and friendly access to health, wellness and beauty.”</p>
</span>
</div>
</div>
</div>

Applying an opacity filter over an image on html

I was trying to find this solution but I can only find solutions to apply filter on images as background-image on css.
I have a row with 3 images in equal size on my HTML.
The effect that I am trying to replicate is a "filter" on all of the photos that give a gradient opacity. This filter has a bottom completely dark and starts getting transparent until reaching the top. (a little bit like this: http://www.webdesignerwall.com/wp-content/uploads/2010/04/css-gradient-box.gif where the white top would be transparent)
How could I do that, considering that images are 100% responsive and changes for every time we change the size of the browser.
PS: The gradient code is not a problem, I can do that, the problem I can't find the solution is how to apply a "DIV" or something over each of those images that always follow the image size, no matter its height and width.
Here's my HTML:
<section class="home-page-gallery">
<div class="container-fluid">
<div class="row">
<!-- FIRST IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding yellow-bg">
<div class="gallery-item">
<img src="images/photo01.png" alt="">
</div>
</div>
<!-- SECOND IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding blue-bg">
<div class="gallery-item">
<img src="images/photo02.png" alt="">
</div>
</div>
<!-- THIRD IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding pink-bg">
<div class="gallery-item">
<img src="images/photo03.png" alt="">
</div>
</div>
</div><!-- ./ row -->
</div><!-- ./ container-fluid -->
</section>
and the CSS:
.gallery-item{
width:100%;
}
.gallery-item img{
width:100%;
height:auto;
}
I already tried to put another div wrapping each image, giving a position: relative and a z-index trying to make this div stay over the image, but it didn't work
Thank you so much!
Use pseudo-element like this:
.gallery-item {
width: 100%;
position:relative;
}
.gallery-item:after {
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background:linear-gradient(to top,red 20%,transparent 80%);
}
.gallery-item img {
display:block;
width: 100%;
height: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<section class="home-page-gallery">
<div class="container-fluid">
<div class="row">
<!-- FIRST IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding yellow-bg">
<div class="gallery-item">
<img src="https://lorempixel.com/400/200/" alt="">
</div>
</div>
<!-- SECOND IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding blue-bg">
<div class="gallery-item">
<img src="https://lorempixel.com/400/200/" alt="">
</div>
</div>
<!-- THIRD IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding pink-bg">
<div class="gallery-item">
<img src="https://lorempixel.com/400/200/" alt="">
</div>
</div>
</div>
<!-- ./ row -->
</div>
<!-- ./ container-fluid -->
</section>
you need a element that is a sibling to the image, inside the gallery-item wrapper.
you want to do something like this with your css:
.gallery-item{
width:100%;
position: relative;
}
.gallery-item img{
width:100%;
height:auto;
position: relative;
}
.overlay {
height: 100%;
width: 100%;
position: absolute;
opacity: 0.5;
z-index: 1;
background: linear-gradient(red, yellow);
}
position the outer container as relative, then position the gradient el as absolute. here is a fiddle:https://jsfiddle.net/y9o1paex/11/

Why is my responsive background image leaving white space at the bottom of the image?

I have a responsive image which is leaving white space under the image when resizing the browser. I tried cover but the image doesn't resize at all only setting the background to 100% gives perfect responsiveness. I tried multiple other solutions from stack overflow and none seem to work.
error here :https://drive.google.com/open?id=0BxHtDrLLi2x5ckJNMVVNblRSSWc
css:
#jumbotron{
text-align:center;
background-color:#71706e;
padding-top:80px;
width:100%;
background: url(images/showcase5.jpg) no-repeat;
background-size: 100%;
}
html:
<section id = "jumbotron">
<div class="text">
<h1 class="animated slideInDown">Now now now!</h1>
<h2 class="animated slideInDown">Now now now now<br> before your now do!</h2>
<a href="#" class="learnMore " >Get Started</a>
</div>
</section>
<div id="recent">
<h3>Recent Projects</h3>
</div>
The general concept is to set the height of the container to 0 and use a vertical padding that matches the background image aspect ratio. To get that padding, divide the image height by the width and multiply by 100 to get a percentage. Then the div will scale the same as the background image. And just set the background size to 100%, contain, or cover.
#jumbotron {
background: url('http://placehold.it/1920x1265') 0 0 no-repeat / cover;
padding-bottom: 65.89%;
height: 0;
text-align: center;
}
<section id = "jumbotron">
<div class="text">
<h1 class="animated slideInDown">Now now now!</h1>
<h2 class="animated slideInDown">Now now now now<br> before your now do!</h2>
<a href="#" class="learnMore " >Get Started</a>
</div>
</section>
<div id="recent">
<h3>Recent Projects</h3>
</div>

HTML/CSS making 3 images in line responsive and well designed

Im trying to make these images to be displayed nicely inline and change its position/size depending on the screen size. This is my HTML code:
<div class="row tryRow white">
<div class="col-xs-4 portfolio-item leftPic">
<div class="imgWrap">
<img class="img-responsive" src="~/img/FMA.png" />
<p class="imgDescription">
Some text in here </p>
</div>
</div>
<div class="col-xs-4 portfolio-item centerPic">
<div class="imgWrap">
<img class="img-responsive" src="~/img/SFK.png" />
<p class="imgDescription">
Some text in here
</p>
</div>
</div>
<div class="col-xs-4 portfolio-item rightPic">
<div class="imgWrap">
<img class="img-responsive" src="~/img/CTG.png" />
<p class="imgDescription">
Some text in here </p>
</div>
</div>
</div>
These images display some text below them when they are hovered on.
This is CSS of one of the images:
.leftPic {
opacity:0.5;
border-radius:4px;
max-width: 33%;
width:auto;
}
As you can see I am trying to set the max width to 33% as I have 3 images per line, but the margins are not correct and to be honest there is a large problem with this.
Problem: To make them shrink, re-position depending on the browser while keeping the relatively sharp look.
i tried with this one:
.tryRow{ display: inline-block;}
Hmmm... I would approach it in a different way setting background-image instead of using html <img>. As you expect nice responsive behavior and your images are quite small have a look at this:
<div class="row">
<div class="col-md-4">
<div class="image image-1">Some text</div>
</div>
<div class="col-md-4">
<div class="image image-2">Some text</div>
</div>
<div class="col-md-4">
<div class="image image-3">Some text</div>
</div>
</div>
.image {
background-position: center center;
background-repeat: no-repeat;
-webkit-background-size: cover;
background-size: cover;
// height: control it with media queries
}
.image-1 {
background-image: url(path/to/image-1.jpg);
}
.image-2 {
background-image: url(path/to/image-2.jpg);
}
.image-3 {
background-image: url(path/to/image-3.jpg);
}
This approach will also give you more flexibility styling those boxes content.