CSS - Vertical Alignment of icon not showing up correctly

I have been trying to have bins that show up on the right side but they don't appear to have been placed very well, I'm new to CSS, I have looked through the internet and no luck (or I didn't make sense of it). The bin seems to be not in proportion with the background, and so if I want to make it fill the tag it will just overflow off the box.

#container {
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);
    width: 360px;
    background-color: #f7f7f7;
    margin: 100px auto;
}

.completed {
    color: gray;
    text-decoration: line-through;
}

body {
    font-family: Roboto;
    background: #FFAFBD;
    background: -webkit-linear-gradient(to right, #ffc3a0, #FFAFBD);  
    background: linear-gradient(to right, #ffc3a0, #FFAFBD); 

}

li {
    background-color: white;
    height: 40px;
    line-height: 40px;
    color: #666;
}

input {
    font-size: 18px;
    background-color: #f7f7f7;
    width: 100%;
    padding: 13px 13px 13px 20px ;
    box-sizing: border-box;
    color: #2980b9;
}

input:focus{
    background-color: white;
    border: 3px solid #2980b9;
    outline: none;
}

li:nth-child(2n){
    background-color: #f7f7f7;
}

span {
    height: 35px;
    width: 40px;
    display: inline-block;
    margin-right: 20px;
    margin: 0 auto;
    text-align: center;
    color: white;
    background-color: #e74c3c;
}

h1 {
    background-color: #2980b9;
    color: white;
    margin: 0;
    padding: 10px 20px;
    text-transform: uppercase;
    font-size: 24px;
    font-weight: normal;
}

ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

#plus {
    width: 20px;
    height: 20px;
    float: right;
    margin-top: 3px;
}

.remove {
    height: 20px;
    width: 15px;
}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="assets/CSS/todo.css">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="">
    <title>Trello</title>
</head>
<body>

    <div id="container">
        <h1>To-do List <img id="plus" src="assets/Plus.png" alt=""></h1>
        <input type="text" placeholder="Add New Todo...">

        <ul>
            <li><span><img class="remove" src="assets/Bin.png" alt=""></span> Go to potions class</li>
            <li><span><img class="remove" src="assets/Bin.png" alt=""></span> Buy New Robes</li>
            <li><span><img class="remove" src="assets/Bin.png" alt=""></span> Visit Hagrid</li>
        </ul>
    </div>


<script src="assets/JS/lib/Jquery.js"></script>
<script src="assets/JS/Custom/todos.js"></script>
</body>
</html>

Thanks for the help in advance. enter image description here

Upvotes: 0

Views: 58

Answers (2)

syntacticgeorge
syntacticgeorge

Reputation: 1

How about making you span elements the same height as the li so that the red bg fills up completely?

span { height: 40px; }

Just like this?

Upvotes: 0

Alessio
Alessio

Reputation: 3610

Use Flexbox! Give to your <li> and to the <span> a display: flex; This way you can have control of the positioning of its children (in this case your <img>).

li {
    display: flex;
}
span {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 2px 0 0;
}

Here's a working Codepen. Here's a nice guide to Flexbox.

Upvotes: 1

Related Questions