Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a backdrop over a div (lightbox effect)?

i'm editing an AngularJS project and i want to add a backdrop (like Bootstrap Modal) over the main DIV when users click on search input box.

enter image description here

Here is the HTML code:

    <div class="main-box">
        <div class="search-function" ng-click="showInputForm()">
            <img src="../images/my_project/search.png">
        </div>

        <div class="search-form" ng-if="showForm">
            <form ng-submit="textSearch()">
                <input type="text" autofocus class="search-input" ng-model="text.value" />
            </form>
        </div>
    </div>

As you can see the white box appears when users click on the search icon and now i want to add a backdrop over the main DIV, except on the white box.

Here is the LESS code:

.search-function {
  margin-left: 30%;
}

.search-form {
  padding-left: 15%;
  padding-right: 15%;
  position: relative;
  z-index: 0;

  .search-input {
    color: #2b84a6 !important;
    background-color: #fff !important;
    font-weight: 300;
    font-size: 16px;
  }
}

How can i reach this?

like image 931
smartmouse Avatar asked Apr 19 '16 08:04

smartmouse


2 Answers

Something like this

 <div class="main-box">
    <div class="backdrop" ng-if="showForm"></div>
    <div class="search-function" ng-click="showInputForm()">
        <img src="../images/my_project/search.png">
    </div>

    <div class="search-form" ng-if="showForm">
        <form ng-submit="textSearch()">
            <input type="text" autofocus class="search-input" ng-model="text.value" />
        </form>
    </div>
</div>

And add the CSS as

.backdrop {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background: black;
    opacity: 0.5;
}
like image 69
berentrom Avatar answered Sep 30 '22 18:09

berentrom


Here's a very complete article about different methods of achieving what you need

CSS Overlay Techniques

like image 45
Pietro Avatar answered Sep 30 '22 16:09

Pietro