Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to get my anchor text to move up, but it doesn't seem to work no matter what I try. I don't know if I messed up somewhere on my html or css, but I tried using the span element or p elements to add padding to the bottom of the anchor text so it would move up but I don't know if there is any other methods to get my anchor text to move up or not.

I'm trying to get the anchor text that says, "Play" to move up with padding and the span and p elements didn't do anything to it. I also wanted to show a picture of the problem but I don't know how to do it on here.

At the bottom of my CSS you can see where have a selector called "#sidebar p" and I was trying to add some padding to the bottom of it, but it didn't do anything.

Here's my HTML and CSS:
<!DOCTYPE html>
<html>
<head>
    <title>nested anchor links in divs</title>
    <link rel="stylesheet" href="styles/styling.css">
</head>

<body>
    <div id="outer-container">
        <div id="sidebar">
            <div class="subnav">
                <a href="#" id="subnavbtn"><img src="images/play logo.webp" alt="play" id="play" height='25px' width='25px'><p>Play</p></a>
            </div>


        </div>
        <div id="content">




        </div>
    </div>

</body>

</html>


html {
	height: 100%;
}

body {
	margin: 0;
	height: 100%;
}

#outer-container {
	display: table;
	width: 100%;
	height: 100%;
}

#sidebar {
	display: table-cell;
	width: 15%;
	height: 100%;
	vertical-align: top;
	background-color: rgb(68, 68, 68);
}

#content {
	display: table-cell;
	width: 85%;
	vertical-align: top;
	background-color: gray;
}

#subnav #subnavbtn {
	font-size: 16px;  
	border: none;
	outline: none;
	color: rgb(214, 208, 208);
}
#sidebar a {
	background-color: rgb(20, 15, 15); 
	color: white; 
	display: block; 
	padding: 10px; 
	text-decoration: none; 
}

#sidebar p {
	padding-bottom: 1em;
	display: inline;
}

#sidebar img {
	padding-top: .2em;
	padding-right: .1em;
}


What I have tried:

I've tried using p and span elements but they don't work on the anchor text for some reason.
Posted
Updated 7-Aug-21 5:14am
v2

1 solution

So steps are as follows:
1. You wrap your "play" text into div to apply block layout
2. You switch the order of your contents

HTML
<a href="#" id="subnavbtn">
	<div class="play">Play</div>
	<img id="play" src="images/play logo.webp"  height='25px' width='25px'>                   
</a>

3. You apply margin to your image
CSS
#play {
  margin-top: 25px;
}

Here's the fiddle
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900