give background shadow for text present on image - html

we have images in our site as below
at the bottom of the image we are displaying text , we want to give background shadow for that text as below :
.fanbook-img img {
width: 100% !important;
}
img {
display: block;
}
, *:before, *:after {
box-sizing: border-box;
margin: 0;
padding: 0;
}

HTML -
<div id="img"><div id="text"><p>text </p></div><div>
CSS-
#img{
background-image: url('');
}
#text{
background-color: rgba(?,?,?,0.5);
padding: 10px 10px;
margin: 0 ;
}

The text and whole thing needs to be in some html element, for example the HTML
<p>text</p>
which will then get the CSS
p {
display: block;
padding: [vertical padding] [horizontal padding];
background: [background color, in rgba];
}
The display: block makes it full-width and makes it take padding. Just to give you an example of working CSS, here are so sample values:
p {
display: block;
padding: 20px 40px;
background: rgba(255,255,255,.5);
}
The background is an rgba ("red green blue alpha") value in order to give you transparency. Hex values, the other common way of writing colors for the web (they look like "#ff00ff"), don't support transparency. r, g, and b are 0 (none) to 255 (full), and a is 0 (transparent) to 1 (opaque); the example is half-opaque white (rgba(0,0,0,.5) would be half-opaque black).
Note that the p in p {...} in the CSS is targeting the <p>..</p> in the HTML - if you were wrapping the text in some other element, you'd use that in the CSS instead. Targeting a "bare" selector can be risky, because those styles will apply to every instance of it. To be safer, can also target a class or id, instead of the element name. For example
HTML
<p class="text-with-transparent-background">
text
</p>
CSS
.text-with-transparent-background {
...(styles as above)...
}
A class can be reused multiple times on a single page. An id (HTML <elementname id="yourcustomidname">...</elementname>, CSS #yourcustomidname {...styles...}) can only be used once per page

You need to make some changes in your css. See teh below css code .
.fanbook-name {
background: rgba(255, 255, 255, 0.5); /* add this */
bottom: 0;
position: absolute;
text-align: center;
width: 100%;
z-index: 1;
}
.fanbook-name b {
/* bottom: 25px; */
color: #000;
font-size: 12px;
/* position: relative; */
text-transform: capitalize;
}
.fanbook-image li {
float: left;
margin-bottom: 1%; /* change this */
margin-left: 0.5%;
margin-right: 0.5%;
position: relative; /* add this */
width: 24%;
}
I hope it will helps you.

<div class="fanbook-img">
<a href="http://sb.kidsdial.com/white-marble-2-samsung-galaxy-j7-phone-case.html">
<div class="">texttext texttext texttext texttext texttext texttext</div>
<img style="width:250px;height:250px;text-align:center;" src="http://sb.kidsdial.com/media/FanBook/iQdzXDrvEU.jpg">
</a>
</div>
.fanbook-img > a {
position: relative;
width: 100%;
}
.fanbook-img div {
background-color: rgba(0, 0, 0, 0.5);
bottom: 0;
color: #ffffff;
height: auto;
left: 0;
margin: 0 auto;
padding: 10px;
position: absolute;
right: 0;
text-align: center;
width: 100%;
z-index: 99;
}

Related

Text in a div crosses its boundaries and text padding not working

I am trying to create a part of my website,
Here is the code:
import React from 'react';
import './stylesheets/BeyondHelloWorld.css';
import BHW from './assets/bhw.png';
function BeyondHelloWorld() {
return (
<div className="mainDiv">
<div className="card">
<div className="cardContainer">
<div style={{height: "100%", display: "block"}}>
<img src={BHW} className="bhwImage"/>
</div>
<div class="bhwText">
<span className="bhwTitle">BeyondHelloWorld</span>
<span className="fadedTitle">Beyond</span>
<span className="bhwDescription">BeyondHelloWorld is a learning community for budding programmers. It is aimed at equipping amateurs with easy knowledge of the tech world through engaging content like New Tech information, tips & tricks & BTS of a developers life!</span>
<span className="bhwDescription">A lot of community problems can be solved using technology. BeyondHelloWorld aims to influence non-programmers into the world of programming.</span>
</div>
</div>
</div>
</div>
)
}
export default BeyondHelloWorld
If you see the span bhwDescription, it is inside bhwText div which is inside cardContainer.
Now I have a picture on the left with classname bhwImage
When the text exceeds the height of this image, the text starts from the left of the cardContainer, but I want it to start from the starting edge of the bhwText.
Example:
But with my code, What it looks like:
What am I doing wrong?
Also, if you notice, the fadedTitle and bhwTitle are not exactly aligned. I want them all to start where the picture starts. But something is going off. Even if I keep the padding/margin same, even then they have different starts.
Here is the css:
.mainDiv {
width: 100%;
padding: 50px;
background-color: #1e3512;
}
.card {
background-color: #1e3512;
box-shadow: 5px 5px 20px 0px rgba(0, 0, 0, 0.48);
padding: 0;
overflow: hidden;
}
.cardContainer {
margin: 0;
padding: 0 20px 0 0;
width: 100%;
}
.bhwImage {
height: 18vh;
object-fit: contain;
margin: 40px;
border: 5px solid #fff;
float: left;
}
.bhwText {
margin-top: 20px;
color: #ffffff;
}
.bhwTitle {
font-size: 3.5rem;
font-weight: 600;
display: block;
margin-bottom: 20px;
}
.fadedTitle {
position: absolute;
top: 25px;
font-size: 150px;
line-height: 75px;
opacity: 0.1;
font-weight: 900;
}
.bhwDescription {
display: block;
margin-bottom: 20px;
font-size: 1.8rem;
font-weight: 500;
word-wrap: break-word;
}
Add display:flex to your .cardContainer class
.cardContainer {
margin: 0;
padding: 0 20px 0 0;
width: 100%;
display: flex;
}
and remove width:100% from .mainDiv class
.mainDiv {
/* width: 100%; */ remove this
padding: 50px;
background-color: #1e3512;
display: flex;
}
Live Demo
The reason why the content runs underneath the image is because its style is float: left;, and your .bhwText class has a width of 100% because it's a block element. div elements are generally display: block; by default. This means .bhwText width is 100% of the parent container by default. The text will fill up space where available in it's container; including below the image.
To fix this issue, add left padding to the .bhwText class. Something like this example here.
.bhwText {
margin-top: 20px;
color: #ffffff;
padding: 0 0 0 200px;
}

Overflowing Underline While Being Responsive to Text Length

I'm trying to emulate this effect via CSS:
The reason this is an issue is because it needs to be re-usable. The red underline's size should be dictated by the text length, but also overflow its container in a predictable manner, e.g.:
<div>
<h1>This</h1>
<h1>Cool</h1>
<h1>Effect</h1>
</div>
The red underline should extend outside the div by 10px on the left, and then also overflow the text itself by roughly 50px on the right. So, all told, the red line is +60 pixels wider than the text itself.
How can I achieve this effect without doing it manually each time? I've had no success with pseudo elements, and box-shadow won't extend on the left and right as I need it to.
Pseudo elements was the answer for me. Setting z-index on the :after element to get it positioned behind the parent element is a neat trick. The elements can't be block elements, but other than that it seemed straightforward.
html {
min-height: 100%;
}
body {
min-height: 100%;
background: linear-gradient(to bottom, #0b122f 0%, #17457d 100%);
padding: 20px;
}
h1 {
position: relative;
display: inline-block;
color: #fff;
font-family: sans-serif;
font-size: 100px;
font-weight: 300;
margin: 0;
}
h1:before {
content: "";
background: red;
height: .25em;
width: calc( 100% + 60px);
position: absolute;
bottom: .15em;
left: -10px;
z-index: -1;
}
<div>
<h1>This</h1>
<br />
<h1>Cool</h1>
<br />
<h1>Effect</h1>
</div>
use <h1><span>This</span></h1> make effect in span and adjust red box to use padding to were's you want :
h1 span {
position: relative;
font-size: 100px;
font-weight: 300;
margin: 0;
padding:0 0 0 20px;
}
h1 span::before {
content: "";
background: red;
height: .25em;
position: absolute;
bottom: .15em;
z-index: -1;
width: 100%;
left: 0;
}
like: https://jsfiddle.net/bdmpqkme/1/
All this examples mentioned above by lalit bhakuni and JasonB work really well, but only when you don't have any section with a background behind this underlined text.
The z-index: -1 will put the line you want behind the text like you want and also behind any other parent sections. In case any of these parent sections have a background, the line will be hidden (behind).
Other solution, not so clean, but solves all our problems is by adding an extra element inside of your heading:
HTML
<div class="div-with-background">
<h1><span>This</span></h1>
<br />
<h1><span>Cool</span></h1>
<br />
<h1><span>Effect</span></h1>
</div>
CSS
.div-with-background {
background-color: #333;
}
h1 {
position: relative;
display: inline-block;
color: #fff;
font-family: sans-serif;
font-size: 100px;
font-weight: 300;
margin: 0;
}
h1::before {
content: "";
background: red;
height: .25em;
width: calc( 100% + 60px);
position: absolute;
bottom: .15em;
left: -10px;
}
h1 > span {
position: relative;
}
In this case, we don't even need to use the z-index property.

Align placeholder with input in <input>

I changed some left padding in the ::placeholder pseudo-element and am experiencing some trouble getting the input text aligned with the placeholder.
The problem: The distance from the icon needs to be identical on both input text and placeholder text. The input text is flush up against the icon but the placeholder is in the correct position.
A demonstration of the problem and my code is below:
A link to my fiddle: https://jsfiddle.net/4jh52b18/1/
Source code:
CSS:
#search-overlay {
position:absolute;
top: 0;
left:0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.9);
.search-overlay__wrapper {
max-width: 752px;
margin: 0 auto;
margin-top: 160px;
}
.search-overlay__search-bar {
width: 720px;
margin: 0 auto;
font-size: 35px;
font-family: sans-serif;
color: black;
padding: 20px;
border: none;
border-bottom: 1px solid gray;
background: url("https://d30y9cdsu7xlg0.cloudfront.net/png/28403-200.png") left no-repeat;
background-size: 20px;
&::placeholder {
padding-left: 25px;
}
#media (max-width: 980px) {
width: 100%;
margin: 0 auto
}
}
.search-overlay__close {
display: inline;
vertical-align: middle;
#media (max-width: 980px;) {
position: absolute;
top: 0;
right: 0;
padding: 24px;
}
}
}
HTML:
<div id="search-overlay">
<div class="search-overlay__wrapper">
<input type="text" name="search" placeholder="Search" class="search-overlay__search-bar" value="">
<a class="search-overlay__close" href="#"> <img src="images/overlay-close.png" alt=""> </a>
</div>
</div>
In the live jsfiddle example, you'll see that the input text doesn't align with the placeholder when they need to be aligned in the same spot. What is the attribute to be able to do this? I tried adding a padding-left directly on the input but that didn't work as expected.
In your SCSS (line 23-25), modify/remove the following:
&::placeholder {
padding-left: 25px;
}
The reason why it didn't work is because & in SCSS replaces the current selector. Therefore &::placeholder translates into:
#search-overlay .search-overlay__search-bar::placeholder {...}
Most likely, you used a weaker selector and it didn't apply.

