Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Centered object gets pushed off-center

Featured Replies

On a page, I might have something centered at the top, such as a title graphic. I'd like to float a div box to one side, but I find that it pushes my centered graphic off-center so that it's centered between the edge of the floating box and the other side of the page.

 

I want this:

+--------------------------------------+
|                                      |
| +----+       +-------+               |
| |    |       | title |               |
| |    |       +-------+               |
| |    |                               |
| +----+                               |
|                                      |
|                                      |
+--------------------------------------+

 

I'm getting this:

+--------------------------------------+
|                                      |
| +----+           +-------+           |
| |    |           | title |           |
| |    |           +-------+           |
| |    |                               |
| +----+                               |
|                                      |
|                                      |
+--------------------------------------+

 

css code for floating box:

 

div.floatingbox {

float: left;

width: 100px;

}

 

css code for div surrounding graphic title:

 

div.graphictitle {

text-align: center;

}

This works. The left floatingbox is position: absolute so that it doesn't affect the positioning of the graphictitle. The #wrap div has position: relative so that the position: absolute div takes its position from the top left corner of the #wrap div:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="keywords" content="Wickham">                
<meta name="description" content="Test items">            
<meta http-equiv="content-type" content="text/html; 
charset=iso-8859-1">

<title>Test</title>                  

<style type="text/css">
#wrap { position: relative; width: 600px; margin: auto; background: pink; 
height: 300px; }
.floatingbox { position: absolute; left: 30px; top: 50px; background: lime; 
height: 150px; }
.graphictitle { position: relative; width: 150px; height: 50px; margin: auto; 
top: 50px;background: skyblue; }

</style>

</head>

<body> 
<div id="wrap">
<div class="floatingbox">Left box</div>
<div class="graphictitle">Title</div>
</div>

</body>
</html>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.