<div id="app">
<div class="navigation">
<ul>
<li v-for="(link, index) in links">
<a :href="link.url">
{{ link.text }}
</a>
<span class="removeHover">
<button @click="removeLink(index)">X</button>
</span>
</li>
</ul>
</div>
<div class="navigation--input">
<label for="" >Link Title</label>
<input v-model="newLink" type="text">
<label for="">Link URL</label>
<input v-model="newURL" @keyup.enter="addLink" type="text">
<span class="error" v-if="isEmpty" v-model="error">Error! {{ error}}</span>
<button @click="addLink">Add to Navigation</button>
</div>
</div>
body {
padding: 0;
margin: 0;
}
.navigation {
background-color: #ddd;
width: 100%;
margin: 0;
ul {
margin: 0;
padding: 20px 0;
text-align:center;
}
li {
display: inline-block;
padding: 0 20px;
position: relative;
a {
color: #555;
text-decoration: none;
&:hover {
border-bottom: 2px solid;
}
}
}
&--input {
width: 20%;
text-align: center;
padding: 40px 0;
margin: 0 auto;
input {
margin: 10px auto 0 auto;
border-radius: 5px;
border: 1px solid #ddd;
padding: 5px;
display: block;
width: 100%;
}
button {
margin-top: 20px;
background-color: cornflowerblue;
padding: 10px 24px;
border-radius: 3px;
color: #fff;
transition: all .3s ease-out;
&:hover {
background-color: navy;
}
}
label {
text-align: left;
display: block;
&:not(:first-child){
margin-top: 20px;
}
}
}
}
.removeHover {
opacity: 0;
z-index: 2;
transition: all .3s ease-out;
// &:hover {
// opacity: 1;
// }
li:hover &{
opacity: 1;
}
button {
position: absolute;
text-align: center;
border-radius: 50%;
background-color: lightcoral;
color: #fff;
font-size: .5em;
top: 0;
right: 0;
margin-top: -11px;
padding: 5px;
outline: none;
&:hover {
background-color: coral;
}
}
}
.error {
width: 100%;
display: block;
background-color: #ff000029;
padding: 10px 5px;
margin-top: 14px;
border-radius: 3px;
}
View Compiled
new Vue({
el: '#app',
data: {
isEmpty: false,
error: '',
newLink: '',
newURL: '',
links: [
{ text: 'Home', url: 'http://google.com' },
{ text: 'Work', url: 'http://dribbble.com'},
{ text: 'Blog', url: 'http://medium.com'},
{ text: 'Test', url: 'ham' }
]
},
methods: {
addLink: function() {
var text = this.newLink.trim()
var url = this.newURL.trim()
if ((text !== '') && (url !== '')) {
this.isEmpty = false
this.links.push({ text: text, url: url })
this.newLink = ""
this.newURL = ""
} else {
this.isEmpty = true
this.error = 'Complete all boxes!'
}
},
removeLink: function(index) {
this.links.splice(index, 1)
}
}
})
This Pen doesn't use any external CSS resources.