How to center slider in css?

2019-08-01 23:55发布

I installed this plugin on a theme. This theme had a slider, but I didn't like it. So I installed this one.

http://wordpress.org/extend/plugins/content-slide/

I tried using this

#wpcontent_slider_container{
position:relative;
margin: 0 auto;
}

And this

#wpcontent_slider_container{
position:relative;
margin-left:auto;
margin-right:auto;
}

And nothing happens.

Do I have to put something in div?

7条回答
迷人小祖宗
2楼-- · 2019-08-02 00:12

I had the same problem. This is how I solved it:

#wpcontent_slider_container {
margin-left: auto !important;
margin-right: auto !important;
}

#wpcontent_slider {
/* Your styling here */
}

Without the "!important" thingy the CSS didn't work fo me either.

查看更多
贼婆χ
3楼-- · 2019-08-02 00:15
#wpcontent_slider_container{
text-align: center;
}

or use <center> Tag

查看更多
forever°为你锁心
4楼-- · 2019-08-02 00:27

In #wpcontent_slider_container's parent element add

text-align:center;

to center align your #wpcontent_slider_container

查看更多
成全新的幸福
5楼-- · 2019-08-02 00:28

Finally I can fix the problem with the slider ubication in my web page.

Just modify the style.css , .main_img { float:left; margin:15px 10px 0 60px}, change the values.

查看更多
我想做一个坏孩纸
6楼-- · 2019-08-02 00:29

Change width

#wpcontent_slider_container{
    width: 500px;
    margin:0 auto;
}
查看更多
我想做一个坏孩纸
7楼-- · 2019-08-02 00:30

If you know the width of the slider, here is a little fix that worked for me when center align was being stubborn.

#sliderDiv{
   position:relative;
   left:50%;
   margin-left:-(half the width of the div);
  (ex. if div is at 500px it would be margin-left:-250px;)
 }

It's not pretty, but it works. You might have to hide the horizontal overflow of the outer container though.

查看更多
登录 后发表回答