How to put an image behind text in CSS?

I want an image to be displayed behind some text in an <h1> tag. But when I add the image it replaces the text and pushes the text below it.
Screenshots : Before and After
CSS
body {
background-color: #1a1a1a;
}
header,
h1 {
text-align: center;
font-family: CGF Locust Resistance;
font-size: 50px;
color: lightgray;
-webkit-text-stroke: 1.5px #000;
}
header {
margin: 0;
padding: 0;
height: 100px;
border-bottom: .5px solid #b3b3b3;
}
nav {
position: relative;
top: -5px;
margin: auto;
padding: 0;
list-style: none;
width: 100%;
text-align: center;
border-bottom: .5px solid #b3b3b3;
}
nav ul li {
display: inline;
color: #fff;
font-family: CGF Locust Resistance;
font-size: 12.5px;
padding: 20px;
}
.red {
color: red;
}
#omen {
z-index: -1;
}
Set the image as a background-image of header. Is that what you're after?
h1 {
background: url(the/filepath/to/your/image.jpg) no-repeat center 100px;
background-size: 400px auto;
}
That's approximately how you would use a background image in this situation. center 100px means horizontally centered and 100px from the top (in relation to the h1 element).
h1 {
position : abosolute;
}
This should do the trick but it is preferable to use ids instead of changeing the h tags everywhere on your side
Put this parameter to the image object in css (example creating custom classes) :
.image{
position: relative;
}
And this one to the text :
.text{
position: absolute;
}
Of course, you have to set this classes to it's respective objects. Hope it helps !

