I am trying to follow a tutorial on YouTube to create a toolbar, but I am using Vuejs instead of regular HTML like on the video and the content of the views (.vue files) goes beside the toolbar instead of below it and another thing, I try to make center the toolbar.
<template>
<div id="app">
<div class="toolbar">
<ul>
<li>
Home
</li>
<li>
About
<ul>
<li>
<a href>Our Team</a>
</li>
<li>
<a href>Camp Sites</a>
</li>
<li>
<a href>Mission & Vision</a>
</li>
<li>
<a href>Resources</a>
</li>
</ul>
</li>
<li>
Things to do
<ul>
<li>
<a href>Activities</a>
</li>
<li>
<a href>Parks</a>
</li>
<li>
<a href>Shops</a>
</li>
<li>
<a href>Events</a>
</li>
</ul>
</li>
<li>
Contact
<ul>
<li>
<a href>Map</a>
</li>
<li>
<a href>Directions</a>
</li>
</ul>
</li>
<li>
News
</li>
</ul>
</div>
<div>
<router-view/>
</div>
</div>
</template>
#app {
margin: 0;
padding: 0;
}
body {
background-color: black;
background-size: none;
margin-left: 10%;
}
.toolbar ul {
margin: 0px;
padding: 0px;
list-style: none;
font-family: arial;
}
.toolbar ul li {
float: left;
width: 200px;
height: 40px;
background-color: black;
opacity: 0.8;
line-height: 40px;
text-align: center;
font-size: 20px;
}
.toolbar ul li a {
text-decoration: none;
color: white;
display: block;
}
.toolbar ul li a:hover {
background-color: green;
}
.toolbar ul li ul li {
display: none;
}
.toolbar ul li:hover ul li {
display: block;
}
Whatever what I tried today, either the view was correctly below the toolbar but then the submenus were unclickable, or the views were below and centered but with a big margin-top to make the menu clickable or just beside the toolbar.
I am trying to replicate this kind of toolbar with the views right below it.
I guess the problem is 'float'. You will need a div with clear:both style after the toolbar and before the div containing router-view.
...
div class="toolbar"
...
/div
div style="clear:both"/
div
router-view
...
Related
I have to create left section for a website ".leftpart" in which I have parent navigation class ".nav-links" with CSS properties. I have also have same class ".nav-links" as a sub section under parent ".nav-links". I want to give a different background color "red" to child ".nav-links" [Edit and Save]. Can you anyone suggest best way to do this ?
My code is below, thanks in advance :
.leftpart {
width: 100%;
display: block;
margin: 20px;
}
.leftpart .nav-links ul {
list-style: none;
margin: 0;
padding: 0;
display: block;
}
.leftpart .nav-links ul li {
margin-bottom:20px;
}
.leftpart .nav-links ul li a {
background:green;
color:#fff;
padding: 20px;
display: inline-block;
}
<div class="leftpart">
<div class="nav-links">
<h1> Primary Links </h1>
<ul>
<li>
Profile
</li>
<li>
Friends
</li>
<li>
Milestones
</li>
<li>
Groups
</li>
</ul>
<div class="sub-seciton">
<div class="nav-links">
<ul>
<li>
Edit
</li>
<li>
Save
</li>
</ul>
</div>
</div>
</div>
<div class="nav-links">
<h1> Secondary Links </h1>
<ul>
<li>
Privacy
</li>
<li>
Settings
</li>
</ul>
</div>
</div>
Just use an additional decedent selector only changing the background property:
.leftpart .nav-links .nav-links ul li a {
background: red;
}
.leftpart {
width: 100%;
display: block;
margin: 20px;
}
.leftpart .nav-links ul {
list-style: none;
margin: 0;
padding: 0;
display: block;
}
.leftpart .nav-links ul li {
margin-bottom: 20px;
}
.leftpart .nav-links ul li a {
background: green;
color: #fff;
padding: 20px;
display: inline-block;
}
.leftpart .nav-links .nav-links ul li a {
background: red;
}
<div class="leftpart">
<div class="nav-links">
<h1> Primary Links </h1>
<ul>
<li>
Profile
</li>
<li>
Friends
</li>
<li>
Milestones
</li>
<li>
Groups
</li>
</ul>
<div class="sub-seciton">
<div class="nav-links">
<ul>
<li>
Edit
</li>
<li>
Save
</li>
</ul>
</div>
</div>
</div>
<div class="nav-links">
<h1> Secondary Links </h1>
<ul>
<li>
Privacy
</li>
<li>
Settings
</li>
</ul>
</div>
</div>
You need to target .nav-links inside the sub-section. You can also style your nav-links siblings separately. See my example:
.leftpart {
width: 100%;
display: block;
margin: 20px;
}
.leftpart .nav-links ul {
list-style: none;
margin: 0;
padding: 0;
display: block;
}
.leftpart .nav-links ul li {
margin-bottom:20px;
}
.leftpart > .nav-links ul li a {
background:green;
color:#fff;
padding: 20px;
display: inline-block;
}
.leftpart .nav-links .sub-seciton .nav-links ul li a {
background:red ;
}
.leftpart > .nav-links:nth-child(2) ul li a {
background: blue;
}
<div class="leftpart">
<div class="nav-links">
<h1> Primary Links </h1>
<ul>
<li>
Profile
</li>
<li>
Friends
</li>
<li>
Milestones
</li>
<li>
Groups
</li>
</ul>
<div class="sub-seciton">
<div class="nav-links">
<ul>
<li>
Edit
</li>
<li>
Save
</li>
</ul>
</div>
</div>
</div>
<div class="nav-links">
<h1> Secondary Links </h1>
<ul>
<li>
Privacy
</li>
<li>
Settings
</li>
</ul>
</div>
</div>
Just set your CSS code more specific for it:
.leftpart {
width: 100%;
display: block;
margin: 20px;
}
.leftpart .nav-links ul {
list-style: none;
margin: 0;
padding: 0;
display: block;
}
.leftpart .nav-links ul li {
margin-bottom:20px;
}
.leftpart .nav-links ul li a {
background:green;
color:#fff;
padding: 20px;
display: inline-block;
}
.leftpart .nav-links .sub-seciton .nav-links ul li a {
background:red;
color:#fff;
padding: 20px;
display: inline-block;
}
<div class="leftpart">
<div class="nav-links">
<h1> Primary Links </h1>
<ul>
<li>
Profile
</li>
<li>
Friends
</li>
<li>
Milestones
</li>
<li>
Groups
</li>
</ul>
<div class="sub-seciton">
<div class="nav-links">
<ul>
<li>
Edit
</li>
<li>
Save
</li>
</ul>
</div>
</div>
</div>
<div class="nav-links">
<h1> Secondary Links </h1>
<ul>
<li>
Privacy
</li>
<li>
Settings
</li>
</ul>
</div>
</div>
.leftpart {
width: 100%;
display: block;
margin: 20px;
}
.leftpart .sub-seciton>.nav-links ul li:nth-child(1) a,
.leftpart .sub-seciton>.nav-links ul li:nth-child(2) a{
background:red;
}
.leftpart .nav-links ul {
list-style: none;
margin: 0;
padding: 0;
display: block;
}
.leftpart .nav-links ul li {
margin-bottom:20px;
}
.leftpart .nav-links ul li a {
background:green;
color:#fff;
padding: 20px;
display: inline-block;
}
<div class="leftpart">
<div class="nav-links">
<h1> Primary Links </h1>
<ul>
<li>
Profile
</li>
<li>
Friends
</li>
<li>
Milestones
</li>
<li>
Groups
</li>
</ul>
<div class="sub-seciton">
<div class="nav-links">
<ul>
<li>
Edit
</li>
<li>
Save
</li>
</ul>
</div>
</div>
</div>
<div class="nav-links">
<h1> Secondary Links </h1>
<ul>
<li>
Privacy
</li>
<li>
Settings
</li>
</ul>
</div>
</div>
I would like to place an image to the left of the text and keep it like that depending on the resolution of the window.
Here's what it looks like without an image: http://prntscr.com/fmky4f
This is what I would like it to look like after placing it. https://prnt.sc/fmkk0a
This is my code:
.xd {
font-size: 20px;
list-style: none;
margin: 0;
padding: 0;
text-align: center;
}
.xd li {
display: inline;
}
.xd a {
display: inline-block;
padding: 5px;
color: #080808;
}
.logo {
width: 10%;
height: auto;
float: left;
}
<div class="container">
<div id="container-fluid">
<ul class="xd">
<li>
Home
</li>
<li>
About Us
</li>
<li>
News
</li>
<li>
Gallery
</li>
<li>
Map
</li>
<li>
Contact Us
</li>
</ul>
</div>
Now I tried just simply putting in the image with the .logo class properties, but they don't seem to do the job as intended.
If you're going to use floats and widths for the logo, use that for the menu also.
.xd {
float: left;
width: 90%;
font-size: 20px;
list-style: none;
margin: 0;
padding: 0;
text-align: center;
}
.xd li {
display: inline;
}
.xd a {
display: inline-block;
padding: 5px;
color: #080808;
}
.logo {
width: 10%;
height: auto;
float: left;
}
<div class="container">
<div id="container-fluid">
<img class="logo" src="http://placehold.it/50x50">
<ul class="xd">
<li>
Home
</li>
<li>
About Us
</li>
<li>
News
</li>
<li>
Gallery
</li>
<li>
Map
</li>
<li>
Contact Us
</li>
</ul>
</div>
You could also use flexbox. Perhaps something like this:
header,
ul {
display: flex;
}
header img {
display: block;
max-width: 100%;
height: auto;
}
header ul {
flex-grow: 1;
justify-content: center;
margin: 0;
padding: 0;
list-style: none;
font-size: 20px;
}
header a {
padding: 5px;
color: #080808;
}
<header>
<div>
<img src="http://placehold.it/50x50">
</div>
<ul>
<li>
Home
</li>
<li>
About Us
</li>
<li>
News
</li>
<li>
Gallery
</li>
<li>
Map
</li>
<li>
Contact Us
</li>
</ul>
</header>
You can use position: absolute; and the default settings on the image as shown below. (You can use top and left settings to move it away from the border/corner if you want)
This keeps the menu items centered in relation to the container.
.xd {
font-size: 20px;
list-style: none;
margin: 0;
padding: 0;
text-align: center;
}
.xd li {
display: inline;
}
.xd a {
display: inline-block;
padding: 5px;
color: #080808;
}
.logo {
width: 10%;
height: auto;
float: left;
}
#image1 {
position: absolute;
}
<div class="container">
<img src="http://placehold.it/80x50/fb4" id="image1">
<div id="container-fluid">
<ul class="xd">
<li>
Home
</li>
<li>
About Us
</li>
<li>
News
</li>
<li>
Gallery
</li>
<li>
Map
</li>
<li>
Contact Us
</li>
</ul>
</div>
I am trying to figure out why my background grows bigger when switching from one page to the next. They style is perfect one the home page. But when I switch to the portfolio or the contact page seems to me it adds padding to it.
header {
background-color: white;
display: inline-block;
top: 0;
width: 100%;
background-attachment: fixed;
}
header h1 {
float: left;
display: block;
}
header ul {
float: right;
display: block;
list-style: none;
}
header li {
display: inline-block;
padding: 10px;
}
<header>
<!--site title-->
<h1>
Clayton J. Batchelor
</h1>
<!--Navigation section-->
<ul>
<li>
<a href="index.html">
Home
</a>
</li>
<li>
<a href="portfolio.html">
Portfolio
</a>
</li>
<li>
<a href="contact.html">
Contact
</a>
</li>
</ul>
</header>
I've almost got my dropdown menu working, but I can't get the dropdown content to appear underneath the head when it's clicked. It's moved off to the side. What's causing that? Is it improperly written position?
Fiddle: https://jsfiddle.net/kiddigit/8sxj3eeg/
* {
font-family: garamond;
line-height: 1.9em;
}
.dropdownwrapper {
padding-top: 2px;
}
.dropbtn {
color: black;
padding: 13px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown-content {
/* display: none;*/
position: absolute;
}
.dropdown-content a {
color: white;
padding: 0 27.5px ;
text-decoration: none;
display: block;
background-color: #3f3f3f;
}
.dropdown-content a:hover {
color: #a9a9a9;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: black;
color: white;
}
header {
border-bottom: 5px solid;
margin-bottom: 10px;
overflow: hidden;
}
header ul {
float: right;
list-style-type: none;
margin-top: 22px;
padding:0;
width: 50%;
}
header li {
float: right;
}
header li a {
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
header li a:hover {
background-color: #111;
color: white;
}
header h1 {
float: left;
text-align: left;
line-height: 0;
font-size: 2em;
}
<header>
<h1>Father Bart Gage</h1>
<ul>
<li><a id="about" href="#">ABOUT</a></li>
<li>CONTACT</li>
<div class="dropdownwrapper">
<div class="dropdown">
<li><div class="dropbtn" onClick=”return true”>SCRIPTURE</div></li>
<div class="dropdown-content">
<a id="mark" href="#">Mark</a>
<a id="matthew" href="#">Matthew</a>
<a id="luke" href="#">Luke</a>
<a id="john" href="#">John</a>
</div>
</div>
</div>
</ul>
</header>
You have to move the dropdown-content element into the list item:
<div class="dropdown">
<li>
<div class="dropbtn" onClick=”return true”>SCRIPTURE</div>
<div class="dropdown-content">
<a id="mark" href="#">Mark</a>
<a id="matthew" href="#">Matthew</a>
<a id="luke" href="#">Luke</a>
<a id="john" href="#">John</a>
</div>
</li>
</div>
There's a couple things going on that probably need some attention.
First, a <div> element is not technically "legal" as a direct child of a ul element. The only direct child of a ul should be a li. To solve this, I've moved your dropdown divs inside the li.
Second, you may be suffering a bit of "div-itis". You probably (definitely?) don't need so many div elements to accomplish what you want. I've proposed alternate markup below your markup below.
Third, it's all about position: when you set position: absolute, the position (top, right, bottom, left) are relative to the nearest parent with position: relative. Therefore, you probably want to be sure your li elements have position: relative.
Your original markup, with the divs enclosed in the li
<header>
<h1>Father Bart Gage</h1>
<ul>
<li><a id="about" href="#">ABOUT</a></li>
<li>CONTACT</li>
<li>
<div class="dropdownwrapper">
<div class="dropdown">
<div class="dropbtn" onClick=”return true”>SCRIPTURE</div>
<div class="dropdown-content">
<a id="mark" href="#">Mark</a>
<a id="matthew" href="#">Matthew</a>
<a id="luke" href="#">Luke</a>
<a id="john" href="#">John</a>
</div>
</div>
</div>
</li>
</ul>
</header>
Alternate proposed markup
(note that this also requires altered styles - see the fiddle for those!)
<header>
<h1>Father Bart Gage</h1>
<ul>
<li><a id="about" href="#">ABOUT</a></li>
<li>CONTACT
<!-- nested ul for the dropdown, rather than divs -->
<li>
<div class="dropbtn" onClick=”return true”>SCRIPTURE</div>
<ul class="dropdown dropdown-content">
<li><a id="mark" href="#">Mark</a></li>
<li><a id="matthew" href="#">Matthew</a></li>
<li><a id="luke" href="#">Luke</a></li>
<li><a id="john" href="#">John</a></li>
</ul>
</li>
</ul>
</header>
Working Fiddle using the alternate proposed markup.
I wonder if it is possible to make the following work:
#keepwidth {
width: 1000px;
}
.row.top-menu > ul {
padding: 0;
}
.row.top-menu > ul > li {
display: inline-block;
}
.row.top-menu > ul > li > a {
display: inline-block;
background-color: #009ec3;
color: #fff;
min-width: 123px;
text-align: center;
text-transform: uppercase;
border: 2px #009ec3 solid;
border-radius: 3px;
margin: 0;
}
.row.top-menu > ul > li > a:hover {
background-color: #90d2ec;
color: #666;
text-decoration: none;
}
.row.top-menu > ul > li.dropdown:hover ul {
display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div id="keepwidth">
<div class="row top-menu">
<ul>
<li>
asdas
</li>
<li class="dropdown">
Hover here <span class="caret"></span>
<ul class="dropdown-menu">
<li>
temp
</li>
</ul>
</li>
<li>
sadsad
</li>
<li>
asdasda
</li>
<li>
sadasdasdsa
</li>
<li>
sadasdsadsa
</li>
<li>
sadasdsasdasdsa
</li>
</ul>
</div>
</div>
I do not wish to make use of JavaScript and I do not wish to move the dropdown menu element around (e.g. margin-top: 0 or margin: 0) and I want to make the dropdown appear when hovering both the dropdown menu itself and the button refering to it.
Since you're using Bootstrap, you'll need to follow their CSS conventions as explained here in order to get predictable behavior:
https://jsfiddle.net/Bendrick92/mgny3g87/
#keepwidth {
width: 1000px;
}
.navbar-nav > li > a {
display: inline-block;
background-color: #009ec3;
color: #fff;
min-width: 123px;
text-align: center;
text-transform: uppercase;
border: 2px #009ec3 solid;
border-radius: 3px;
margin: 0;
}
.navbar-nav > li > a:hover {
background-color: #90d2ec;
color: #666;
text-decoration: none;
}
.dropdown:hover .dropdown-menu {
display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div id="keepwidth">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
asdas
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" role="button">
Hover here <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
temp
</li>
</ul>
</li>
<li>
sadsad
</li>
<li>
asdasda
</li>
<li>
sadasdasdsa
</li>
<li>
sadasdsadsa
</li>
<li>
sadasdsasdasdsa
</li>
</ul>
</div>
</div>