Home > other >  How do you hide href="dummy1" attachment to link when clicked on?
How do you hide href="dummy1" attachment to link when clicked on?

Time:11-22

I want to hide the href link attachment to my browser link when I click on each href. For example, when I click on the href="dummy1" I don't want it to show mydomain.com/#dummy1. I want to hide the #dummy1 part. Hope this question makes sense.

Each hypertext scrolls down to a different part of my page.

Here is my CSS and HTML code

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

body {
    background: #000;
    min-height: 200vh;
}

header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: 0.6s;
    padding: 40px 100px;
    z-index: 100000;
}

header .logo {
    position: relative;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    font-size: 3em;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: 0.6s;
}

header.sticky {
    padding: 5px 100px;
    background: #fff;
}

header ul {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

header ul li {
    position: relative;
    list-style: none;
}

header ul li a {
    position: relative;
    margin: 0 15px;
    text-decoration: none;
    color: #fff;
    letter-spacing: 2px;
    font-weight: 500px;
    transition: 0.6s;
}

.banner {
    position: relative;
    width: 100%;
    height: 100vh;
    background: url(IMG-1022.jpg);
    background-size: cover;
}

header.sticky .logo,
header.sticky ul li a {
    color: #000;
}

#home {
    padding-bottom: 500px;
    background-color: aqua;
}

#aboutMe {
    padding-bottom: 500px;
    background-color: orange;
}

#portfolio {
    padding-bottom: 500px;
    background-color: yellow;
}

#contact {
    padding-bottom: 1000px;
    background-color: purple;
}

#wrapper {
    padding-bottom: 50px;
}

#dummy1,
#dummy2,
#dummy3 {
    margin-top: -65px;
}

#aboutMe,
#portfolio, 
#contact {
    margin-top: 65px;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=chrome">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="indexStyle.css">
    <link rel="shortcut icon" type="image/jpg" href="favicon.img"/>
    <title>Document</title>
</head>
<body>
    <header>
        <a href="#" class="logo">My Name</a>
        <ul>
            <li class="page-scroll"><a href="#dummy1">About Me</a></li>
            <li class="page-scroll"><a href="#dummy2">Portfolio</a></li>
            <li class="page-scroll"><a href="#dummy3">Contact</a></li>
        </ul>
    </header>
    <section class="banner"></section>
    <script type="text/javascript">
        window.addEventListener("scroll", function(){
            var header = document.querySelector("header");
            header.classList.toggle("sticky", window.scrollY > 100);
        })
    </script>
    <div id="dummy1"></div>
    <div id="aboutMe">This is the about me section</div>
    <div id="dummy2"></div>
    <div id="portfolio">This is the portfolio section</div>
    <div id="dummy3"></div>
    <div id="contact">This is the contact me section</div>
    
</body>
</html>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

This can be achived by setting the href property to href="" and by attaching a onClick event to the <a> tag to redirect the link after clicking. In the end, it should look like this:

<a href="" onclick="location.href='https://yourSite.com' '#dummy1'">Your text.</a>

CodePudding user response:

For this case you can use JavaScript. Bind your link to a clickevent and set the link target via JS and jump there. This way you can manipulate the link as you like.

function jump (target) {    
  window.location = '#'   target;  
  return false;
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

body {
    background: #000;
    min-height: 200vh;
}

header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: 0.6s;
    padding: 40px 100px;
    z-index: 100000;
}

header .logo {
    position: relative;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    font-size: 3em;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: 0.6s;
}

header.sticky {
    padding: 5px 100px;
    background: #fff;
}

header ul {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

header ul li {
    position: relative;
    list-style: none;
}

header ul li a {
    position: relative;
    margin: 0 15px;
    text-decoration: none;
    color: #fff;
    letter-spacing: 2px;
    font-weight: 500px;
    transition: 0.6s;
}

.banner {
    position: relative;
    width: 100%;
    height: 100vh;
    background: url(IMG-1022.jpg);
    background-size: cover;
}

header.sticky .logo,
header.sticky ul li a {
    color: #000;
}

#home {
    padding-bottom: 500px;
    background-color: aqua;
}

#aboutMe {
    padding-bottom: 500px;
    background-color: orange;
}

#portfolio {
    padding-bottom: 500px;
    background-color: yellow;
}

#contact {
    padding-bottom: 1000px;
    background-color: purple;
}

#wrapper {
    padding-bottom: 50px;
}

#dummy1,
#dummy2,
#dummy3 {
    margin-top: -65px;
}

#aboutMe,
#portfolio, 
#contact {
    margin-top: 65px;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=chrome">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="indexStyle.css">
    <link rel="shortcut icon" type="image/jpg" href="favicon.img"/>
    <title>Document</title>
</head>
<body>
    <header>
        <a href="#" class="logo">My Name</a>
        <ul>
            <li class="page-scroll"><a onclick="return jump( 'dummy1')" href="dummy1">About Me</a></li>
            <li class="page-scroll"><a onclick="return jump( 'dummy2')" href="dummy2">Portfolio</a></li>
            <li class="page-scroll"><a onclick="return jump( 'dummy1')" href="dummy3">Contact</a></li>
        </ul>
    </header>
    <section class="banner"></section>
    <script type="text/javascript">
        window.addEventListener("scroll", function(){
            var header = document.querySelector("header");
            header.classList.toggle("sticky", window.scrollY > 100);
        })
    </script>
    <div id="dummy1"></div>
    <div id="aboutMe">This is the about me section</div>
    <div id="dummy2"></div>
    <div id="portfolio">This is the portfolio section</div>
    <div id="dummy3"></div>
    <div id="contact">This is the contact me section</div>
    
</body>
</html>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related