Selection of text within a block resembling a bar of buttons

design.css

body {
    background-color: #666666;
    margin-left:500px;
    margin-right:500px;
    margin-top:10px;
    margin-bottom:20px;
    font-family:Verdana, Geneva, Tahoma, sans-serif;
    font-size:12px; 
    color:white;
}

div.header {
    background-color: #333333;  
}

div.navigationBar {
    border:0;
    border-style:solid;
    background-color:#112211;  
}

div.navigationButton {
    border:1px;
    border-color:#ffffff;
    border-style:solid;
    background-color:#112211;
    padding:15px;
    width:100px;
    height:40px;
    text-transform:uppercase;
    overflow:hidden;
    font-weight:bold;
    text-align:center;
}

.navigationBar ul {
    list-style-type:none;   
    padding:1px;
}

.navigationBar li {
    display:inline;
    float:left; 
}

.navigationButton a
{
    text-decoration:none;
    color:#eec600;
    display:block;
}


.navigationButton a:link {
    text-decoration:none;
}


.navigationButton a:hover {
    color:#ffe811;
}

homepage.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta content="pl" http-equiv="Content-Language">
  <link rel="stylesheet" type="text/css" href="design.css"/> 
</head>
<body>
  <div class="header" style="height:200px; width: 800px;"></div>
  <div class="navigationBar" style= "height:73px; width: 800px;" > /* added unit to the height property */
    <ul>
      <li><div class="navigationButton" ><a href="#link4">Button4</a></div></li>
      <li><div class="navigationButton" ><a href="#link5">Button5</a></div></li>
      <li><div class="navigationButton" ><a href="#link6">Button6</a></div></li>
    </ul>
  </div>
</body>
</html>

Why is there a space between the header div and the navigationBar? Any feedback or suggestions for improvements are greatly appreciated.

The strange gap appears in web browsers (but not in jsFiddle). I have tested this code on Firefox and IE.

Answer №1

Your code has several mistakes that need to be addressed:

  • Avoid using div elements inside list items
  • Ensure your height values in HTML have a specified unit, like height: 73px;
  • Avoid unnecessarily nesting elements, such as placing your ul element within a div, along with links inside list items.
  • Avoid mixing inline styles with linked stylesheets.

If you can provide more details on what you're trying to achieve or any specific examples, it would help in providing better assistance.

I've made some modifications to your code for better cross-browser compatibility. Let me know your thoughts on the revised version.

Here is a Fiddle link to the updated code with CSS separated into a different file: http://jsfiddle.net/FsvJ3/

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Example</title>

  <style type="text/css">
    /* Updated CSS styles */
  </style>

</head>
<body>
  <div id="header"></div>

  <ul id="nav">
    <li><a href="#">Button 1</a></li>
    <li><a href="#">Button 2</a></li>
    <li><a href="#">Button 3</a></li>
  </ul>
</body>
</html>

In your original code, the way you attempted to center content could lead to unexpected behavior. I adjusted it by setting explicit width and using auto for margins.

It's advisable to simplify the structure by minimizing unnecessary elements. For instance, consider styling the list directly instead of enclosing it in a div with the class navigationBar.

Keep your markup concise, focusing solely on essential elements rather than adding extra hooks for styling purposes.

Answer №2

It is not recommended to place div elements inside li elements. Instead, you can simply assign the li element a class of navigationButton.

I have tested your code on jsfiddle and I cannot see any gap that you mentioned...I would recommend checking the link: http://jsfiddle.net/qL8Ra/

Answer №3

Check out this Fiddle

I'm puzzled by the Gap between the grey Header and the navigation bar. Any thoughts on how to address it? Also, any feedback on the code provided?

<li> class="navigationButton" ><a href="#link1">Button1</a></li>
<li> class="navigationButton" ><a href="#link2">Button2</a></li>
<li> class="navigationButton" ><a href="#link3">Button3</a></li>

It's recommended not to use inline styles like

style="height:200px; width: 800px;"
since you already have a stylesheet.

Your code could be more readable if formatted properly for easier understanding.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Enhanced browsing experience with personalized search suggestions

As a developer, I am aware that you have the ability to customize the browser's suggestions for various fields. For example, specifying that a field is for email and only suggesting values for email fields in the future. Is this functionality really ...

Error 404: The requested file could not be located on the MAMP server

Whenever I try to access a PHP file on MAMP, I keep getting a 404 error message. The error reads: "The requested URL /‘welcome.php’ was not found on this server." Oddly enough, both the HTML and PHP files work perfectly fine when accessed via localho ...

How to visually deactivate a flat button ( <input type="button"> ) programmatically with JavaScript

