-1

I just started to learn CSS and created a sample page on my local portal. I would like to know whether these style of coding is correct or not.

I came to know that these style of coding doesn't work in major extents.

Could you correct my code according to make it much more feasible and I would try to learn some of your coding styles and will adapt it to my convinience.

Sorry if these sort of questions can't be asked in this site.

<div class="initial">

<div style="position:relative; width:100%; margin-Top: 4.75%; font-size: 1.3em; font-family: Helvetica; text-align: center; background-color: #bbb;">
<center><p style='line-height:200%'>

<a href=h.php style="text-decoration: none; color:white"> Home</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<a href=click.php style="text-decoration: none; color:white">Please Click Here</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<a href=contact.php style="text-decoration: none; color:white">Contact</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<a href=about.php style="text-decoration: none; color:white">About Me</a></p></center>
    
</style>
</div>
</div>

Thanks,

Novice
  • 141
  • 1
  • 11

3 Answers3

2

At first points to be noted..

  1. Don't use inline CSS
  2. Instead of using &nbsp; use either margin or padding
  3. Margin and padding let's you give space between two tags

See the snippet how i implement the padding

.initial-content {
  position: relative;
  width: 100%;
  margin-Top: 4.75%;
  font-size: 1.3em;
  font-family: Helvetica;
  text-align: center;
  background-color: #bbb;
}
p {
  line-height: 200%;
}
a {
  text-decoration: none;
  color: white;
  padding: 5px 25px;
}
<div class="initial">

  <div class="initial-content">
    <center>
      <p>

        <a href=h.php> Home</a>
        <a href=click.php>Please Click Here</a>
        <a href=contact.php>Contact</a>
        <a href=about.php>About Me</a>
      </p>
    </center>

  </div>
</div>
Amit singh
  • 1,886
  • 1
  • 11
  • 19
1

Things to Note:

  1. HTML skeleton is missing.
  2. CSS can be used seperately rather inline.
  3. Instead of nbsp you need to use margins and padding. You need to know float.
DDphp
  • 390
  • 2
  • 3
  • 16
  • Thanks for sharing. Will work it out on the margins now but i would like to know why to use padding property in this code? – Novice Sep 25 '15 at 11:25
  • @Novice Think like this: "What information I want to deliver to user?" - your HTML should answer this question. "How I want it to look like?" - use CSS to achieve that. – akasummer Sep 25 '15 at 11:28
  • @Novice In this example you are using ` ` for visual purposes, that should be your trigger to substitute it with correct CSS – akasummer Sep 25 '15 at 11:30
0

Well, if it 'doesn't work in major extents', you answered half a question: it means it's not correct. What exactly is not correct:

  1. Inline CSS should work fine, and you can use it for testing. But you should otherwise use a css file. Use identifiers like ids and classes.
  2. href attribute value must be inside quotes or double quotes.
  3. </style> closing doesn't close anything. You could use css code inside these tags, but it's more appropriate to use .css files instead.
  4. &nbsp; thing: Use positioning css. For example, if you want the items aligned vertically, you can use item{clear:left;float:left;}
  5. <center> tag is deprecated. Why? Use instead:<div class="centered(or whatever you feel like calling it)"> and style it:.centered{width: 60%;margin:auto;}

But the rest is just right.

Community
  • 1
  • 1
Vali S
  • 1,366
  • 2
  • 9
  • 17