Jump to content

Recommended Posts

When setting the width or height of any HTML element on the page you need to have a good understanding of the box model.

 

Browsers calculates the width of any HTML element by the following simple formula (l+r stands for left and right):

(borders l+r, padding l+r) + width = width;

 

So if you set up div as follows:

<div style="width: 100px;"> 100px wide DIV</div>

It'll be 100px wide, very simple.

 

Now if you apply 10px padding:

<div style="width: 100px; padding:10px"> 124px wide DIV</div>

The Div will now be 120px wide.

 

The DIV wll increase in size even more if you add a border:

<div style="width: 100px; padding:10px; border:2px solid #FF0000"> 120px wide DIV</div>

it'll now be 124px wide.

 

To keep the div at 100px wide you'll need to set the width 24px less than what it should be, so 76px.

 

The same principle applies to the height also, except this time you consider the top and bottom padding and borders

 

Margins don't have an affect on the size of an element.

Link to comment
https://forums.phpfreaks.com/topic/102351-solved-set-margins/#findComment-524151
Share on other sites

use the font-size property, eg:

 

div {
   font-size: 12px;
}

The above CSS will set any text with a DIV to 12px. If you to set the size to a specific DIV, give it a class eg:

 

<div>Normal sized text</div>

<div class="biggerText">Much Larger text</div>"

Set the following CSS:

.biggerText {
   font-size: 24px;
}

 

You can learn the basic of CSS over W3Schools.com. They also support code demo's which you can test live.

Link to comment
https://forums.phpfreaks.com/topic/102351-solved-set-margins/#findComment-525281
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.