I have a problem. I suspect that the problem is a browser-side rendering problem. Maybe even an expectable behaviour, but I have no idea, and that is why I am going to ask you:
I have an <a>-element and I place two other elements (a <span> and a <div>, the <div> has even more children) inside that element.
I upload my HTML-file to my server and can access and download it (e.g. via curl or wget). There is no problem and the file is exactly the same. When I open it in web browsers (I tested Firefox and Chrome) it is still the same, but only when I open it using the "debugging" tab where I can see the original files. The displayed HTML-file (which I can access using the "inspection" tab) is different. The <div>-element got moved out of the <a>-element. Here is the code-snippet:
<div class="navbar">
A link
<a class="dropdown">
<span>A dropdown</span>
<div class="dropdown-content">
Another link
And a third link
</div>
</a>
</div>
As you can guess, it is a snipped from a navbar ;) Maybe you need the CSS (I use SCSS-files) too:
.navbar {
background-color: $navbar-color;
overflow: hidden;
padding-left: 10vw;
padding-right: 10vw;
a {
position: relative;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
color: $navbar-text-color;
}
a.dropdown {
position: static;
display: inline-block;
span::after {
content: '\f0d7';
font-family: FontAwesome;
padding-left: 6px;
}
.dropdown-content {
display: block;
position: absolute;
background-color: $navbar-color;
min-width: 160px;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
a {
float: none;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
color: $navbar-text-color;
}
}
}
}
I know, the design is not perfect and not finished, but I expect I am facing an HTML problem and so I wanted to ask you first.
Do you have any hints, ideas, references, explanations or corrections for me? I would really appreciate it.
Related
When I tried to add a dropdown menu to my navigation bar it sent that child to the right of the navigation bar. I want it to be the 3rd child. How can I fix that? I tried to make it an absolute to keep its place however, it will then place itself over another child. I do not want that.
rightNav {
float: left;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
background: white;
}
.rightNav:hover{
color: #0067ff;
transition-duration: .4s;
}
.bar {
background-color: white;
}
.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
color: black;
padding: 15px;
text-decoration: none;
display: block;
font-size: 17px;
}
.dropdown-content a:hover {
background-color: #ebebeb;
transition: .1s;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="navbar">
<div>
LOGO
<div class="w3-right smallScreen">
HOME
DIRECTOR OF BANDS
<div class="dropdown">
MARCHING BAND
<div class="dropdown-content">
MARCHING BAND
STAFF
MUSIC
</div>
</div>
CONCERT BAND
JAZZ BAND
CLASSES
MEDIA
CONTACT US
</div>
Antonio.
I tried replicating your code to troubleshoot it, but the CSS is poorly pasted, so I won't be able to give you a full picture on it right now.
If I understand correctly, the issue you're facing is that the drop-down content isn't behaving as such, instead just showing up as links in the nav-bar. Correct?
If that is the case, I would refer you to https://www.w3schools.com/howto/howto_js_dropdown.asp as you'd need some JavaScript to make it work. There is some neat code there ready for the use. Also, I would strongly recommend that you use no spaces in any of the class names in your HTML, as it becomes quite impossible to reference them later in your CSS code.
I've been working on making a personal site with a navigation bar. I read w3schools' article and used the code there to make my nav. There are some problems with this, however:
The same code needs to be copied and pasted on each page.
If I decide to add a new page, I have to add the navigation bar to the new page and add the new page's link to the navigation bar on every page.
If I find an error in the nav code, I have to fix it on each individual page.
Here's the code:
html {
color: blue;
font-family: sans-serif;
}
.resource-dropdown {
position: sticky;
display: inline-block;
}
.resource-dropdown-content {
display: none;
position: absolute;
background-color: #b51d1d;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
padding: 12px 16px;
z-index: 1;
}
.resource-dropdown:hover .resource-dropdown-content {
display: block;
}
.resource-dropdown-content:hover {
color: greenyellow;
}
.topnav {
background-color: black;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: white;
color: black;
}
<div class="topnav">
Home
<div class="resource-dropdown">
<span><a>Resources</a></span>
<div class="resource-dropdown-content">
<p>Sites</p>
<p>Books</p>
<p>Videos</p>
<p>Other</p>
</div>
</div>
About
</div>
Is there a way to make a shortcut? (Something like the alias command in the C languages)
There is no shortcut in HTML only. If you avec a local server such as MAMP / XAMP for exemple, and that you're ready to make a bit of PHP, you'll be able to create one file for the menu, and include it in all other files. This way, each time you change the menu in the menu file, it'll change on every pages.
here is the official documentation on php include function : http://php.net/manual/en/function.include.php
here is the documentation of MAMP : https://www.mamp.info/en/#controlcenter
Im having a bizarre problem. On one of the sites im coding, I use css hover commands to attach pull down menus to buttons. As many of you know, on mobile devices, hover commands translate to taps. The problem is that whatever I do, I cannot get iOS safari to register a click, making the entire drop down menu inaccessible on iOS safari ONLY. It works in chrome on iphone, and it works on every desktop browser. Any ideas?
This is my CSS:
/* Reserve Pull Down */
.reserve {
font-size: 30px;
color: white;
position: relative;
display: inline-block;
cursor: pointer;
margin: 30px;
}
.reservetitle{
color: white;
}
.reservedropdown {
display: none;
position: absolute;
background-color: white;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
color: black;
padding: 12px 16px;
text-decoration: none;
}
.reserve:hover .reservedropdown {
display: block;
}
.reserve.active .reservedropdown {
display: block;
}
/* Reserve Pull Down End */
And this is my html....
<div class="reserve">
<a class="reservetitle">Reserve</a>
<div class="reservedropdown">
<a class="dropdowntext" href="reserve/index.html">By Location</a>
<div class="dropdowngap"></div>
<a class="dropdowntext" href="tel:+13014333005">Call Now</a>
</div>
</div>
Any ideas? Im having a very hard time figuring it out. Ive tried ":active", ":focus". and of course, ":hover". Cant get anything to work on iOS safari. Any help would be appreciated.
Cheers!
-Julian
I was able to get it to work by tweaking your HMTL slightly
http://codepen.io/bjornmeansbear/pen/wGdzMg
I simply made sure that the <a class="reservetitle">Reserve</a> had an href="" … Reserve
The browser for sure sees it as a link that you would click/hover on, and everything then works fine.
I have a webpage of vocabulary words, and hovering over the words triggers a popup with the definition. I accomplish this with the "dropdown" and "dropdown" content Divs. However for some reason the content inside the Divs (in this case the vocab words themselves) completely disappear in mobile, although the unordered list bullets do not. This is a pure html/css settup so I'm not sure what the issue is. I've already tested it on multiple browsers and phones and the problem is clearly displaying on mobile, whether it's iOS or Android.
Here is how the HTML looks like for one of the vocab words:
<ul><li style="color:white; float:left; width:50%;" rel="color:white;float:left; width:50%;"><div class="dropdown"><strong><span style="font-size: 16px; color:white;">Character</span></strong><div class="dropdown-content"><span style="color: rgb(0, 0, 0);">The nature of an individual's moral personality, derived from his rooted, chosen moral values which are
consistently applied and expressed by his behavior and actions.</span></div>
Here's the dropdown code from the stylesheet:
.dropdown {
position: absolute;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
width: 300%;
min-width:350px;
max-width:850px;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}
.dropdown:hover .dropdown-content {
display: block;
}
Note I am working off a third party online courses platform for what it's worth. There may be some styling rules hidden that could cause issues, but hopefully whatever is causing this is obvious enough to much more seasoned developers.
.dropdown {
position: absolute;
display:block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
width: 300%;
min-width:350px;
max-width:850px;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
<ul>
<li style="color:white; float:left; width:50%;" rel="color:white;float:left; width:50%;">
</li>
</ul>
<div class="dropdown">
<strong>
<span style="font-size: 16px; color:black;">Character
</span>
</strong>
<div class="dropdown-content">
<span style="color: rgb(0, 0, 0);">The nature of an individual's moral personality, derived from his rooted, chosen moral values which are
consistently applied and expressed by his behavior and actions.
</span>
</div>
</div>
hi i tried your html and its working hope this helps thanks
Hey all I posted a question earlier here : Why am I getting white space between my HTML element? which was solved.
I have continued working on this page and have ended up with the following:
IE Screenshot:
http://postimage.org/image/2aqd5k99g/
Chrome Screenshot:
http://postimage.org/image/1xdm95138/
What I really want is basically the chrome screenshot but without the white space below my red footer. What can I do to get this desired effect for both IE and Chrome?
My HTML file is:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="swaggersstyle.css">
<title>Oamaru Backpackers Hostel, Swaggers Backpackers - Home</title>
</head>
<body>
<img src="final.jpg" id="banner"></img>
<ul id="nav">
<li class="links">Home</li>
<li class="links">Planning</li>
<li class="links">Construction</li>
<li class="links">Evaluation</li>
</ul>
<div id="mainc">
<p>Make Yourself at Home</p>
<p>Swaggers Backpackers is a converted old house located within walking distance of all the best parts of Oamaru. Explore the old victorian era buildings and shops of the city centre, or see the penguin colonies down the street. Swaggers is owned and operated by camp mum Agra, who makes all guests feel welcome, informed, and perhaps a bit mothered. </p>
</div>
<div id="rightcolumn">
<p>hghadgadgadg</p>
<p>easfasf</p>
<p>safSFS</p>
<p>afafafadf</p>
<p>safasf</p>
<p>saasfasf</p>
<p>fasfsaf</p>
</div>
<div id ="footer">
<p> fsafasfasf </p>
</div>
</body>
</html>
and my CSS file is:
html{
font-family: sans-serif;
background-color:#464E54;
}
body{
width: 960px;
margin: auto;
background-color: white;
border: 5px solid black;
}
#banner{
padding: 0px;
margin: 0;
display: block;
}
#nav {
list-style-type: none;
padding: 0px;
margin: 0px;
overflow: hidden;
}
#mainc {
float: left;
width: 760px;
background-color: white;
margin: 0;
}
#rightcolumn {
padding-left: 3px;
float: left;
background-color: #dad8bf;
width: 197px;
}
#footer {
clear: both;
background-color: red;
}
.links {
float: left;
margin: 0px;
}
a:link {
display: block;
width: 232px;
font-weight: bold;
color: #444444;
background-color: #dad8bf;
text-align: center;
padding: 4px;
text-decoration: none;
text-transform: uppercase;
margin-top: 0px;
}
a:visited {
display: block;
width: 232px;
font-weight: bold;
color: #444444;
background-color: #dad8bf;
text-align: center;
padding: 4px;
text-decoration: none;
text-transform: uppercase;
margin-top: 0px;
}
a:hover {
background-color: #999999;
}
a:active{
background-color: #999999;
}
Once again cheers for everyones help - hopefully after this I will be a bit more familiar to these mysterious white lines showing up.
add the following rule
div#footer p {
margin:0;
}
Use inspect element on chrome by right clicking.
you will find the area which is blue by moving mouse over the respected area and then you can solve the problem
Have you checked it on different chrome browsers (From different PCs chrome browsers) or do you have any download manager extension installed on your browser, if yes; then disable that first and then reload your page.
Hope this works for you.
Many of these problems are solved, only by importing and using a CSS Reset. Why don't you use them?
Theory: Browsers apply some default style on HTML elements, and they are not the same in that. For example, IE might add 15px margin to p elements, while Chrome might add 13px. This means that incosistencies can exist between default styles of HTML elements across browsers. CSS Reset is technically a set of CSS rules which zero-outs these default values. For example, you can see that in CSS reset, a p is directed to have 0 margin.
p
{
margin: 0;
}