Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Float an element next to a centered element

I have a table in the center of my page

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

Is it possible to place the button in the example, just to the left of the table?

This highly skilled drawing should give you a better picture:

|                  |
|    $$center      |
|                  |

Where $$ is the button I want to place off center.

like image 986
Norse Avatar asked Oct 04 '12 07:10

Norse


People also ask

What happens if you use a float property on an absolutely positioned element?

Absolutely positioned page elements will not affect the position of other elements and other elements will not affect them, whether they touch each other or not. There are four valid values for the float property. Left and Right float elements those directions respectively.

How do you center text float in CSS?

To center the text using float we can use margin-left or margin-right and make it 50% , like below.

How do you make a div float in the center of the screen?

You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.


1 Answers

Try this approach, based on your 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/

The button is placed absolutely, from the right edge, to 100% of the width of the span element.

like image 60
Josh Davenport-Smith Avatar answered Sep 29 '22 21:09

Josh Davenport-Smith