Linking External Style Sheets

make a navigation button using a div with a link inside it

i just started programming and I wanted to try css with html. However, I keep running into errors like these where I want a button, however when displayed on browser the said button becomes a link. can someone explain?

     h1 < color: blue; >a < color: blue; text-decoration: none; >a:hover 

Click here: Link Button

I wanted to give it a border, background and text color also, and make it change when theres a mouse over it with the code.

2 Answers 2

If you want a button then simply use instead of :

However, you can’t use href with a button since buttons are suited for forms. In this case you can either style the link to look like a button (@RahulB answer) or wrap the (real) button in a form which submits to http://www.w3schools.com.

)">edited Feb 1, 2017 at 4:22
answered Feb 1, 2017 at 4:07
2
Add a comment|
1

You can style the link as button --

a

Источник

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.

Источник

[ Solved – 11 Answers ] CSS – HTML – Make a div into a link

But most-likely what you really want is to have an tag displayed as a block level element.

HTML:

CSS:

Open in new window :

Open in same window :

  • Here’s how to make a div into a clickable link that will open the target URL into the same window.

The code :

  • You could also try by wrapping an anchor, then turning its height and width to be the same with its parent.

This is one of the solution :

Try this code :

You can make surround the element with a href tags or you can use jquery and use

Wikitechy Editor

Wikitechy Founder, Author, International Speaker, and Job Consultant. My role as the CEO of Wikitechy, I help businesses build their next generation digital platforms and help with their product innovation and growth strategy. I'm a frequent speaker at tech conferences and events.

Related Tags
  • clickable div bootstrap,
  • div a css,
  • div link html,
  • div link yale,
  • how to give link to div tag in html,
  • How to Make a div a Clickable Link - HTML & CSS,
  • How to make a whole div clickable?,
  • href to div on same page,
  • html - How do I make entire div a link?,
  • html - How do you make a div tag into a link,
  • Javascript - Make Div Into A Clickable Link,
  • Make a whole div clickable,
  • make div clickable javascript,
  • make div clickable jquery,
  • Make Entire Div Clickable,
  • Turn an Entire DIV into a Clickable Link
Leave a Reply
You May Also Like

How to Modify the URL without reloading the page

PROBLEM: How to Modify the URL without reloading the page? SOLUTION 1: Updating address bar with new URL without hash or reloading the page Example: [pastacode lang=”javascript” manual=”%20function%20processAjaxData(response%2C%20urlPath)%0A%7B%0A%20%20%20%20%20document.getElementById(%22content%22).innerHTML%20%3D%20response.html%3B%0A%20%20%20%20%20document.title%20%3D%20response.pageTitle%3B%0A%20%20%20%20%20window.history.pushState(%7B%22html%22%3Aresponse.html%2C%22pageTitle%22%3Aresponse.pageTitle%7D%2C%22%22%2C%20urlPath)%3B%0A%20%7D%0A%0A” message=”javascript code”…

[Solved – 10 Answers] Click through a DIV to underlying elements

PROBLEM we have a div that has background:transparent, along with border. Under this div, we have more elements. Currently, we able to click the underlying elements when we click outside…

How to remove border (outline) around text/input boxes

PROBLEM: How to remove the orange or blue border (outline) around text/input boxes? It only happens on Chrome to show that the input box is active. Here’s the input CSS…

How to apply CSS to iframe

HTML – CSS – iframe css example – How to apply CSS to iframe – An IFrame (Inline Frame) is an HTML document embedded inside another HTML document on

Is there a “previous sibling” CSS selector

Explaining about CSS Selector Cascading Style Sheets: A CSS selector is the part of a CSS rule set that actually selects the content you want to style. CSS Syntax: A CSS rule-set consists of a…

Offsetting an html anchor to adjust for fixed header

PROBLEM: Offsetting an html anchor to adjust for fixed header? SOLUTION 1: You could use CSS without any javascript. Give your anchor a class: [pastacode lang=”markup” manual=”%3D%22%3Ca%20classanchor%22%20id%3D%22top%22%3E%3C%2Fa%3E%0A” message=”HTML CODE” highlight=””…

Источник

putting the link in the div will only make the text a link and not the whole div.
the reason i've got the div in there is becuase i use it to create a box and add a colored background to this.

I also need to be able to achieve the same thing, with a list item.
e.g. I currently have

I need to make a whole div, become a link.

but this does not validate as xhtml strict.

putting the link in the div will only make the text a link and not the whole div.
the reason i've got the div in there is becuase i use it to create a box and add a colored background to this.

It doesn't validate because it should be like this:

I don't know where your learning from, but I would stop. Try here It's a pretty good tutorial on HTML.

Oh, and w3schools.com is an excellent source for HTML, CSS, and PHP (IMHO), although I don't think you need it.

A div cannot be made into a link. It is a structural element, and block level, and is not content by itself. is inline only and will not work on block level elements.

Can't remember where i read it, it was a while back, so can't remember if i'm doing it the right way.

The div that i have represents a small box on the screen, this box contains an image and a


tag and some text. The whole things needs to be a link.

i'm already using the javascript onclick method on the div, but i wanted to do it without using javascipt to make it more SEO friendly.

has anyone ever tried anything similar, or is there a better way of doing it, to acheive the same resutls.
Thanks

Can't remember where i read it, it was a while back, so can't remember if i'm doing it the right way.

The div that i have represents a small box on the screen, this box contains an image and a


tag and some text. The whole things needs to be a link.

i'm already using the javascript onclick method on the div, but i wanted to do it without using javascipt to make it more SEO friendly.

has anyone ever tried anything similar, or is there a better way of doing it, to acheive the same resutls.
Thanks

Depending on where your putting the text you can just make the image a link.

It can be done with javascript, like this:

In the syleheet add:
cursor: pointer;
to your div.

I didn't know

had "onclick" as an attribute. Which makes me want to look further into making a div as a link. Just wrapping around a
will work but the validator complains about it.

I guess
display:block;
seems to do the trick.
technically it wouldn't be a div as a link but same difference.

The book I'm reading suggests setting the display property of the anchor to block.

The div that i have represents a small box on the screen, this box contains an image and a


tag and some text. The whole things needs to be a link.

I believe there's no point of inserting an image and


inside a link. A good alternative can be if you use display: block (as you already know), then use the image as a background-image with no-repeat, stuff a padding-left (or which ever side you want the image to be) according to the size of the image, and then finally replace the


with border-bottom.
If you want an encapsulating border for this whole thing, pack it inside a div tag (w3c'cally legal) with required border and a small padding.

One: The OP wants it to validate. CSS doesn't cause HTML to validate. A block element cannot be placed in an inline element, regardless of the CSS. So, placing the DIV inside of the A won't work.

Two: Part of the lack of validation is that the LI element should be the only direct child of the UL element. The A element cannot be the direct child of the UL element.

Three: ~jermouri has it right, to a point. However, giving the block element a "cursor:pointer" style doesn't address the fact that clicking it will accomplish nothing.

So, the answer that you are looking for is to simply use an element other than DIV. For validation, you'll want to use an inline element. You could use SPAN, as suggested by ~jermouri, or you could use an element with more meaning. I, personally, am more likely to choose STRONG, EM, B, or I before resorting to SPAN.

You can then use CSS to make these elements block elements. The reason that hte HTML must validate without the CSS is because the HTML should be able to stand on its own without the CSS. Without CSS, block elements inside of inline elements makes no sense.

Источник

Читайте также:  Java io printstream println
Оцените статью