tags:

views:

65

answers:

2

I want to do this using only CSS + HTML. It has to work in all major/latest browsers - not IE 6 just yet.

The code I have is as follows:

<div id="left_arrow"> 
        <img src="images/left-arrow.png">
    </div>

#left_arrow {
    position: absolute;
    left: 0px;          
    margin: 10px 0 15px 0;  /* top, right, bottom, left */  
    padding: 5px 5px 7px 5px;   /* top, right, bottom, left */  
}

I tried doing the position as 'absolute', but if the browser size changes the arrow doesn't move and I want it to always be at the center of the browser regardless of the size.

Edit:

I want it to always be at the center of this div:

<div id="images" width="100%">
        <img src="image1.jpg" width="45%">
        <img src="image2.jpg" width="45%">
</div>

This is the entire block of code that it is within:

<div id="compare_view" align="center">

    <div id="compv-navbar">
        <a href="#"><img src="icon1.png" id="icon1"></a> | 
        <a href="#"><img src="icon2.png" id="icon2"></a> | 
        <a href="#"><img src="icon3.png" id="icon3"></a> | 
        <span id="view_name"> text </span>
    </div>

    <div id="left_arrow"> 
        <img src="images/left-arrow.png">
    </div>

    <div id="right_arrow"> 
        <img src="images/right-arrow.png">
    </div>

    <div id="images" width="100%">
        <img src="image1.jpg" width="45%">
        <img src="image2.jpg" width="45%">
    </div>

    <div id="notice">
        Notice will be here.
    </div>

</div>

Edit 2: If there is no CSS solution, a jQuery solution is also fine.

Edit 3: Still no takers? bump

+1  A: 

I've had succes using "text-align:center" for the horizontal centering. For the vertical centering, try this:

.vBox {min-height: 12em;   display: table-cell;   vertical-align: middle; }

 <div class="vBox"> <p>Lorem Ipsum is simply dummy text </p> </div>

Cheers, Erik

Erik
Nah...that didn't work for me.
marcamillion
Remember that I am trying to center an image inside a div, essentially centering the div. Not just text.
marcamillion
+1  A: 

Have a look at 'Dead Centre'.

Alexander
This is a start. The issue is that there are other elements on the page, and that solution doesn't quite work with my situation. However, I like the direction they are going.I will continue looking at it.
marcamillion
Another issue with this solution, is that they can statically set the top coordinates to be negative half of the height of the 'content' box that the 'Dead Centered' text is in.In my situation, the div that I want the arrows to always be at the center of, changes height depending on the browser size - because the images inside change size. The browser automatically resizes the images accordingly. As such, the height changes and the arrow positions would be thrown off :|
marcamillion