Позиционирование элемента с медиа-запросами,

0

Привет, У меня есть элемент, который я хочу изменить, когда изменяется размер экрана. Я хочу, чтобы он изменился с фиксированной позиции на центр страницы. Код CSS выглядит так:

#symboler {
    position:fixed;
    top:5px;
    right:20px;}

@media screen and (max-width: 766px) {
        #symboler {display:block; position:relative; margin:0 auto;}
}
  • 0
    так что не работает?
  • 0
    Элемент движется вверх в левый угол.
Показать ещё 4 комментария
Теги:

3 ответа

1
Лучший ответ

Вы ищете что-то вроде этой скрипки?

HTML

<div id="symboler"></div>

CSS

* {
    margin: 0; // reset browser value
    padding: 0; // reset browser value
}

#symboler {
    position:fixed;
    top:5px;
    right:20px;
    height: 200px; // just to display a red cube
    width: 200px; // just to display a red cube
    background: red; // just to display a red cube
}

@media screen and (max-width: 766px) {
    #symboler {
        display:block; // you can remove this if you are using a block element like div
        position:relative;
        margin:0 auto;
        right:0; // reset your value
    }
}
0

Попробуйте добавить

float:none;
width: 450px //specify width accurately in pixel or em
margin : 0 auto;
position:relative;
0

Проверьте это демо jsFiddle

CSS

#symboler {
    position:fixed;
    top:5px;
    right:20px;
    height: 200px;
    width: 200px;
    background: red;
}
@media screen and (max-width: 766px) {
    #symboler {
        display:block;
        position:relative;
        margin:0 auto;
        right:0;
    }
}

Ещё вопросы

Сообщество Overcoder
Наверх
Меню