Tips for eliminating corner gaps in css

As I dive into the world of CSS, I encountered an issue while working on my webpage. The problem lies in a space that appears on my displayed webpage.

.grouping:before,
.grouping:after {
  content: " ";
  display: table;
}

.grouping:after {
  clear: both;
}

nav {
  background-color: white;
  position: fixed;
  top: 0px;
  right: 0px;
  left: 0px;
}

nav figure {
  position: absolute;
}

img {
  width: 100px;
}

.primary-nav {
  float: right;
}

.primary-nav>li {
  display: block;
  float: left;
}

.primary-nav>li>a {
  float: left;
  padding: 25px 0;
  width: 100px;
  border-left: 1px solid;
}

nav li a {
  font-family: Arial, Helvetica, sans-serif;
  color: black;
  text-transform: uppercase;
  font-size: 15px;
  text-align: center;
}

nav li:first-child a {
  border-left: none;
}

nav li a:focus,
nav li a:hover {
  background: red;
  background-color: red;
}

body {
  background-color: grey;
}
<nav class="grouping">
  <figure>
    <img src="images/logo.png" alt="LOGO">
    <ul class="primary-nav">
      <li><a href="#">Home</a></li>
      <li><a href="#">Home2</a></li>
      <li><a href="#">Home3</a></li>
      <li><a href="#">Home4</a></li>
      <li><a href="#">Home5</a></li>
    </ul>
  </figure>
</nav>

My goal is to have the output match the Expected Result Image, but unfortunately, what I'm seeing is different with spaces at the corners as indicated by the arrows in the image here: Generated Result Image

Answer №1

1) The browser renders a default margin on the ul element, which can be fixed by adding the following CSS:

ul {
    margin: 0;
}

2) Similarly, the figure element also has default margins that can be removed using the following CSS:

figure {
    margin: 0;
}

It is recommended to inspect the output of the browser to observe how these default margins are rendered and adjust them accordingly.

https://jsfiddle.net/k5j7nayd/8/

Answer №2

If I were to style the image and the list items, I would opt for using `display: inline-block` instead of floats and reset some margins as illustrated below:

(Please note that in order to fit the elements into a narrow snippet window, I have reduced their width from 100px to 80px, but this adjustment is not necessary for wider viewports.)

(Additionally, I have inserted empty HTML comments at the end and beginning of each li element to eliminate the whitespace caused by inline blocks, ensuring that hover backgrounds completely fill the space between vertical borders.)

html, body {
margin: 0;
}

nav figure {
  position: absolute;
  width: 100%;
  margin: 0;
}

img {
  width: 80px;
  display: inline-block;
}

.primary-nav {
  float: right;
  margin: 0;
}

.primary-nav>li {
  display: inline-block;
}

.primary-nav>li>a {
  float: left;
  padding: 25px 0;
  width: 80px;
  border-left: 1px solid;
}

nav li a {
  font-family: Arial, Helvetica, sans-serif;
  color: black;
  text-transform: uppercase;
  font-size: 15px;
  text-align: center;
}

nav li:first-child a {
  border-left: none;
}

nav li a:focus,
nav li a:hover {
  background: red;
  background-color: red;
}

body {
  background-color: grey;
}
<nav class="grouping">
  <figure>
    <img src="images/logo.png" alt="LOGO">
    <ul class="primary-nav">
      <li><a href="#">Home</a></li><!--
      --><li><a href="#">Home2</a></li><!--
      --><li><a href="#">Home3</a></li><!--
      --><li><a href="#">Home4</a></li><!--
      --><li><a href="#">Home5</a></li><!--
    --></ul>
  </figure>
</nav>

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

How can you enable a button to be clicked from within a drawer?

Hey there, I've got a div that toggles hide/show like a drawer when clicked. When the drawer is in show state, it contains a button. How can I make the button clickable without toggling the drawer? Any ideas on this?! `zIndex` doesn't seem to be ...

I'm trying to create a horizontal list using ng-repeat but something isn't quite right. Can anyone help me figure out

Feeling a bit lost after staring at this code for what seems like an eternity. I'm trying to create a horizontal list of 2 image thumbnails within a modal using Angular's ng-repeat. Here's the HTML snippet: <div class="modal-body"> ...

Clipped Words & Silhouettes

I'm having trouble ensuring the text in this particular example displays correctly. I am experiencing challenges with the clipping of text and shadows on certain letters, and I'm struggling to identify the root cause as well as the solution. In ...

Tips for adjusting the positioning of a div element in a responsive design

