When building a website with HTML, and CSS. Is it possible to create a link to another page with CSS alone?. To be more specific, I don't want to use an anchor tag with HTML.
CodePudding user response:
No — CSS stands for 'Cascading Style Sheets', It does not provide anything other than styling. You CAN create a link without an A-tag though with Javascript, like this:
// Define your 'link' element
const el = document.getElementById('not-link-element');
// Define your target URL
const href = 'www.url-here.com';
// When your element is clicked, navigate to your target URL
el.addEventListener('click', function () {
window.location.href = href;
});
That said, I highly, highly discourage it and can't see any use case where you'd have a clickable link but wouldn't use an A-tag, so proceed with caution.
CodePudding user response:
It's not possible, as CSS is a styling language. To write content you would need HTML, a markup language.
If you don't want to use HTML directly, you could use JavaScript, a high-level programming language that can manipulate the DOM (Document Object Model). One way to do it is using the write()
method, which you can reference here: https://www.w3schools.com/jsref/met_doc_write.asp.
CodePudding user response:
For do that I recommend to you use an tag
<a href="https://www.w3schools.com">Visit W3Schools.com!</a>
Then you could add to it some css style using a class for example
<a href="https://www.w3schools.com" >Visit W3Schools.com!</a>
Then you could define the style at the css class.
.yourCssClass {
color:blue;
}