This is sample code(HTML):
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="The_secondweb.css">
<meta charset="utf-8">
<title><!-- There will be a title --></title>
</head>
<body>
<h1 >Welcome to this website</h1>
</body>
</html>
This is what I did in CSS:
#title{
text-align: center;
}
Problem:
When I don't use the id attribute the text don't gets aligned to the center, but when I don't use the id attribute the code does what it should. Am I doing something wrong while using the id attribute or we cannot align the text to center using any attribute we should name the tag in CSS?
CodePudding user response:
When you are using class you have to use "." whereas "#" is used in case of id.
You can also do it with inline styling in html as below:
<html>
<head>
<link rel="stylesheet" href="The_secondweb.css">
<meta charset="utf-8">
<title><!-- There will be a title --></title>
</head>
<body>
<h1 style="text-align: center;">Welcome to this website</h1>
</body>
</html>
CodePudding user response:
using # in CSS is id selector
.title{
text-align: center;
}
when your use classes
