Adjust height of button according to navbar html - html

I have a navbar and a button defined in HTML like this :
<div class="topnav">
<a class="active" href="#home">Hooligans</a>
<button class="button"><p style="font-family:courier;">drop dead</p></button>
</div>
The CSS for the above goes like this :
.topnav {
background-color: #F9FAFA;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
color: #BA55D3;
text-align: center;
padding: 8px 5px;
text-decoration: none;
font-size: 3vw;
}
.button {
background-color: #F9FAFA;
border: 2px solid #BA55D3;
border-radius: 5%;
color: #BA55D3;
text-align: center;
margin-left: 70%;
display: inline-block;
}
Right now, the best I can do is the button to fit exactly inside navbar. I want it to be smaller than the navbar like the Signup button in the stackoverflow navbar.
When I set height of the button the text inside the button goes out of the border and when I try padding the button goes bigger.
Any help ?

Remove the <p> tag inside the button, that is what's causing the unexpected margins. Also, I added display: flex to center align the items in the nav:
.topnav {
background-color:#F9FAFA ;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
overflow: hidden;
display: flex;
align-items: center;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
color: #BA55D3 ;
text-align: center;
padding: 8px 5px;
text-decoration: none;
font-size: 3vw;
}
.button{
background-color: #F9FAFA ;
border:2px solid #BA55D3;
border-radius: 5%;
color:#BA55D3;
text-align: center;
margin-left: 70%;
display: inline-block;
font-family: courier;
font-size: 1vw;
}
<div class="topnav">
<a class="active" href="#home">Hooligans</a>
<button class="button" >drop dead</button>
</div>

Related

Navbar always pushes from the right when resizing width of window

I'm sorta new to web development. My navbar seems to have this problem where anytime I resize the width of the window it edges off to the right. Example: https://imgur.com/OdVdwBR
I'm not sure if its the method I used to make the nav or something internal that's only happening to my system, but anyway;
How would I fix this?.
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body{
font-family: sans-serif;
}
/*Navigation Bar*/
nav{
display: flex;
justify-content: space-around;
align-items: center;
font-family:'Nunito', sans-serif;
background-color: #49e949;
box-shadow: 0px 0px 10px 0px #535353dc;
white-space: nowrap;
}
.nav-links{
list-style: none;
display: flex;
justify-content: space-around;
width: 50%;
font-weight: 700;
font-size: 18px;
}
.nav-links a{
text-decoration: none;
color: #ffffff;
padding: 1rem 5rem;
display: block;
transition: 0.2s;
}
.nav-links a:hover{
color: #49e949;
background-color: #ddfddd;
}
.nav-links .active-page{
color: #49e949;
background-color: #ddfddd;
}
/*Content*/
.container{
text-align: center;
position: absolute;
top: 40%;
margin: 0;
left: 44%;
}
.count-container{
display: flex;
align-items: center;
}
.count-container div{
cursor: pointer;
}
.count-number{
font-size: 50px;
margin: 0px 40px;
}
/*Arrows*/
.add-arrow{
border-top: 25px solid transparent;
border-left: 50px solid #4667fa;
border-bottom: 25px solid transparent;
}
.subtract-arrow{
border-top: 25px solid transparent;
border-right: 50px solid #ff3333;
border-bottom: 25px solid transparent;
}
/*Arrows End*/
.reset{
text-transform: uppercase;
border: 2px solid black;
font-weight: 500;
border-radius: 5px;
padding: 5px;
cursor: pointer;
outline: none;
transition: 0.3s;
}
.reset:hover{
background-color: black;
color: white;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght#400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/counter.css" type="text/css">
<title>Counter</title>
</head>
<body>
<nav>
<ul class="nav-links">
<li>Colour Switcher</li>
<li>Counter</li>
<li>Sidebar</li>
<li>Modal</li>
</ul>
</nav>
<div class="container">
<div class="count-container">
<div class="subtract-arrow" id="subtract-arrow"></div>
<h1 class="count-number" id="count-number">0</h1>
<div class="add-arrow" id="add-arrow"></div>
</div>
<button class="reset" id="reset">reset</button>
</div>
<!--Javascript-->
<script src="js/counter.js"></script>
</body>
</html>
Your padding: 1rem 5rem; property inside of .nav-links a is pushing your links outside of their container when the size of the navbar decreases in width. W3C defines a rem unit as:
Equal to the computed value of font-size on the root element.
In most browsers this computed value is equal to 16px so 5rem is actually pretty large. This means that there is 160px of combined padding between each of your links. So you could go with 1 or 2 rem instead and that will give you a lot more leeway as far as when elements will start getting pushed out of their container relative to screen size.
This happens because the width of your links are at a set width due to padding on each link which is set here in your CSS:
.nav-links a {
text-decoration: none;
color: #ffffff;
padding: 1rem 5rem;
display: block;
transition: 0.2s;
}
The width of your page isn't going to change the padding of those links, unless you tell it to. You can use media-queries to change the padding to be smaller when the page reaches a certain width like this:
#media (max-width: 900px) {
.nav-links a {
padding: 1rem 2rem;
}
}
Be sure to put this media query at the bottom of your CSS stylesheet.
You can read more here: https://developer.mozilla.org/en-US/docs/Web/CSS/#media

