Misiu
Misiu

Reputation: 4919

Bootstrap 3 Modal auto size, 30 pix from sides

I'm trying to build modal window that will be positioned absolute, 30 pixels from edge of screen.

enter image description here

I've build this css:

.modal {
    overflow: hidden;
}
.modal-dialog {
    position: absolute;
    top: 50px;
    bottom: 50px;
    left: 50px;
    right: 50px;
    margin: 0;
}
@media (min-width: 768px) {
    .modal-dialog {
        width: auto;
        margin: 0;
    }
}
.modal-footer {
    position: absolute;
    bottom: 0;
    left:0;
    right:0;
}
.modal-header, .modal-body, .modal-footer {
    padding: 10px;
}
.modal-content {
    height: 100%;
    border-radius: 0;
    -webkit-box-shadow: none;
    box-shadow: none;
}
.modal-backdrop {
    background-color: #fff;
}
.modal-header .close {
    margin-top: 3px;
}
.btn {
    border-radius: 0;
}

and my results so far looks like this: http://jsfiddle.net/Misiu/LT3YM/

My modal window is correctly positioned, but modal-body isn't sizing, i would like it to take rest of available height of modal - from header to footer.
I can position absolute modal-body and add top and bottom properties, but I'm wondering if there is a better way of doing this.

My solution for now is this code:

.modal-body {
    position: absolute;
    top: 46px;
    bottom: 54px;
    overflow-y: scroll;
}

and demo of what I have: enter image description here

How can I modify my code better so that modal-body will always be correct height? Is positioning it absolutely only option?

Upvotes: 0

Views: 356

Answers (1)

Ali Gajani
Ali Gajani

Reputation: 15091

http://jsfiddle.net/LT3YM/4/

You should change the values in .modal-dialog. You can make bottom and right 30px too

.modal-dialog {
    position: absolute;
    top: 30px;
    bottom: 50px;
    left: 30px;
    right: 50px;
    margin: 0;
}

enter image description here

Alternatively, this uses 3%: http://jsfiddle.net/LT3YM/7/

.modal-dialog {
    position: absolute;
    top: 3%;
    bottom: 3%;
    left: 3%;
    right: 3%;
    margin: 0;
}

Looks like this:

enter image description here

Upvotes: 1

Related Questions