Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Padding the top and the bottom of inline element

Tags:

html

css

xhtml


Quote from Head first html:

You can add padding to the top and bottom of inline element, but the padding doesn’t affect the spacing of the other inline elements around it, so the padding will overlap other inline elements

a) As far as I understand the above quote, adding padding to the top and bottom of inline element doesn’t ( ever ) have any effects on surrounding elements and thus on the look of the page?!

b) But what exactly is meant by “padding will overlap other inline elements”? Does it perhaps suggest that in certain circumstances padding ( top and bottom of an inline element ) will have effect on the look of the page?!


thanx

like image 346
SourceC Avatar asked Sep 09 '09 18:09

SourceC


People also ask

What is padding top and bottom?

The CSS padding properties are used to generate space around an element's content, inside of any defined borders. With CSS, you have full control over the padding. There are properties for setting the padding for each side of an element (top, right, bottom, and left).

How do you do inline padding?

Syntax. The padding-inline property may be specified with one or two values. If one value is given, it is used as the value for both padding-inline-start and padding-inline-end . If two values are given, the first is used for padding-inline-start and the second for padding-inline-end .

Does padding top or padding bottom have an effect on inline elements?

Padding can be given to any display element. However, when applied to an inline element the top and bottom padding's do not affect the surrounding elements.


4 Answers

Use inline-block instead. Add these properties to all the elements on which you want to add padding. For example:

a:link {
display: inline-block;
display: -moz-inline-box;
-moz-box-orient: vertical;
vertical-align: top;
zoom: 1;
*display: inline;
}
like image 145
eozzy Avatar answered Oct 02 '22 12:10

eozzy


If I understand correctly, and from an example I just made:

a) the text is an inline element, so me adding a span with top and bottom padding is not pushing the other lines down

b) as you can see, since I've added a color to the span, the color will overlap the other lines.

I hope this is both right, and answers your question :D

like image 24
theIV Avatar answered Oct 02 '22 12:10

theIV


Try this:

<style type="text/css">
  div { background: blue; height: 4em; padding: 1em }
  span { background: red; padding: .5em; }
</style>

<div>
  <span>one</span>
  <br/>
  <span>two</span>
</div>
like image 35
Michał Górny Avatar answered Oct 02 '22 14:10

Michał Górny


The padding will affect the element itself. For example, any text within the element will be more padded from other DOM elements.

like image 24
Evan Meagher Avatar answered Oct 02 '22 14:10

Evan Meagher