Result:
However, we should remove the index and margin, padding from the list:
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
Full code like this:
Note: This code is used for both horizontal and vertical navigation bars.
To build a vertical navigation bar, you continue to format the element inside the list in the example above, adding the code below:
li a {
display: block;
width: 60px;
}
Also, you can set the width of both
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 60px;
}
li a {
display: block;
}
Create a simple vertical navigation bar with a certain background color and change the background color of the path when the user hovers over it:
Add 'active' to the current link so that users know what category they're currently viewing:
.active {
background-color: #58257b;
color: white;
}
Add text-align: center in
Add the border attribute
ul {
border: 1px solid #db7093;
}
li {
text-align: center;
border-bottom: 1px solid #db7093;
}
li:last-child {
border-bottom: none;
}
Create a navigation bar defining the height, fixed on the left:
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 25%;
background-color: #f1f1f1;
height: 100%; /* chiều cao 100% */
position: fixed; /* cố định thanh điều hướng cả khi cuộn để đọc website */
overflow: auto; /* nếu nội dung quá dài sẽ có thêm thanh cuộn để xem phần còn lại */
}
What is CSS?
CSS stands for English phrase "Cascading Style Sheet".
CSS describes how HTML elements display on screens and methods
Other convenience.
CSS is very useful and convenient. It can control all pages
on a website.
The external stylesheet is stored as .CSS files.
Why should CSS be used?
CSS is used to define styles for pages on the website
you, including the design, the layout and the different ways to display it
device with different screen sizes.
CSS helps solve big problems of HTML.
HTML does not have an element to format the web page. HTML only
used to create content for the site. When elements like and attribute
Colors are added to HTML 3.2, the nightmare of web developers
begin. Developing a large website that adds font or color information
sharpness on each page requires a lot of time.
To solve this problem, the World Wide Web Consortium (W3C) has created
CSS, eliminating style formatting from HTML pages. Definitions
related to the style that is included in the .css file and thanks to the file
External stylesheet, you can change the whole website with just one episode
Unique news.
Note :
There are 2 ways to create a horizontal navigation bar, that is to use a list inline or float .
Inline is a way to display elements on the same row. To create a horizontal navigation bar, you add the display: inline attribute to the element
li {
display: inline;
}
By default,
Another way to create horizontal navigation bar is float elements
li {
float: left;
}
a {
display: block;
padding: 8px;
background-color: #e9d8f4;
}
Create a simple horizontal navigation bar with a background color and change the background color of the path when the user hovers over it:
Add 'active' to the current link so that users know what category they're currently viewing:
.active {
background-color: #58257b;
color: white;
}
You can push an element to the right of the screen according to the layout of the website using float: right
Add a right border to all list items, except for the last item, to divide the navigation bar into clearer items.
li {
border-right: 1px solid #db7093;
}
li:last-child {
border-right: none;
}
ul {
border: 1px solid #d6b7eb;
background-color: #e9d8f4;
}
li a {
color: #black;
}
1. Use position: fixed
Fixed the navigation bar at the top or bottom of the page even when users use the scroll bar to move page content:
Fixed top side Fixed bottom side
ul {
position: fixed;
top: 0;
width: 100%;
}
ul {
position: fixed;
bottom: 0;
width: 100%;
}
CSS helps a lot when writing a website in HTML.
CSS stands for English phrase "Cascading Style Sheet".
CSS describes how HTML elements display on screens and methods
Other convenience.
CSS is very useful and convenient. It can control all pages
on a website.
The external stylesheet is stored as .CSS files.
CSS is used to define styles for pages on the website
you, including the design, the layout and the different display ways
Many devices with different screen sizes.
HTML does not have an element to format the web page. HTML only
used to create content for the site. When elements like and attribute
Colors are added to HTML 3.2, the nightmare of web developers
begin.
To solve this problem, the World Wide Web Consortium (W3C) has created
CSS, eliminating style formatting from HTML pages.
2. Use position: sticky
Using this attribute, the original menu will still have a flexible position until a certain location and "stick" there.
ul {
position: -webkit-sticky; /* áp dụng với Safari */
position: sticky;
top: 0;
}
Knowledge - Experience - FAQ
CSS helps a lot when writing a website in HTML.
CSS stands for English phrase "Cascading Style Sheet".
CSS describes how HTML elements display on screens and methods
Other convenience.
CSS is very useful and convenient. It can control all pages
on a website.
The external stylesheet is stored as .CSS files.
CSS is used to define styles for pages on the website
you, including the design, the layout and the different display ways
Many devices with different screen sizes.
HTML does not have an element to format the web page. HTML only
used to create content for the site. When elements like and attribute
Colors are added to HTML 3.2, the nightmare of web developers
begin. Developing a large website that adds font or color information
sharpness on each page requires a lot of time.
To solve this problem, the World Wide Web Consortium (W3C) has created
CSS, eliminating style formatting from HTML pages
The meaning is related to the style that is included in the .css file and thanks to the file
External stylesheet information, you can change the entire website with just one
single file.
Previous article: Opacity / Transparency Properties in CSS
Next lesson: CSS Dropdown effect