2012-10-04 16 views

Odpowiedz

8

Spróbuj podejście, oparte na jsfiddle:

HTML

<span>Center body text<button>Click</button></span> 

CSS

span { 
    display: block; 
    width: 200px; 
    margin: 0 auto; 
    position: relative; 
} 
button { 
    position: absolute; 
    right: 100%; 
} 

http://jsfiddle.net/YrBnd/4/

Przycisk umieszczony jest absolutnie, od prawa krawędź do 100% szerokości elementu przęsła.

+0

Geniusz! Usuwanie mojej odpowiedzi. – GolezTrol

+0

Proste. Dzięki. – Norse

-2

można rozwiązać to za pomocą jquery.

na stronie obciążenia można sprawdzić gdzie rozpoczyna tabeli, a następnie dodać przycisk po lewej stronie tabeli

Na przykład

$(function(){ 
    //Get the left position of the table 
    var leftPosition = $("table").offset().left; 
    //Get the top position of the table 
    var topPosition= $("table").offset().top; 

    //Now add the left position of the table minus the button width and a spacing of 5 
    var leftButtonPosition = leftPosition - $("myButton).width() + 5; 

$("myButton).offset({ top: topPosition + 5 , left: leftButtonPosition }); 
}); 

et voila;)

+2

Nie używaj JQuery, jeśli można to zrobić za pomocą CSS. – GolezTrol

-1
.center 
{ 
    width:250px; 
    margin:0px auto 0px auto; 
} 
.center input[type="button"], div 
{ 
    float:left; 
} 

<div class="center"> 
    <input type="button" name="submit" value="$$" /> 
    <div> center text </div> 
</div> 
Powiązane problemy