简体   繁体   中英

how to position the <span> with background to the center?

I created a slider seeker but cant seem to get it to the center of the div. I used span and kept the background-image as the seeker image. How do I set the position to the center. Is there any other good method to implement this.

   <div class="slider-seeker">
     <a href="#"><span class="position-image active"></span></a>
     <a href="#"><span class="position-image"></span></a>
     <a href="#"><span class="position-image"></span></a>
     <a href="#"><span class="position-image"></span></a>
    </div>

http://jsfiddle.net/j1bnbf3q/

Solution 1

Create a wrapper div to contain the seeker buttons, and centralize the wrapper: http://jsfiddle.net/pwLsb290/

Solution 2

Apply display: inline-block; on the seeker buttons, and get rid of the float property. (The problem with this method is the whitespace associated with inline-block elements.) http://jsfiddle.net/26dk1zeL/

Used to this css add your .position-image display:inline-block property and remove float: left; as like this

.position-image{
    /* float: left; */  // remove this
    display: inline-block;  // add this
    vertical-align: top;   // add this 
}

=========== 2nd option is

Demo used to this

.slider-seeker > a {
    display: inline-block;
    vertical-align: top;
}

See fiddle

CSS:

.slider-seeker a{
 margin:0px auto;
}
.position-image {
 display:inline-table;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM