A style attribute on a <nav> tag assigns a unique style to the element.
Its value is CSS that defines the appearance of the nav element.
A style attribute on a <nav> element.
<nav style="background: indigo; padding: 10px; text-align: center; font-size:16px;">
<a style="color:white;margin-right:20px;" href="javascript:alert('Home was clicked')">Home</a>
<a style="color:white;margin-right:20px;" href="javascript:alert('Gallery was clicked')">Gallery</a>
<a style="color:white;margin-right:20px;" href="javascript:alert('Contact Us was clicked')">Contact Us</a>
<a style="color:white;margin-right:20px;" href="javascript:alert('About was clicked')">About Us</a>
</nav>
The style attribute specifies the style, i.e. look and feel, of the <nav> element.
A style contains any number of CSS property/value pairs, separated by semicolons (;).
The style attribute overrides any other style that was defined in a <style> tag or an external CSS file.
This inline styling affects the current <nav> element only.
<nav style="CSS-styles">
Value | Description |
---|---|
CSS-styles | One or more CSS property/value pairs separated by semicolons (;). |
A style attribute on a <nav> element.
Clicking the button will align the links vertically.
<style>
.nav {display:flex;background:indigo; padding: 8px 20px;}
.nav a {margin: 5px 20px; font-size:16px; color:white; text-decoration:none;}
</style>
<nav id="mynav" style="flex-direction: row;" class="nav">
<a href="javascript:alert('Home was clicked')">Home</a>
<a href="javascript:alert('Gallery was clicked')">Gallery</a>
<a href="javascript:alert('Contact Us was clicked')">Contact Us</a>
<a href="javascript:alert('About was clicked')">About Us</a>
</nav>
<br />
<button onclick="toggle();">Toggle style</button>
<script>
let toggle = () => {
let element = document.getElementById("mynav");
if (element.style.flexDirection === "row") {
element.style.flexDirection = "column";
} else {
element.style.flexDirection = "row";
}
}
</script>
The style attribute assigns a layout of the <nav> element.
Clicking the button calls JavaScript, changing the layout of the <nav> to vertical.
Here is when style support started for each browser:
Chrome
|
6.0 | Sep 2010 |
Firefox
|
4.0 | Mar 2011 |
IE/Edge
|
9.0 | Mar 2011 |
Opera
|
11.0 | Dec 2010 |
Safari
|
5.0 | Jun 2010 |
Back to <nav>