div class and style

This article will show you how to have different link style (colors, size, effect) in different areas in the site or on the same page.

You can download a sample html file at the end of this page.

To set an overall style for your links in site your CSS will look like this:

a:link is where you set the link colors, background color, size, etc.

a:visited is a link color, size, padding, etc for a link that has already being clicked, visited

a:hover is link settings for the moment when mouse is over the link

Now what about if you want to have one link color in top area of your site (header) and another link color in the bottom area of your site (footer)?! In this case you need to place the html code of the link inside a

.

, give that div a class name then customize that class in CSS, for example here is the html code for the » header » area:

Then the CSS for the «header» area is like this. you add the dot and class name in front of the default a:link and a:hover:

.header a:link < color:#006699; font-size:14px; text-decoration:none; padding:5px; background-color:#DDEEFF; >.header a:visited < color:#003399; font-size:14px; text-decoration:none; padding:5px; background-color:#DDEEFF; >.header a:hover

For other areas of the page do the same, place links in a div, give it a class name like header, footer, left_links, top_links, etc then inside the CSS file write that class name before the a:link.

Источник

The first solution uses CSS absolution position, which is a bad practice most of the time. You can scroll down to see the other solution.

Create HTML

Create CSS

  • Set the position to «absolute» for the inner tag.
  • Use the z-index property to place the link above all the other elements in the div.
.container < font-size: 5em; background-color: #a8a8a8; color: white; width: 8em; height: 2em; line-height: 2; text-align: center; font-family: Helvetica, Arial, sans-serif; font-weight: bold; cursor: pointer; position: relative; > .link < position: absolute; width: 100%; height: 100%; top: 0; left: 0; z-index: 1; >
HTML> html> head> style> .container < font-size: 5em; background-color: #a8a8a8; color: white; width: 8em; height: 2em; line-height: 2; text-align: center; font-family: Helvetica, Arial, sans-serif; font-weight: bold; cursor: pointer; position: relative; > .link < position: absolute; width: 100%; height: 100%; top: 0; left: 0; z-index: 1; > style> head> body> div class="container"> W3Docs a href="https://www.w3docs.com/"> span class="link"> span> a> div> body> html>

Result

You can also use the nested inside a hyperlink.

Second solution: making a div a clickable link by nesting it in the tag:

HTML> html> head> style> a < display: block; background: orange; padding: 20px; text-align: center; > style> head> body> a href="https://www.w3docs.com/learn-html/html-introduction.html"> div> This is a clickable div. div> a> body> html>

As the div takes place inside the anchor tag, the anchor tag covers all the div’s area, and thus the div becomes a clickable link.

Источник

HTML div style class

Inserting style for div, there are three ways:
External style sheet, — In this case we make file as style.css where we add CSS style
Internal style sheet, — We add CSS style betweenthem:

Inline style,
For any on your page, you can specify any CSS property as: color, font-style, font-family, font-size, background, etc.

Example: On this window you can edit online this script,
div class and internal style.

 




.text font-family: Verdana, Geneva, sans-serif;
font-size: 16px;
color: #09C;
background-color: #CCC;
margin: 12px;
padding: 15px;
>



Add your text here


Note: try to avoid inline-css, you have to make external style in a separate file as: style.css

Inline html div style

Here, in the next example we show you how to use inline css style what can be applied to div box as: height, width, background and color.

Example: Edit online this window, then Execute to see how you script change page.

 






Add your text here


div style class, border, center, color, background color, width, align center, background image

margin top 24px margin-bottom 20px span style= font size 24px color

How to use div style in HTML

Internal and external style applied for div

You can archieve same style using Internal and External CSS

1. Internal style for html div.

Example: Edit online this window, then Execute to see how you script change page.

 




Here your text:

This is a box useing internal style



2. External style for html div.

HTML div style class

The HTML div style class attribute is used to define equal styles for item with the same class name.
So, all HTML div style class item with the same attribute will have the same format and style.
Here we have three HTML class elements that point to the same class name:

ROMA

ROMA is the capital of Italy.

MADRID

Madrid is the capital of Spain.

SEOUL

Seoul is not the capital of Japan.

div class and style together, div class style css, div class style inline, div class style background image, color, size, full screen, inline, center, combine, background image, html div style width, background color, width percentage, example, attributes, center, display, border, styles
HTML div style — div style class — html tutorial

news templates

news templates

This tool makes it easy to create, adjust, and experiment with custom colors for the web.

news templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

news templates

Find here examples of creative and unique website layouts.

news templates

Find here examples of creative and unique website CSS HTML menu.

news templates

news templates

This tool makes it easy to create, adjust, and experiment with custom colors for the web.

news templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

news templates

Find here examples of creative and unique website layouts.

news templates

Find here examples of creative and unique website CSS HTML menu.

Источник

Читайте также:  Using trees in java
Оцените статью