Using opacity to blur a Div's background colour instead of mentioning rgba colour of a Div

I have an Image on the page. I have put a Div on footer with a heading and a paragraph inside the Div. I have made the Div's background transparent like this way , background-color: rgba(0,0,0,.6);.
But I need to implement this like this way , background-color:black; opacity:0.6".
The problem is, if I am doing it using opacity then the heading and paragraph is also getting blur with the Div's colour. How can I solve it?
Below is my full code.
CSS
<style type="text/css">
.div1 {
max-width: 100%;
height: auto;
text-align: center;
display: block;
border: none;
}
.feature-text-overlay {
background-color: rgba(0,0,0,.3);
bottom: 0;
padding: .6em 0 .8em;
position: absolute;
text-align: center;
width: 100%;
}
.feature-title {
font-size: .875em;
margin: 0;
text-transform: uppercase;
color:white;
}
.feature-description {
line-height: 1.2;
margin: 0 2em;
color:white;
}
</style>
Html
<div class="div1">
<img src="~/Content/Image/rendering-graphics-in-resolution-222734.jpg" />
<div class="feature-text-overlay" style="height:52.599999277954px; min-height:1px;">
<h4 class="feature-title">Enterprise Mobility Suite</h4>
<p class="feature-description">Manages Users, Devices and Data</p>
</div>
</div>
css
.feature-text-overlay {
bottom: 0;
padding: .6em 0 .8em;
position: absolute;
text-align: center;
width: 100%;
position:relative; /* add this to specify position */
}
/* create pseudo css element */
.feature-text-overlay:before {
content:"";
background-color: #000;
opacity:0.3;
bottom: 0;
top:0;
right:0;
left:0;
position: absolute;
}
Demo
edit as per comment demo 2