I am facing an issue with my buttons. I have one regular button and another flat button created using input elements. After every click, I want to disable the buttons for 5 seconds. The disable function is working properly for the normal button, but for th ...

CSS Animation glitch with images

I am currently facing an issue with a slide that transitions between four pictures. The slide is set at a specific pace, but I am encountering a problem with the transition from the last slide back to the first one. I have attempted various solutions such ...

In JavaScript, a "switch statement" retrieves a test value from a "input type text" by accessing the value using getElementByName.value

Attempting to test 7 possible values for the variable 'a' by passing it to a function from user input in seven 'input type text' boxes, then checking each value individually with clicks on 7 'input type image' elements. Howeve ...

The back button fails to refresh the page on a website utilizing Ajax technology

Recently, I implemented AJAX on a client's website to introduce some smooth animations for page transitions. When navigating from the homepage of firedogcreative.com to the edit page, and then to one of the work pages, we see a history like this: fir ...

Properly appears in Chrome, but experiences issues in Internet Explorer 11

The design of the website looks seamless in Chrome and Firefox, however, when I view it in Internet Explorer, I notice a significant gap on the right side of the first two pages. How can I fix this issue specifically for Internet Explorer? Should I use a m ...

Is it possible to place a list/accordion above a button in Semantic UI?

Check out this rough code sandbox here There seems to be an issue with the accordion overflowing behind the button on the left side. I attempted to add style={{position: 'absolute', bottom:'2%', overflow: 'scroll'}} to the A ...

"Activate the mat-checkbox based on the outcome of a certain process

I'm working with a mat-checkbox that triggers a mat-dialog when clicked. If the user clicks "confirm" in the dialog, I want the checkbox to be checked. If they click "cancel", I want it to remain unchecked. How can I achieve this? Below is the method ...

SVG tags are not functioning properly

Hello, I am new to working with SVG files. I have a set of icons created using SVG and I am attempting to use the <use> tag in order to display a specific part of an SVG file. However, I seem to be encountering some issues and I am unable to identi ...

Adding several <div> elements with the correct indices

I need help with a dynamic form that requires users to select a state before revealing the corresponding cities within that state. <form method="post"> <div class="summary"> <div class="trip"> <select name="State" class="s ...

Switch up the color of checkboxes with a dropdown menu option

I have an HTML dropdown code and I am trying to trigger a click event when a specific value is selected. Once this value is clicked, I want some checkboxes to change color. <select> <option value="calculate">calculate</option> ...

Checkbox offering a tri-state option

Seeking help on creating a checkbox with three states. I have implemented a method to toggle between these states upon clicking. However, the issue is that this method is only triggered after the HTML changes. As a result, the checkbox's navigation be ...

"Addclass() function successfully executing in the console, yet encountering issues within the script execution

I dynamically created a div and attempted to add the class 'expanded' using jQuery, but it's not working. Interestingly, when I try the same code in the console, it works perfectly. The code looks like this: appending element name var men ...

Create an HTML table using data from a Python dictionary

Can anyone help me convert the dictionary below into an HTML table? {'Retry': ['30', '12', '12'], 'Station MAC': ['aabbccddeea', 'ffgghhiijj', 'kkllmmnnoo'], 'Download&ap ...

Page width incorrectly set leading to unnecessary scrolling

Having a bit of trouble with this layout - while everything looks good, the page extends to the right with just a blank space. I've tried everything but nothing seems to work. .container.open-sidebar { position: relative; left: 240px; } #sidebar ...

Selenium Webdriver is retrieving background colors with unexpected alpha values

When I need to retrieve the background-color of a WebElement, I typically use the following code: string color = IWebElement.GetCssValue("background-color"); Selenium often returns something like this for the color value: color = "rgba(153, 255, 255, 1) ...

Display or conceal a frame with the help of JavaScript or jQuery

Is there a simple way to hide the "topFrame" and "menu" frames when clicking an image or button, and then unhide them by clicking again? Apologies for not including the "topFrame" and "menu" jsp files, as they are dynamically generated in my application. ...

Troubleshooting issue with Calendar styling in Bootstrap and SimpleCalendar Rails integration

I am having trouble applying styling to my SimpleCalendar in Rails, using the gem. When I render it, this is what I see: https://i.sstatic.net/kJi7m.png Here is the CSS provided by https://github.com/excid3/simple_calendar: .simple-calendar { table { ...

I have just started a new project in Vue and noticed that the app div has some extra margin around it. Can anyone

In my fresh Vue project, I have the following code: App.vue: <template> <div id="app"> <p>hello</p> </div> </template> <script> export default { name: 'App', components: { } ...