Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 months ago.
This post was edited and submitted for review 2 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
The links in my nav bar have a :hover effect where the font size is increased and a box shadow is added. Everything works fine except that, when the curser leaves the nav link, the other nav elements do a little hop (they move up a bit for just a moment, then back down to their original position). I'm not sure why this is happening or how to fix it. Any suggestions would be greatly appreciated. Thanks!
Edit: To reproduce this issue, follow the link to the site, use the dropdown field near the top left of the page to select the "Rounded and fun (Google style)" option, hover over the nav links in the top right then move your mouse off of the link. You should see the other links move up briefly, then move back down
I had the same problem on this site with the default stylesheet that had the links styled differently but had a somewhat similar :hover effect (increased font size and add a bottom border). I was able to fix that issue by decreasing the bottom padding a bit on :hover, but I tried that for this issue and it did not work.
I'm using plain HTML 5 and CSS 3.
I've attached the HTML, and all CSS related to the nav/header elements as well as a link to the webpage itself. My page has multiple stylesheets that the user can switch between using the dropdown field. My issue is related to the "rounded" style
This is my first "full" website that I've made (I'm currently going through a course on Codecademy) and it is also my portfolio site. So any suggestions on general improvements to the site/best practices are also welcome.
Site Link
https://jackf514.github.io/portfolio-site/
nav {
display: inline-block;
width: 50%;
padding-right: 5%;
flex-shrink: 2;
}
nav ul {
display: flex;
list-style: none;
float: right;
}
nav li {
padding: 0.5rem;
transition: font-size 0.1s;
}
nav a {
text-decoration: none;
color: hsla(210, 40%, 45%, 1);
font-size: 1.375rem;
transition: font-size 0.1s, color 0.5s, box-shadow 0.25s;
}
nav li:hover {
border-bottom: 2px solid hsla(210, 40%, 20%, 1);
padding-bottom: 6px;
font-size: 1.425rem;
}
nav li:active {
color: hsla(210, 40%, 35%, 1);
font-size: 1.4rem;
border-bottom-width: 1px;
}
nav a {
margin-left: 10px;
}
nav li {
padding: 8px 12px;
border: 1px solid hsla(210, 40%, 20%, 1) !important;
}
nav a,
nav li {
border-radius: 25px;
}
nav li:hover {
box-shadow: 0px 2px 3px hsla(210, 0%, 20%, 1);
font-size: 1.475rem;
padding-bottom: 6px;
}
/*nav a:hover li {
padding: 6px 12px 5px 12px;
border-width: 0px;
}
nav a:hover {
box-shadow: 0px 3px 3px hsla(210, 0%, 20%, 1);
font-size: 1.475rem;
}*/
<header>
<div id='title'>
<a href="#top">
<h1>Jack Ferguson</h1>
</a>
</div>
<nav>
<ul>
<a href="#about">
<li>About Me</li>
</a>
<a href="#projects">
<li>My Projects</li>
</a>
<a href="#contact">
<li>Contact Me</li>
</a>
</ul>
</nav>
</header>
There are multiple ways to fix this.
The reason for horizontal expand on hover is because of font size increase. When your font size changes, size of your ul container also changes. Hence , causing weird effect on hover.
I would recommend using scale for such transition instead of font size. It makes more sense and is easier to debug.
As of setting border , you can also use text-underline.
nav li:hover {
/* border-bottom: 2px solid hsla(210, 40%, 20%, 1); */
/* padding-bottom: 6px; */
/* font-size: 1.425rem; */
scale: 1.1;
text-decoration: underline;
text-underline-offset: 8px;
}
On your site, you could replace flex on your UL with grid, like the following:
display: grid;
grid-template-columns: 127px 144px 139px;
That being said, I wouldn't recommend it, because then you'd have to change the px values every time you update your menu. It is an option if you don't mind doing that though.
The reason why the shifting is occuring is because when the font size increases, it also increases the size of the menu. So the spacings need to readjust to accomodate. With flex, the sizes are done automatically based on the content so it needs to adjust. With the grid approach, you're specifying how big you want each menu item to be, so no shifting occurs.
IMO you should just do an underline and forgo the font increase altogether.
Also, for proper syntax make sure your list structure is as follows (as of now you have the a and li mixed up).
<ul>
<li>
<a></a>
</li>
</ul>
I've downloaded the CSS and HTML files directly from your website you provided above.
What's important to understand is that because of the flex display type, when you perform the transition the elements themselves change size to accommodate the transitions
A helpful tool I like to use to debug when I have size issues via margin, border, padding, or element sizing on my pages is to apply a random color to the specified elements background via background-color. These will let you see in real time how your hover is changing the actual size of the element you are looking at and also how all your elements interact with each other on the page. (this affect can also be seen to a lesser extent via the developer tools in your browser)
Using the background trick we can see that on Hover your ul element is changing its height and because of this causing all the other elements in it to move as well such that they are centered.
ul{
height:50px;
}
adding this to your style sheet allows the enough head room for the div when it grows to not resize it all and removes the vertical hoping around of your list items on hover. They will still move sideways due to the above mentioned resizing. This could be removed if space is added between the li
Understanding how each layer is built on top of each other is super important for how your site will look and understanding how things are affected. If your like me putting in the debug colors on your elements backgrounds can be a super useful tool to understanding how they are arranged on your page
Related
I'm trying to style my navbar and work on its aesthetics but I think I'm missing a trick. The darken which happens on the hover is too big for my liking, but the only size change I can do is an overall padding which doesn't allow fine tuning.
I've spent the last 2 hours looking for a solution and I'm stumped. I bet it's something simple and I'm just not seeing it.
#navbar {
background-color: #333;
position: fixed;
top: 0;
width: 100%;
height: 6%;
transition: top 0.3s;
z-index: 2;
}
#navbar a {
float: left;
display: block;
color: white;
margin: 10px;
padding: 10px;
text-align: center;
text-decoration: none;
border-radius: 30px;
}
#navbar a:hover {
background-color: #ddd;
color: black;
height: 6%;
border: 1px inset #000000;
}
<div id="navbar">
<div class=buttonContainer>
<div class="homeBorder">
Home </div>
Skills
Projects
About
Contact
</div>
</div>
Right now, your code does not show any "darkening" but I hope I still understood your question correctly: You want the background of the navbar links to be of a certain color on hover but the area is too big, especially in height?
You are right, your issue is caused by the 10px-padding that you have set on your link elements. I would recommend you to reduce the padding to maybe 5px to achieve the height you would like to see on hover (same padding for normal and hover, otherwise the links "jump" on hover). You could then wrap all links in an additional div to make universal changes or you could simply work with margins instead. I would also recommend not setting a specific height on the navbar but letting the elements inside determine its height by using padding and margin.
What always helps me when dealing with spacing in CSS, is adding differently colored backgrounds to ALL of the elements involved as to understand their behavior and to test my code.
In case there is a specific reason why you cannot reduce the padding, then please edit your question and make your requirements clearer.
Btw, there is one fatal error in your code:
<div class=buttonContainer>
should be:
<div class="buttonContainer">
(quotes!!)
...and ideally it should be:
<div class="button-container">
as it's not best practise to use camel case in CSS as opposed to JS or other programming languages.
I am relatively new to HTML/CSS, and am finding a basic bug in a website that I am attempting to create.
I am using an external CSS file to style my website, and I use the following code as a general guideline for my HTML links.
a:link, a:visited{
background-color: #000000;
color: white;
padding: 14px 25px;
text-align: center;
font-size: 18px;
text-decoration: none;
display: inline-block;
}
a:active, a:hover{
background-color: rgb(46, 46, 46);
color: white;
}
After I link my styles.css file to my HTML file (via link), I want to have a standard logo at the top right corner of the screen, which when clicked, will bring the user to the home screen. However, I do not want to set a specific pixel size, rather, I want it to cover a specific percentage of the screen so the website would look natural on a phone and a computer (rather than being too big/small). I have attempted to do so below, and although the image is in the correct proportions I want it to be, I am still getting an issue when I hover over the label, there seems to be a border that lights up around the image (even though I don't want it to). Here is the code that I used to add the logo:
<a href="index.html" style="float:right; padding:0px 0px;">
<img src="images/test.jpg" alt="Testing Logo" style="width:35%; height:20%; border:0;">
</a>
I am pretty sure that adding the percentages to both the width and height is illegal, right? I'm also curious why this seems to work for the height, but not for the width, and if there is something flawed in doing so please let me know. Here is the output that this code will cause to my logo:
In the above image, I am not hovering over the image with my mouse. The logo is taking up more space than I would like and has a border.
The above image shows my logo when I am hovering over it with my mouse. Notice that the border around it changes color, and if you click in this area, then it will redirect it to the homepage (which is what I want it to do, but I want to minimize the clicking area to just the picture of the logo, not the space surrounding it, and I want to get rid of the border surrounding the logo).
there's a property in CSS called as an outline
a:link, a:visited{
background-color: #000000;
color: white;
padding: 14px 25px;
text-align: center;
font-size: 18px;
text-decoration: none;
display: inline-block;
outline: none;
}
this will remove your border which is highlighting when you hover over it
Your issue is not that clear.
It is best to show your live site or place your code on sites like CodePen or JSFiddle, so others can test to check the issue.
By the way, you can also post your code here as well.
You can try this, but please read what follows: :)
a:link, a:visited{
background-color: #000000;
color: white;
padding: 14px 25px;
text-align: center;
font-size: 18px;
text-decoration: none;
display: inline-block;
border: none; /* <-- add this */
}
a:active, a:hover{
background-color: rgb(46, 46, 46);
color: white;
}
From what I see: I suspect the border (and box-shadow ?) to come from a parent node. You can use the inspector of your browser and click on the border to identify the html tag we want and give him the medicine:
{
border: none;
box-shadow: none;
}
I am pretty sure that adding the percentages to both the width and height is illegal, right?
The SWAT won't come at your place, though we tend to avoid that directly in the HTML file.
More, it's better to not put style inside the HTML file itself, as it may override some rules written on your css files. If you don't know about CSS specificity, here is a good read.
Though it's ok on a CSS file. Myself I usually put max-width: 100% to the images, and I change the width and height of it's parent's div as needed.
I do not want to set a specific pixel size, rather, I want it to cover a specific percentage of the screen
This is perfect! Did you know about vw and media queries ?
I have a button , well .. actually a <li> acting as one. I shape it with the padding without giving it any height. For a click effect, I set font increase +1 on active. Now, on Firefox it expands the button, which is not what I want. On Chromium it does it right and keeps the button size constant while increasing the font size. I can fix this with setting the buttons height - no problem. Although it is not ideal.
But I am just wondering what is the correct behaviour? Should the font size expand the button or should it not?
I assumed that with IE out of the way, two compliant browsers should agree on how to render stuff in common scenarios.
Thanks.
UPDATE
I do apologise for not including the CSS. I thought the wording is simple enough. Here is the sample ...
<!DOCTYPE html>
<html>
<head>
<title>Basal</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="base2.css">
</head>
<body>
<nav>
<ul>
<li> Create </li>
<li> Read </li>
<li> Update </li>
<li> Delete </li>
</ul>
</nav>
</body>
</html>
And the CSS ...
html, body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
nav ul {
display: flex;
border: 2px solid #232B2B;
border-radius: 5px;
}
nav ul li {
flex: 1;
display: inline-block;
border-right: 2px solid #232B2B;
text-align: center;
padding: 5px 0;
cursor: pointer;
background: #685642;
font-size: 16px;
}
nav ul li:last-child {
border-right: 0;
}
nav ul li:hover {
background: #74695C;
}
nav ul li:active {
font-size: 18px;
}
In Firefox, It expands the <li> container every time I click it. In Chromium - it does not. In Chromium it just increases the font size keeping the container size constant.
Firefox - 28.0
Chromium - 34.0.1847.116 (260972)
The height of an element generally depends on the height requirements of its content. The details have intentionally been left browser-dependent in CSS specifications. Increasing font size may or may not increase the height requirements; typically, an increase of 1px does not, an increase of 2px does.
For the given code, both Firefox and Chrome (34.0.1847.131, Win 7) increase the height of the li element when it is activated. The difference is that on Chrome, the increased height remains even when the element returns from active state to normal state. This is probably unintentional and might be classified as a bug. (The effect can perhaps be seen better if you add :active { background: red }.)
In general, you should not expect different browsers to assign the same height to an element unless you explicitly set the height.
If you're increasing the font size, it would make sense that when the font gets large enough, the "li" container will also have to increase its size to keep it contained.
I test your question in chrome, and it does the same as it in Firefox.When you set font increase +1 on active, you must set the active button's attribute "padding-top" or "padding-bottom" decrease the same size.
Browser calculate button's height as follows:
height=margin-top+border-top+padding-top+height+padding-bottom+border-bottom+margin-bottom
You can search CSS box model to see more detail.
Question: What's the best way to create a horizontal menu with drop down capabilities that can be dynamically resized? (Or preferably, how can I edit my current menu to behave like that?)
Explanation: I'm using a thin, horizontal drop-down menu as the main navigation on my site. When the browser window is at full width, there are no problems, but when it is resized, the right-most link pushes down to the next line, as it is floated.
Horizontal menus are such a common thing, I know there have to be some common tricks and ways to create them so that they can be dynamically resized. So if trying to fix my current menu is too burdensome, I would be fine just to hear some tips or read some stuff on how to create better horizontal menus.
Here is what I think would be the main problem:
.menu2 li {
position: relative;
float: left;
width: 150px;
z-index: 1000
}
I've tried different combinations of making this inline and making other tweeks, such as making the 150px width into a percentage, but that would create all sorts of alignment issues with the text.
Here is a demo with all of the code now: http://jsfiddle.net/HSVdg/1/
Some notes on the above link:
I am using Tiny Drop Down 2 (http://sandbox.scriptiny.com/tinydropdown2/) for drop-down functionality (in the form of JS and CSS, which are noted in comments), though the drop down is not actually working in the jsfiddle. I'm pretty sure all of the JS is irrelevant to my main question.
Tiny Drop Down uses a lot of CSS, so it's been quite difficult for me to try and make little tweeks.
The buttons are not vertically lined up with the actual bar, but again this is not the main issue since this is not happening on my actual site.
The window size in the jsfiddle doesn't actually accomodate the entire length of buttons, so you immediately see the problem of the buttons moving to the next line.
Try my version, with display table/table-cell:
http://jsfiddle.net/HSVdg/10/
I've basically just replaced floats with display: table on .menu2 and display: table-cell on its children (li's)
This is how i see it
<nav>
<ul>
<li id="youarehere">Home
<li><a>Products</a>
<li><a>Services</a>
<li><a>Contact Us</a>
</ul>
</nav>
ul#navigation {
float: left;
margin: 0;
padding: 0;
width: 100%;
background-color: #039;
}
ul#navigation li { display: inline; }
ul#navigation li a {
text-decoration: none;
padding: .25em 1em;
border-bottom: solid 1px #39f;
border-top: solid 1px #39f;
border-right: solid 1px #39f;
}
a:link, a:visited { color: #fff; }
ul#navigation li a:hover {
background-color: #fff;
color: #000;
}
ul#navigation li#youarehere a { background-color: #09f; }
I read once how to create cross-browser rounded buttons with shadow using images, I lost my bookmarks unfortunately that's why I ask does anybody remember the technique.
There is left side picture i.e
And then very wide body image which ends up with right curved border/shadow like this :
So at the end you end up with one button which can be used with multiple sizes? I was googling this, but it seems noways everyone use css without images.
Does anybody knows how this technique is called or can refer me to the link? or give me code example, I'd appreciate any of those
When using an image for the start and one for end of the button, these technique is called "sliding doors" and there are myriads of search results with any search engine…
For an introduction read the A List Apart article: http://www.alistapart.com/articles/slidingdoors
But as Neurofluxation asked you in the comment above: Why the hell would you do that years after we have multiple other methods of styling a button in CSS? The A List Apart article for example is from 2003 - which is an age in Internet terms.
This technique is a variation of the "Sliding Doors" technique:
http://www.alistapart.com/articles/slidingdoors/
http://css-tricks.com/snippets/css/perfect-css-sprite-sliding-doors-button/
http://azadcreative.com/2009/03/bulletproof-css-sliding-doors/
Basically you use markup like this:
<button><span>Text</span></button>
Then style the span with the edge image to the side, overlapping the main background image of the parent element. Something like this:
button {
background:url(main-image.png) top right no-repeat;
border:0;
padding:0;
width:80px; /* with only 1 "door", you might need to set a width */
/* other resets may be necessary */
}
span {
background:url(left-door.png) left top no-repeat;
}
button, span {
height:37px; /* height of your sprite */
display:block;
}
Demo: http://jsfiddle.net/Kqs3m/
Your results may vary depending on your sprites and the natural width of the content.
Here's the technique which I think you are looking for (using the same images you attached):
HTML:
<a href="#" class="button">
<span>Small</span>
</a>
<a href="#" class="button">
<span>Large button</span>
</a>
CSS:
.button {
background: url('http://i.stack.imgur.com/htUHL.png') no-repeat left top;
padding-left: 9px;
height: 37px;
display: inline-block;
text-decoration: none;
color: #555;
text-shadow: 0 1px 1px #FFF;
font-family: sans-serif;
font-size: 0.8em;
}
.button span {
background: url('http://i.stack.imgur.com/ID6nO.png') no-repeat right top;
display: inline-block;
height: 37px;
padding: 5px 12px 5px 3px;
}
.button:hover span {
color: #333;
}
Link to the demo: http://jsfiddle.net/v284q/
Using CSS properties instead of images can make your applications faster.
In this case you could just use: Border-Radius, Box-Shadow combined with a gradient background.
Here you can find a good Gradient Editor:
http://www.colorzilla.com/gradient-editor/
How to use Border-radius and Box-shadow:
http://www.css3.info/preview/rounded-border/
http://www.css3.info/preview/box-shadow/