how to align multiple <h1> tags

I wanted to make a header with a title in the center "Resources", left another title "HTML" and right another with "CSS" but I can not align them to put them in the right place and then add a border-right and border-left to separate the left and right title from the title to the center.
For the moment I have this:
header {
border: 2px solid white;
border-radius: 20px;
background-color: rgba(0, 0, 0, 0.2);
color: white;
}
h1 {
display: inline-block;
font-size: 30px;
font-family: Arial, sans-serif;
}
h1.html {
padding-left: 2%;
}
h1.res {}
h1.css {
padding-right: 2%;
}
<header>
<h1 class="html">HTML</h1>
<h1 class="res">Ressources</h1>
<h1 class="css">CSS</h1>
</header>
Because of the display: inline-block; it works better but I do not know how to do it.
It would be simpler to replace the <h1> tags with <span> elements because they are inline by default. The left and right separation can be accomplished several ways. See example below.
.header {
text-align: center;
border-radius: 20px;
background-color: rgba(0,0,0,0.2);
color:white;
font-family: Arial, Helvetica, sans-serif;
font-weight: bolder;
font-size: 24px;
}
.header span:nth-child(1) {
float: left;
width: 33%;
border-right: 2px solid white;
}
.header span:nth-child(3) {
float: right;
width: 33%;
border-left: 2px solid white;
}
<div class='header'>
<span>HTML</span>
<span>RESOURCES</span>
<span>CSS</span>
</div>
You can use a flex layout to position the headings. Add this to your existing header ruleset:
header {
display: flex;
justify-content: space-between;
}

How to align a dropdown menu in CSS

