How to style correctly in HTML - html

I started very recently to study/practicing with HTML, typescript, CSS and angular5, and I'm developing a test app to try what I've learned so far. But I am a little bit confused on how I can solve this problem:
Basically I need to set the color of the text inside of a element (the color of the dropdown button text must be different from the one the menu text has).
<ul class="nav navbar-nav ">
<li class="dropdown" appDropdown>
drop1<span class="caret"></span>
<ul class="dropdown-menu">
<li>menu1</li>
<li>menu2</li>
</ul>
</li>
</ul>
I want "drop1" text in white, while the "menu" element text can be of the default color.
Now if I put in the CSS this:
ul li a {
color: white;
}
Each text is colored in white. Now I know I can set directly the style property in HTML tag to override the style from CSS, but since I have several dropdown I would like to set everything in the CSS. How can I do it?

Try to use > css selector using class like
ul.navbar-nav>li>a
It will selects all <a> elements where the parent is a .navbar-nav class
Stack Snippet
ul.navbar-nav>li>a {
color: white;
background: red;
}
<ul class="nav navbar-nav">
<li class="dropdown" appDropdown>
<a href="#" class="dropdown-toggle" role="button">
drop1
<span class="caret">
</span>
</a>
<ul class="dropdown-menu">
<li>menu1</li>
<li>menu2</li>
</ul>
</li>
</ul>
Another solution is to use :not pseudo class
Stack Snippet
ul:not(.dropdown-menu)>li>a {
color: white;
background: red;
}
<ul class="nav navbar-nav">
<li class="dropdown" appDropdown>
<a href="#" class="dropdown-toggle" role="button">
drop1
<span class="caret">
</span>
</a>
<ul class="dropdown-menu">
<li>menu1</li>
<li>menu2</li>
</ul>
</li>
</ul>
Referece Link
child-selector
:not() selector

You can try this simple idea:
<ul class="nav navbar-nav ">
<li class="dropdown" appDropdown>
<a href="#" class="dropdown-toggle white-text" role="button" >
drop1
<span class="caret">
</span>
</a>
<ul class="dropdown-menu">
<li>menu1</li>
<li>menu2</li>
</ul>
</li>
</ul>
With this CSS
.white-text {
color: white!important;
}
That means you can utilise this class throughout your site if you need the text to be white
edit
If you're worried about using !important inside the class you can just remove that, but just ensure that the class is the last entry in the class stack, for example:
<a href="#" class="dropdown-toggle white-text" role="button" >
rather than
<a href="#" class="white-text dropdown-toggle" role="button" >

Target the class of your element.
.dropdown-toggle {
color: black; // all your toggle menu (main menu) will have a black color;
}
.dropdown-menu a {
color: white; // all your dropdown menu (sub menu) will have a white color;
}
Don't use !important;

You myst either use a CSS file or use the style="" element inside your HTML tag.
i.e.:
First way: <button style="color: red; background-color: green;">Log in</button>
Second way:
HTML file:
<button class="mybtn">Log in</button>
CSS file:
.mybtn {
color: red;
background-color: green;
}
You work like this with all tags and all elements you that want to style.

Related

How to disable multi level bootstrap dropdown?

I want user to be able to select everything within Morphological Transformation (Erosion, Dilation, Opening, Closing), but not 'Morphological Transformation' itself. Thank you for every answer!
HTML Code:
<div class="container">
<div class="row">
<hr>
<div class="dropdown">
<a id="dLabel" role="button" data-toggle="dropdown" class="btn btn-primary" data-target="#" href="/page.html">
Select Pre-Processing Method <span class="caret"></span>
</a>
<ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
<li>Normalisation</li>
<li>Canny Edge Detection</li>
<li>Smoothing</li>
<li></li>
<li class="divider"></li>
...
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Morphological Transformation</a>
<ul class="dropdown-menu">
<li><a>Erosion</a></li>
<li><a>Dilation</a></li>
<li><a>Opening</a></li>
<li><a>Closing</a></li>
</ul>
</li>
...
</ul>
</li>
</ul>
</div>
</div>
You can disable anchor events and keep hover effects by using this:
.disabled-link:hover{
background: red;
}
.disabled-link:active{
pointer-events: none;
}
Test
It is usable for all modern browsers:
click!

How do I keep the hover effect on the navbar when hovering through dropdown lists?

