How to set background colour of an image as black colour? - html

I have an html image
<img src="abc.png">
and I want while the image is being loaded in the browser on a slower connection. The background / placeholder of image appear appear black. Is it possible by giving a class to the image and then setting the css property background-color: black;
<img class="black-back" src="abc.png">
<style>
.black-back {
background-color: rgb(0,0,0);
}
</style>

I inserted the image in div and set the size of image to cover so div will occupy the space as size of image. However if your remove the background properties the div occupy the full line.I hope this is what you are looking for.
<img class="black-back" src="abc.png">
<style>
.black-back img{
background-repeat:no-repeat;
background-size:cover;
}
.black-back {
background-color: rgb(0,0,0);
}
</style>
the below code is without background styling properties
<div class="black-back">
<img src="abc.png">
</div>
<style>
.black-back {
background-color: rgb(0,0,0);
}
</style>

You can do it like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page Title</title>
<style type="text/css">
.black-bg {
background: black;
}
</style>
</head>
<body>
<img class="black-bg" width="100" height="150" src="https://upload.wikimedia.org/wikipedia/commons/b/b6/Trifolium_hybridum_inflorescence_-_Keila.jpg" />
</body>
</html>

Related

How to make input element completely transparent?

How can I make the input element completely transparent so that it has the body background image and not the background colour of its parent?
HTML code:
body{
background-image:url("https://upload.wikimedia.org/wikipedia/commons/3/35/Neckertal_20150527-6384.jpg");
}
#wrapper{
background-color: white;
height: 100px;
}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="wrapper">
<input type="text">
</div>
</body>
</html>
Add css as follows:
#wrapper > input {
background-color: transparent;
border: none;
}
If you want to remove the border on focus too, then add:
#wrapper > input:focus {
outline:none;
}
You can do it this way :
#wrapper{
background-color: white;
height: 100px;
}
#wrapper > input
{
background-color: transparent;
border: none;
}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="wrapper">
<input type="text">
</div>
</body>
</html>
Similar answer was posted few years ago : set input transparent
As I understand you are trying to prevent child element from inheriting parent's background color.
The only way to do is overriding the style
I don't know if this works for you but you can do:
input{
background-image:url("image.jpg");
border: none;
}
you can also do whatever part of the background image you want to display instead input field, simply cut that part of the image and set as a background image for the input field.

How you get a color overlay on an image tag? [duplicate]

This question already has answers here:
How to overlay images
(11 answers)
Closed 2 years ago.
I'm having trouble getting a color overlay on an image tag. I'm not sure why.
The background-color element doesn't appear to working.
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Document</title>
</head>
<body>
<a href="http://google.com" class="image-container">
<img class="image" src="https://img.favpng.com/14/3/12/hamburger-french-fries-fast-food-cheeseburger-small-bread-png-favpng-wz3jTDt4b8xrUBLJveLDpLFfm.jpg" alt="">
<div class="overlay">
<i class="fa fa-heart"></i>
<i class="fa fa-comment"></i>
</div>
</a>
</body>
</html>
this is the mild css code.
.image:hover {
background-color: rgba(0, 0, 0, 0.5);
}
You can't assign a background color to an image. You can do a filter, and adjust it based on CSS filter parameters.
However if you want a specific color to overlay the image you can overlay a div and give it a lighter opacity and change the background color on hover. I included both options in the example snippet.
.image1 {
width: 100px;
}
.image1:hover{
-webkit-filter: contrast(4);
filter: contrast(4);
}
.container{
width: 100px;
height: 100px;
position: relative;
}
.container img{
width: 100px;
height: 100px;
z-index: -1;
}
.overlay{
opacity: 0.3;
width: inherit;
height: inherit;
z-index: 100;
position: absolute;
}
.overlay:hover{
background-color: yellow;
}
<img class='image1' src='https://cdn.pixabay.com/photo/2015/03/04/22/35/head-659652_1280.png'/>
<div class='container'>
<div class='overlay'></div><img src='https://cdn.pixabay.com/photo/2015/03/04/22/35/head-659652_1280.png'/></div>
Instead of keeping the class of image inside the image tag why don't you keep it on the outside.
<div class="image">
<img src="https://img.favpng.com/14/3/12/hamburger-french-fries-fast-
food-cheeseburger-small-bread-png-favpng-wz3jTDt4b8xrUBLJveLDpLFfm.jpg" alt="">
</div>
also change your:
!DOCTYPE html>
instead put:
<!DOCTYPE html>
and you haven't connected your CSS 3 file. So do:
<link rel="stylesheet" href="index1.css">
if your CSS 3 file name is "index1" that is.
But I would just photo shop a copy of it and then say in CSS 3:
.image:hover {
background-image: "where ever you file is";
}

