{"id":4124,"date":"2023-01-03T02:24:45","date_gmt":"2023-01-03T02:24:45","guid":{"rendered":"https:\/\/isophal.com\/?p=4124"},"modified":"2023-01-03T02:24:46","modified_gmt":"2023-01-03T02:24:46","slug":"how-to-create-menu-in-html-with-css","status":"publish","type":"post","link":"https:\/\/isophal.com\/news\/2023\/01\/03\/4124.html\/","title":{"rendered":"How to Create Menu in HTML with CSS"},"content":{"rendered":"\n<p>Another popular part of websites is menu. Basically, it&#8217;s a list of items which are often just simple links pointing to other places on the site. Let&#8217;s implement it! We will start with the following HTML code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n  &lt;head&gt;\n      &lt;meta charset=\"utf-8\"&gt;\n      &lt;title&gt;Menu&lt;\/title&gt;\n      &lt;link rel=\"stylesheet\" href=\"main.css\" media=\"screen\"&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;nav&gt;\n      &lt;ul&gt;\n        &lt;li&gt;\n          &lt;a href=\"index.html\"&gt;Home&lt;\/a&gt;\n        &lt;\/li&gt;\n        &lt;li&gt;\n          &lt;a href=\"training.html\"&gt;Training&lt;\/a&gt;\n        &lt;\/li&gt;\n        &lt;li&gt;\n          &lt;a href=\"conferences.html\"&gt;Conferences&lt;\/a&gt;\n        &lt;\/li&gt;\n        &lt;li&gt;\n          &lt;a href=\"about.html\"&gt;About us&lt;\/a&gt;\n        &lt;\/li&gt;\n      &lt;\/ul&gt;\n    &lt;\/nav&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>Our menu will consist of four items:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Home<\/li>\n\n\n\n<li>Training<\/li>\n\n\n\n<li>Conferences<\/li>\n\n\n\n<li>About us<\/li>\n<\/ul>\n\n\n\n<p>We want it to look something like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"636\" height=\"362\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2023\/01\/image.png\" alt=\"\" class=\"wp-image-4125\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image.png 636w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-600x342.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-300x171.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-585x333.png 585w\" sizes=\"auto, (max-width: 636px) 100vw, 636px\" \/><\/figure>\n\n\n\n<p>You might notice that under the&nbsp;&lt;body&gt;&nbsp;tag, we&#8217;ve added the new tags&nbsp;&lt;nav&gt;,&nbsp;&lt;ul&gt;, and&nbsp;&lt;li&gt;.<\/p>\n\n\n\n<p>&lt;nav&gt;&nbsp;is used for specifying all kinds of navigation functions on websites that contain links to internal or external information. So putting&nbsp;&lt;nav&gt;&nbsp;into the code says &#8220;everything inside &lt;nav&gt; will be used to navigate around the website.&#8221;<\/p>\n\n\n\n<p>Within&nbsp;&lt;nav&gt;, we place the&nbsp;&lt;ul&gt;&nbsp;tag followed by several&nbsp;&lt;li&gt;&nbsp;tags. The tag&nbsp;&lt;ul&gt;&nbsp;represents an &#8220;unordered list&#8221; (like a bullet list) and the&nbsp;&lt;li&gt;&nbsp;tags represent each individual component of that list (single bullet). When creating websites, it&#8217;s common that an unordered list will be the most reasonable choice when it comes to mapping menu pages. In fact, the menu is kind of a list of links that has been created without a predetermined rule as to the order of its elements.<\/p>\n\n\n\n<p>With just the code above that is still unfinished, our list should be displayed as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"744\" height=\"260\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2023\/01\/image-1.png\" alt=\"\" class=\"wp-image-4126\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-1.png 744w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-1-600x210.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-1-300x105.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-1-585x204.png 585w\" sizes=\"auto, (max-width: 744px) 100vw, 744px\" \/><\/figure>\n\n\n\n<p>The next tag is then&nbsp;&lt;ul&gt;, which begins the unordered list. We want our list to be displayed slightly differently than the default. The most important thing is to have a new background:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nav ul {\n  background-color: PaleVioletRed;\n}\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"658\" height=\"262\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2023\/01\/image-2.png\" alt=\"\" class=\"wp-image-4127\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-2.png 658w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-2-600x239.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-2-300x119.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-2-585x233.png 585w\" sizes=\"auto, (max-width: 658px) 100vw, 658px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>nav ul {\n  background-color: PaleVioletRed;\n  list-style: none;\n}\n<\/code><\/pre>\n\n\n\n<p>It looks much better:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"574\" height=\"216\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2023\/01\/image-3.png\" alt=\"\" class=\"wp-image-4128\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-3.png 574w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-3-300x113.png 300w\" sizes=\"auto, (max-width: 574px) 100vw, 574px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>nav ul {\n  background-color: PaleVioletRed;\n  list-style: none;\n  padding: 0;\n}\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"478\" height=\"198\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2023\/01\/image-4.png\" alt=\"\" class=\"wp-image-4129\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-4.png 478w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-4-300x124.png 300w\" sizes=\"auto, (max-width: 478px) 100vw, 478px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>nav ul {\r\n  background-color: PaleVioletRed;\r\n  list-style: none;\r\n  padding: 0;\r\n  width: 200px;\r\n  border: 1px solid MediumVioletRed;\r\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"638\" height=\"238\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2023\/01\/image-5.png\" alt=\"\" class=\"wp-image-4130\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-5.png 638w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-5-600x224.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-5-300x112.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-5-585x218.png 585w\" sizes=\"auto, (max-width: 638px) 100vw, 638px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>nav ul li {\n  border-bottom: 1px solid MediumVioletRed;\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"383\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2023\/01\/image-6-1024x383.png\" alt=\"\" class=\"wp-image-4131\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-6-1024x383.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-6-600x224.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-6-300x112.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-6-768x287.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-6-585x219.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-6.png 1044w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Add padding: <br><code>nav ul li { padding: 5px; }<\/code><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"616\" height=\"334\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2023\/01\/image-7.png\" alt=\"\" class=\"wp-image-4132\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-7.png 616w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-7-600x325.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-7-300x163.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-7-585x317.png 585w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>nav ul {\n  background-color: PaleVioletRed;\n  list-style: none;\n  padding: 0;\n  width: 200px;\n  border: 1px solid MediumVioletRed;\n}\nlist-style: none;\nnav ul li:last-child {\r\n  border-bottom: none;\r\n}\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"344\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2023\/01\/image-8.png\" alt=\"\" class=\"wp-image-4133\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-8.png 624w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-8-600x331.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-8-300x165.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-8-585x323.png 585w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;a href=\"url\">Text entered here will take you to the specified web address&lt;\/a>\n&lt;a href=\"training.html\">Training&lt;\/a>\nnav ul li a {}\nnav ul li a {\r\n  color: white;\r\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"344\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2023\/01\/image-9.png\" alt=\"\" class=\"wp-image-4134\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-9.png 624w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-9-600x331.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-9-300x165.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-9-585x323.png 585w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>nav ul li a {\n  color: white;\n  text-decoration: none;\n}\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"620\" height=\"338\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2023\/01\/image-10.png\" alt=\"\" class=\"wp-image-4135\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-10.png 620w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-10-600x327.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-10-300x164.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2023\/01\/image-10-585x319.png 585w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>nav ul li a:hover {\n  text-decoration: underline;\n}<\/code><\/pre>\n\n\n\n<p>In summary, the final CSS code should look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nav ul {\n  background-color: PaleVioletRed;\n  list-style: none;\n  padding: 0;\n  width: 200px;\n  border: 1px solid MediumVioletRed;\n}\n\nnav ul li {\n  border-bottom: 1px solid MediumVioletRed;\n  padding: 5px;\n}\n\nnav ul li:last-child {\n  border-bottom: 0;\n}\n\nnav ul li a {\n  color: white;\n  text-decoration: none;\n}\n\nnav ul li a:hover {\n  text-decoration: underline;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Another popular part of websites is menu.&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4136,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[382,374,2],"tags":[207,73],"class_list":["post-4124","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","category-css-style","category-html","tag-css","tag-html"],"_links":{"self":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/comments?post=4124"}],"version-history":[{"count":1,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4124\/revisions"}],"predecessor-version":[{"id":4137,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4124\/revisions\/4137"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/media\/4136"}],"wp:attachment":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/media?parent=4124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/categories?post=4124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/tags?post=4124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}