I am currently working on my website and facing a layout issue. In desktop mode, there is a sidebar, but in mobile view, the sidebar goes down under the content displayed on the left side. I would like the sidebar to appear at the top in mobile view, fol ...

floating point for a list item compared to other elements

nav > ul > li { float: left; } #one { float: left; } <nav> <ul> <li> he has a cow </li> <li > he has a dog </li> <li> he has a mouse </li> </ul> & ...

Utilizing Bootstrap 4: Opting for <select> over tabs (<li>)

Is there a way to customize the appearance of Bootstrap tabs by replacing them with a dropdown select menu instead of the standard tab layout created with <ul> and <li> elements? I am working with a relatively small area (such as col-3) where ...

Having trouble getting the `nth-of-type` and `nth-child` selectors in CSS to function

I am attempting to apply a green color for the first nth child flag element <div id="axis"> <div class="super"></div> <div class="flag">flag 1</div><!-- I want this text to be green--> <div class="supe ...

css absolute positioning and setting the height of a repeating background

I am facing a challenge with a container that contains a repeating image and I want it to fill 100% of the available height. However, some inner divs have their :after pseudo elements absolutely positioned to achieve the desired borders, which is causing a ...

When I expand the accordion next to it, the accordion disappears, and it also vanishes when I close that accordion

After incorporating accordions into my site, I encountered a peculiar issue (as shown in this video): when I open one accordion, the adjacent accordion also opens unexpectedly. Similarly, closing one accordion causes its neighboring accordion to mysterious ...

Which web browser(s) can properly display the CSS property display: run-in?

Compatibility with IE7 and FF2.0 Suitable for IE8 and Opera 9+ Works only on IE7 Optimized for IE8 and FF3.5 Supports IE7 and Safari This question came up in a quiz, but I don't have all the browsers to test it. Any assistance would be greatly apprec ...

What causes the CSS `resize` property to be inherited in Chrome browsers?

It was my understanding that elements do not inherit the resize property from their parent elements. However, I recently discovered that in Chromium they actually do: Here is a screenshot of Chromium's inspector: Check out this demo: http://jsfi ...

Update the background image every minute with a smooth transition effect

I am currently in the process of developing a personal dashboard that requires dynamic background images to change every minute. To achieve this functionality, I have integrated the [Pixabay API][1] and formulated the following API request: https://pixaba ...

Modify the appearance of HTML dialog box using CSS styling

Currently, I am working on a Java Spring project that includes a single CSS file consisting of around 1500 rows. Recently, I was tasked with adding a dialog box to one of the screens in the project. The issue I encountered is that the style of the dialog b ...

Unable to perform updates for personalized fonts

I've been trying to incorporate custom fonts into my website, but I seem to be facing difficulties in actually implementing them. Could someone please let me know if I am doing it correctly? .pattern{ background:rgba(0,0,0,.5) url(../images/pattern ...

Tips for positioning an asp.net Button alongside other elements in a form by making use of Bootstrap styling

Looking to revamp the style of my ASP.NET Web Forms project with the latest version of Bootstrap. Having trouble aligning an ASP.NET Button control horizontally with other controls in the form, as seen in this snapshot: https://i.sstatic.net/IVRKo.png Her ...

Activate the Bootstrap 5 responsive font sizing feature (RFS) for the base font elements

I'm attempting to utilize Bootstrap's RFS functionality in version 5.1.3 to apply font sizing globally. Within my SCSS file, I've defined some basic font sizes, imported the Bootstrap SCSS files, and configured the font size settings. Howev ...

Tips for organizing list items in a grid format using CSS and HTML

In my div block, the width is not fixed. Inside the div, there is a list block with 11 items that I want to display evenly like this: ##item## ##item## ##item## ##item## ##item## ##item## ##item## ##item## ##item## ##item## ##item## I&a ...

Tips for using JavaScript to style an array items individually

I have currently placed the entire array within a single div, but I would like to be able to display each element of the array separately so that I can style "date", "title", and "text" individually. This is my JSON structure: [ { "date": "Example ...

What are some methods for applying border styles to the first and last row of a table using Material UI?

In my current project, I am utilizing the combination of Material UI and React Table. Recently, I was asked to implement an expandable row feature, which I successfully added. Once the user expands the row, we need to display additional table rows based on ...

Disappearing text with HTML Bookmark and CSS Overflow:Hidden - What's happening?

Within the header of my webpage, there is an image div that has been styled with overflow:hidden. Inside the content section, I have a bookmark anchor tag: <a name="arghargh"></a> Located at the top of the content area, there is a link that ...