A snippet speaks more than a thousand words:
body {
padding-top: 11%;
background: url(https://fakeimg.pl/1920x1920/);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><body><divclass="container">
<form class="form-horizontal" method="post" action="login.php">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<h2>Entrar</h2>
<hr>
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="form-group has-danger">
<label>Digite seu e-mail</label>
<div class="input-group mb-2 mr-sm-2 mb-sm-0">
<input type="text" name="email" class="form-control" id="email"
placeholder="[email protected]" required autofocus>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="form-group">
<label>Digite sua senha</label>
<div class="input-group mb-2 mr-sm-2 mb-sm-0">
<input type="password" name="password" class="form-control" id="password"
placeholder="********" required>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6" style="padding-top: .35rem">
<div class="form-check mb-2 mr-sm-2 mb-sm-0">
<label class="form-check-label">
<input class="form-check-input" name="remember" type="checkbox" checked="checked">
<span style="padding-bottom: .15rem">Lembrar-me</span>
</label>
</div>
</div>
</div>
<div class="row" style="padding-top: 1rem">
<div class="col-md-3"></div>
<div class="col-md-6">
<button type="submit" class="btn btn-info"><i class="fa fa-sign-in"></i> Login</button>
</div>
</div>
</form>
</div>
</body>
Please note that on this login page I have a simple form with a background image, inserted through CSS by background url .
However when trying to add opacity only in the image, with the code below, the entire form loses its opacity, and the image itself does not lose:
body {
padding-top: 11%;
background: url(https://fakeimg.pl/1920x1920/);
opacity: 0.5;
}
body {
padding-top: 11%;
background: url(https://fakeimg.pl/1920x1920/);
opacity: 0.5;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><body><divclass="container">
<form class="form-horizontal" method="post" action="login.php">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<h2>Entrar</h2>
<hr>
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="form-group has-danger">
<label>Digite seu e-mail</label>
<div class="input-group mb-2 mr-sm-2 mb-sm-0">
<input type="text" name="email" class="form-control" id="email"
placeholder="[email protected]" required autofocus>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="form-group">
<label>Digite sua senha</label>
<div class="input-group mb-2 mr-sm-2 mb-sm-0">
<input type="password" name="password" class="form-control" id="password"
placeholder="********" required>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6" style="padding-top: .35rem">
<div class="form-check mb-2 mr-sm-2 mb-sm-0">
<label class="form-check-label">
<input class="form-check-input" name="remember" type="checkbox" checked="checked">
<span style="padding-bottom: .15rem">Lembrar-me</span>
</label>
</div>
</div>
</div>
<div class="row" style="padding-top: 1rem">
<div class="col-md-3"></div>
<div class="col-md-6">
<button type="submit" class="btn btn-info"><i class="fa fa-sign-in"></i> Login</button>
</div>
</div>
</form>
</div>
</body>
I also tried to add the opacity next to the background url , however it was not recognized and deleted the image:
background: url(https://fakeimg.pl/1920x1920/) opacity: 0.5;
So how can I get the background image of the body with little opacity and keep the text with full opacity?