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.

Padding help

Featured Replies

padding.png

 

On this design when I try to add padding to the text using CSS, the light gray background moves too. What am I doing wrong?

Have you got your code your code you can post up?

You can add padding to the light grey box say 10px on the left but then reduce the width of the box by the same amount to keep it the same size.

  • Author

#container {
width: 900px
}
#floatright {
float: right;
}
#header {
width: 900px;
height: 200px;
background-color: black;
border-bottom: 2px solid #000000;
font-size: 200px;
font-family: Helvetica;
color: orange;
}
#nav {
float: left;
width: 170px;
height: 400px;
background-color: gray;
border-right: 1px dashed white;
font-family: Tahoma;
font-size: Small;
}
#body  {

width: 900px;
height: 400px;
background-color: #b9b9b9;


}
#body a {
color: white;
text-decoration: none;
font-weight: bold;
font-family: Tahoma;
font-size: small;
}
#body a:visited {
color: white;
text-decoration: none;
font-weight: bold;
font-family: Tahoma;
font-size: small;
}
#body a:hover {
color: orange;

}
#section {
width: 170px;
background-color: white;
font-family: Tahoma;
font-size: small;
font-weight: bold;
}
#footer {
clear: both;
background-color: gray;
font-family: Tahoma;
font-size: Small;
}
.box {
margin-top: 10px;
padding: 5px 5px 5px 5px;
background-color: #dddddd;
border: 2px solid red;
width: 350px;
color: black;

}

 

Basically, I want the text inside "body" to be padded so that it isnt touching the edge.

If you just want padding to all paragraphs

 

you need to put text inbetween <p>your text here</p>

 

css

p{padding:10px;}

 

hth

  • Author

Using <p> offsets the background.

 

<html>
<head>
<style type="text/css">

</style>
<link href="style.css" rel="stylesheet" type="text/css">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

</head>
<body background="dots.gif">

<div id="container">

<div id="header">

<div id="floatright"><img src="photo.png"></div></div>

<div id="nav">
<div id="section">navigation</div>
Links here
</div>
</div>

<div id="body">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
</div>

<div id="footer">
Copyright info</div>


</div>

</body>
</html>

 

Here's the HTML.

  • Author

OK, I've got padding to work now using positioning tags on the body section:

 

padding2.png

 

But now the image is at the back. How to I bring it to the front again?

 

EDIT: Done it using z-index tag. Solved.

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.