I'm having some trouble aligning my dropdown menu in my angular app.
Please see the screenshot attached. The menu extends too far right of the screen. I need it to align to the "top right" of the ellipses instead of the "top left" as it is currently. The menu is currently functioning in a table.
Any assistance in getting the menu to shift to the left would be greatly appreciated.
Here is the HTML/CSS:
<td class="dropup">
<div class="dropup">
<button style="background-color: white;" class="dropbtn">
<img class="icon" src="assets/ellipsis.png">
</button>
<div class="dropup-content">
Admin Functionality
Download Project Snapshot
<a [routerLink]="['/project/'+j._id+'/project-activity']">View Project Activity</a>
Archive Project
<a *ngIf="j.creatorid != user._id" (click)="onLeaveProjectClick(j._id, j.projectname, n)">Leave Project</a>
</div>
</div>
</td>
.dropbtn {
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropup {
position: relative;
display: inline-block;
float:right;
}
.dropup-content {
display: none;
position: absolute;
transform-origin: 60% 40%;
top: 20px;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 10px;
}
.dropup-content :hover {
border-radius: 10px;
}
.dropup-content a {
color: black;
padding: 8px 16px;
text-decoration: none;
display: block;
}
.dropup-content a:hover {
background-color: #ddd;
color: #00aca8 !important;
}
.dropup:hover .dropup-content {
display: block;
border-radius: 10px;
}
As you set .dropup-content to absolute, it will be left aligned relative to .dropup as .dropup-content is within .dropup. But as your class is already absolute, simply add:
right: 0;
left: auto; // Unsure if you really need this though
to .dropup-content. This will take care that the class is right aligned relative to .dropup.
add to class .dropup-content this:
right:0;
https://jsfiddle.net/b1stpfr4/2/

Button with a bigger text centering issue

I´m trying to do some buttons with image and text, and I already did this work.
But now I´m studying a diferente hypothesis, If I have a text bigger I´m trying to center the text in the button but I´m not having sucess put this right. I´m not having succeess putting my very big is not good align-center just below the 1st text.
Have you ever had a case like this? How we can solve this?
I have this Html for two buttons:
<button class='btn'>
<img class="big_btn" src="icon1.png" width="40" height="40"/>
Big button so big <span> very big is not good</span>
</button>
<button class='btn'>
<img src="icon1.png" width="40" height="40">
2button big
</button>
And I have this css file:
.btn {
position: relative;
width: 180px;
height: 60px;
margin-top:7%;
padding: 0 10px 0 10px;
line-height: 37px;
text-align: left;
text-indent: 10px;
font-family: 'bariol_regularregular';
font-size: 15px;
color: #333;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
background: #f1f1f1; /* button background */
border: 0;
border-bottom: 2px solid #999; /* newsletter button shadow */
border-radius: 14px;
cursor: pointer;
-webkit-box-shadow: inset 0 -2px #999;
box-shadow: inset 0 -2px #999;
}
.btn:active {
top: 1px;
outline: none;
-webkit-box-shadow: none;
box-shadow: none;
}
.btn img { float: left;}
.btn .big { margin-top:10px;}
.btn:hover { background-color: #f7f7f7;}
Here's the Fiddle: http://jsfiddle.net/3F9pu/
My image updated:
Your problem is your line-height attribute. If you set that to be 37px, each new line of text will be separated by 37px. Remove `line-height:37px and the text will wrap around the image.
line-height: 37px
I also removed your text-indent and replaced it with a margin on your floated image to make the text all align properly.
.btn img{
float:left;
margin-right: 10px;
}
text-indent: 10px
JSFiddle
Use a CSS background image.
Have a fiddle - Fiddle Link!
HTML
<button class='btn'>Big button so big very big is not good</button>
<button class='btn'>2button big</button>
CSS
.btn {
background: url("http://lorempixel.com/output/cats-q-c-40-40-3.jpg") #CCC 10px no-repeat;
border: none;
padding: 10px 10px 10px 60px;
width: 200px;
text-align: left;
vertical-align: top;
min-height: 60px;
cursor: pointer;
}
.btn:hover {
background-color: #F00;
}

Child elements :hover on Internet Explorer not working (HTML/CSS)

I built the following website basically from scratch, and it works perfectly on most browsers (Chrome, Firefox, Safari, Edge), but unsurprisingly not on IE (tested on 9,10,11): Alliance Française du Manitoba
The problem is with the dropdown menus. When hovering over one of the menu headers (<div class="headerMenuItem">), a mega-menu (<div class="headerMenuDropdown">) should appear. Currently, when hovering, the headerMenuItems are highlighting, as expected, but the child headerMenuDropdown isn't appearing.
/***Header Menu***/
#headerMenu { /*Menu Wrapper*/
float: left;
margin: 12px auto 0px;
padding: 0px;
}
.headerMenuItem { /* Individual menu item */
display: block;
float: left;
overflow: hidden;
border-radius: 5px 5px 0px 0px;
margin-top: 6px;
padding-bottom: 10px;
}
.headerMenuItem:hover {
background-color: #d4d9db;
text-decoration: none;
}
.headerMenuItem>a {
padding: 8px 12px 0px;
text-align: center;
border-radius: 5px 5px 0px 0px;
font-weight: bold;
color: #444;
}
.headerMenuItem a:hover { /* override default link behaviour */
text-decoration: none;
color: #444;
}
/*Menu expand*/
.headerMenuDropdown { /* mega-menu wrapper */
float: left;
display: none;
position: fixed;
background-color: white;
width: 100%;
left: 0;
top: 100%;
border-top: 1px solid #da002e;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 105;
text-align: center;
}
.headerMenuItem:hover .headerMenuDropdown { /*Display dropdown*/
display: block;
animation: headerDropdownAppear;
animation-duration: 0.4s;
}
#keyframes headerDropdownAppear {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Create up to 6 equal columns that floats next to each other */
.row {
width: 1200px;
display: block;
margin-left: auto;
margin-right: auto;
}
.column {
float: left;
width: 15.53848%;
padding: 10px 10px 10px 0px;
}
.column span,
.column a {
float: none;
text-decoration: none;
display: block;
text-align: left;
padding: 1px;
}
.column>span {
font-weight: bold;
}
.column>span>span {
padding-left: 15px;
text-indent: -10px;
font-weight: lighter;
font-size: 0.8em;
}
.column>span>span>a {
padding-left: 15px;
margin-left: -15px;
padding-bottom: 3px;
line-height: 120%;
}
.column a:hover {
background-color: #d4d9db;
}
<div id="headerBottom">
<nav id="headerMenu">
<div class="headerMenuItem">
Learn French
<div class="headerMenuDropdown">
<div class="row">
<div class="column">
<span>
Column 1
<span>
Link 1
</span>
<span>
Link 2
</span>
...
</span>
</div>
<div class="column">
<span>
Column 2
...
</span>
</div>
...
</div>
</div>
</div>
<div class="headerMenuItem">
Tests & Exams
<div class="headerMenuDropdown">
<div class="row">
...
</div>
</div>
</div>
...
</nav>
...
</div>
I assumed that this had to do with one of two known IE bugs:
:hover inconsistencies
Unsuported > selector
However, both of these should have been phased out as issues by IE 9, but I'm having issues on IE 11! I've got a proper <!DOCTYPE html>, HTML5Shiv, and even crossover.htc, but nothing seems to work.
This leads me to think that the issue is with the CSS selector
.headerMenuItem:hover .headerMenuDropdown
EDIT: However, IE Inspector shows that it's behaivng properly!
Any known fixes?