Resize background via CSS

I already tried some ways to do it, but still not worked right
Here is a simple code:
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Convite</title>
<style>
body {
background-image: url("bgg.jpg");
}
#media screen and (max-width : 480px) {
background-image: url("bgg.jpg");
background-size: auto; 480px;
.1 {height:300px;
width:480px;
}
.2 {height:107px;
width:480px;
}
.3 {height:34px;
width:480px;
}
}
</style>
</head>
<body>
<br><br>
<center>
<span class="1"><img src="1.png"></span>
<br><br>
<span class="2"><img src="2.png"></span>
<br><br>
<span class="3"><img src="3.png"></span>
</center>
</body>
</html>
So I have 4 elements (3 images and 1 background)
The original size of background is 1280 x 720p
I was wondering to resize elements by % but it still not work
The viewport is not working
What I am doing wrong?
Your CSS and HTML have tons of problems. Here's the fixed version.
Here are the errors:
Missing DOCTYPE
Using numbers to prefix a CSS class
Misuse <br> to adjust layout
Incorrect syntax in media query
Alt is missing in images tag
Use of obsolete <center> tag
Incorrect use of <span> tag, which is an inline element.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Convite</title>
<style>
body {
background-image: url("bgg.jpg");
}
.center {
margin: auto;
}
#media screen and (max-width : 480px) {
body {
background-image: url("bgg.jpg"); /* this line is redundant */
background-size: cover;
}
.foo1 {
height:300px;
width:480px;
}
.foo2 {
height:107px;
width:480px;
}
.foo3 {
height:34px;
width:480px;
}
}
</style>
</head>
<body>
<div class="center">
<div class="foo1"><img src="1.png" alt="" /></div>
<div class="foo2"><img src="2.png" alt="" /></div>
<div class="foo3"><img src="3.png" alt="" /></div>
</div>
</body>
</html>
Last, if you want to make responsive websites, please do not specify fixed height and width.

Background color not changing in div despite setting it

I feel like I'm going crazy, this is simple stuff yet it just refuses to work, I've done it a million times (although it's been awhile.)
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<style type="text/css">
title {
background-color: #000000;
float: left;
margin: 5px;
padding: 15px;
overflow:auto;
}
</style>
<body>
<div class="title">
<p>
<img src="images/new/Salon.jpg" width="530" height="180" style="" border="0" />
</p>
</div>
</body>
</html>
The background color is not changing and that is literally all I've coded so far
You wrote
title {
instead of
.title {

How to make human image with background-color in html and css3

I have been created web page using html5, css3 and jQuery.
Now I just confused with creating human image with background-color.
May I know, is possible to create by using html5,css3?
<img src="Saina_hybd.png" style="background-color:red;" />
I need like this, http://s3.postimg.org/vol07gleb/Untitled_2.png
Can anyone help me to do this, thanks in advance.
You can not directly add background color property to image. You just create a div before the image and apply background color property to div and just reduce the opacity of the image.
.image_box {
width: auto;
height: auto;
float: left;
background-color: red;
}
.image_box img {
float: left;
opacity: 0.6;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div class="image_box">
<img src="http://www.paritybars.com/wp-content/uploads/2013/09/man-ok.png" alt="ok">
</div>
</body>
</html>