I have a hover effect on my navbar and I just added a dropdown to it.
It loses the hover effect when I hover into the lists. How do I keep the hover effect?
My current css:
.navbar-list:hover {color:red;}
Html:
<li class="dropdown">
<a href="#" class="navbar-list dropdown-toggle" data-toggle="dropdown">
About Us
</a>
<ul class="dropdown-menu">
<li>Company Profile</li>
<li>Board of Director</li>
</ul>
</li>
How do I add the css to make it have the hover effect when I hover through the list?
According your code, you need to change your css selector like this.
/*
.navbar-list:hover {color:red;}
*/
.dropdown:hover {color:red;}
<li class="dropdown">
<a href="#" class="navbar-list dropdown-toggle" data-toggle="dropdown">
About Us
<!--
Or you can put your dropdown-menu here
<ul class="dropdown-menu">
<li>Company Profile</li>
<li>Board of Director</li>
</ul>
-->
</a>
<ul class="dropdown-menu">
<li>Company Profile</li>
<li>Board of Director</li>
</ul>
</li>
the css selector .navbar-list:hover {color:red;} indicate to
<a href="#" class="navbar-list dropdown-toggle" data-toggle="dropdown">About Us
</a> which not contains the dropdown-menu.
so you can change your css selector or html structure to fit your request.

Stacked tabs in dropdown menu in navbar

What i am creating is similar to this. I found this while researching on stackexchange.
However, i want the dropdown to open on mouseover. I am able to create a bootstrap navbar with mouseover dropdowns, but unable to add mouseover action to the example given above. Any ideas?
<div class="dropdown">
<a id="dLabel" role="button" data-toggle="dropdown" data-target="#" href="/page.html">
Dropdown <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<ul class="nav nav-tabs">
<li class="active"><a data-target="#home" data-toggle="tab">Home</a> </li>
<li><a data-target="#profile" data-toggle="tab">Profile</a></li>
<li><a data-target="#messages" data-toggle="tab">Messages</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="home">HOME asdfasdfsda</div>
<div class="tab-pane" id="profile">PROFILE asdfafas</div>
<div class="tab-pane" id="messages">MESSAGES asdfdas</div>
</div>
</ul>
</div>
http://jsfiddle.net/pv2Lc/7/
How about this?
http://jsfiddle.net/70ytg4yf/
HTML unchanged
No JS
CSS:
.dropdown:hover {
/* so that no mouseout is triggered when moving to the menu */
padding-bottom: 5px;
}
.dropdown-menu {
/* move up since default is lower because of padding */
margin-top: -5px;
}
.dropdown:hover .dropdown-menu {
display: block;
}

Bootstrap button text color

I am using the Bootstrap 3 custom buttons but can't for some reason change the brand text color nor the dropdown triangles. I've tried a couple of things, but still no luck...
<div class="container">
<div class="row" style="margin-top: -30px;">
<ul class="nav nav-tabs" role="tablist">
<li class="dropdown" style="margin-right: 70px; margin-left: 60px;" >
<a class="btn btn-inverse :active" data-toggle="dropdown" href="#">
Wristbands <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
...
</ul>
</li>
<li class="dropdown" style="margin-right: 70px;">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Hawaii <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
...
</ul>
</li>
In your example, I don't see any text in the navbar-brand div. Is that what you're talking about?
Anyhow, to answer your question, if you have text in navbar-brand, you'd use something like:
.navbar-default .navbar-brand {
color: blue !important;
}
And for the dropdown arrows, something like:
span.caret {
color: red;
}

How to float div up?

I have a menu and a submenu in different divs. There is a space between them. How can I make them look like a one whole menu? I used bootstrap navbar for main menu and simple nav for submenu. I'm very newbie in css. this is what I have:
<div class="navbar navbar-inverse">
<div class="navbar-inner">
<a class="brand" href="#">Website Logo</a>
<ul class="nav">
<li class="active">DashBoard</li>
<li>Docs</li>
<li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#">Account<b class="caret"></b></a>
<ul class="dropdown-menu" style="width: 250px;">
<li>Dashboard</li>
<li>LogOut</li>
</ul>
</li>
</ul>
</div>
</div>
<div>
<ul class="nav nav-pills">
<li class="active">
Stats
</li>
<li>Api Calls</li>
<li>Settings</li>
</ul>
</div>
jsfiddle
I just want to remove the space between them.
And one more little question:
how can I get rid of a little caret between button and it's dropdown? (white triangle between Account nav item and it's dropdown)
Your first question can be answered by removing the default margin-bottom for the class navbar:
.navbar {
margin-bottom:0
}
Now, for your second question. There is a triangle created using borders on your dropdown-menu. You can disable this with this css:
.navbar .nav > li > .dropdown-menu:after {
border:none;
}
Add the following CSS to remove the margins:
.navbar{
margin:0px;
}
JS Fiddle: http://jsfiddle.net/eszf7/3/