2012-10-04 22 views
5

मैं अपने पृष्ठसीएसएस एक केंद्रित तत्व

http://jsfiddle.net/YrBnd/3/

के केंद्र में एक मेज के लिए अगले एक तत्व फ्लोट यह उदाहरण में बटन जगह करना संभव है, बस तालिका के बाईं ओर ?

|     | 
| $$center  | 
|     | 

कहाँ बटन मैं केंद्र बंद रखना चाहते हैं $$ है:

यह उच्च कुशल ड्राइंग आप एक बेहतर तस्वीर देना चाहिए।

+0

+1 "बेहद कुशल" के लिए: पी'। – Bojangles

+0

चित्रों में कौशल नहीं हो सकता है, लोग कर सकते हैं। – Bentley4

उत्तर

8

इस दृष्टिकोण की कोशिश करो, अपने jsfiddle के आधार पर:

एचटीएमएल

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

सीएसएस

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

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

बटन बिल्कुल रखा गया है से, दायां किनारा , अवधि तत्व की चौड़ाई के 100% तक।

+0

प्रतिभा! मेरा जवाब हटाना – GolezTrol

+0

सरल। धन्यवाद। – Norse

-2

आप इसे jquery के साथ हल कर सकते हैं।

पृष्ठ लोड पर

आप जाँच कर सकते हैं जहां मेज शुरू होता है और उसके बाद इस तालिका

उदाहरण के लिए

$(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 }); 
}); 

एट देखा के बाईं ओर बटन जोड़ने;)

+2

यदि jQuery के साथ किया जा सकता है तो JQuery का उपयोग न करें। – 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>