What is the reason the text does not have a border around it?

The border is supposed to be around the text, but it isn't showing up. Where did I go wrong? Could it be that I need to set a position?

html {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background-color: #282A2E;
}

menu {
  color: white;
  font-size: 20px;
}

#menu__item {
  border-color: white;
  border-style: solid;
}
<div style="overflow: hidden;">
  <menu>
    <div class="menu__item">
      text
    </div>
  </menu>
</div>

Answer №1

Here's a solution that should work:

<html>
<head>
        <meta charset="UTF-8"">

<style>
html { width:100%; height:100%; margin:0; padding:0; }
body { width:100%; height:100%; margin:0; padding:0; background-color: #282A2E;  }
menu {
    color:white;
    font-size: 20px;
}
.menu_item {
    border: 1px solid white;
    width:fit-content;
    
}
</style>
</head>
<body>
    <div style="overflow: hidden;">
        <menu>
           <div class="menu_item">
               text
            </div>
        </menu>
    </div>
       
</body>
</html>

The issue was with incorrectly defining the class menu_item. Remember, # denotes an id, not a class.

Result:

<html>
<head>
        <meta charset="UTF-8"">

<style>
html { width:100%; height:100%; margin:0; padding:0; }
body { width:100%; height:100%; margin:0; padding:0; background-color: #282A2E;  }
menu {
    color:white;
    font-size: 20px;
}
.menu_item {
    border: 1px solid white;
    width:fit-content;
    
}
</style>
</head>
<body>
    <div style="overflow: hidden;">
        <menu>
           <div class="menu_item">
               text
            </div>
        </menu>
    </div>
       
</body>
</html>

To enhance the appearance, I also included width:fit-content; to ensure the border only surrounds the text and added padding for better spacing as shown below:

<html>
<head>
        <meta charset="UTF-8"">

<style>
html { width:100%; height:100%; margin:0; padding:0; }
body { width:100%; height:100%; margin:0; padding:0; background-color: #282A2E;  }
menu {
    color:white;
    font-size: 20px;
}
.menu_item {
    border: 1px solid white;
    width:fit-content;
    padding:1em;
    
}
</style>
</head>
<body>
    <div style="overflow: hidden;">
        <menu>
           <div class="menu_item">
               text
            </div>
        </menu>
    </div>
       
</body>
</html>

Note: Using border-color may be redundant. Instead, you can achieve the same effect with

border: <width> <design> <color>
, like so: border: 1px solid white

Answer №2

When utilizing #menu__item, keep in mind that this refers to an ID, not a class. For adjusting the CSS of the menu__item class, utilize the following code:

.menu__item {
    border-color: white;
    border-style: solid;
    
}

Answer №3

When styling with CSS, you are referencing an ID using #menu__item, but in the HTML it is designated as a class. To correct this issue, either change the CSS to target a class or update the HTML to use an ID.

Answer №4

  • Make sure to specify the width of the border.
  • Also, remember to update #menu__item to
    .menu__item</code as <code>menu__item
    is a class name.

html { width:100%; height:100%; margin:0; padding:0; }
body { width:100%; height:100%; margin:0; padding:0; background-color: #282A2E;  }
menu {
    color:white;
    font-size: 20px;
}
.menu__item {
  border: 1px solid white;
  display: inline-block;
}
<div style="overflow: hidden;">
  <menu>
    <div class="menu__item">
      text
    </div>
  </menu>
</div>

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

Is it possible to retrieve the selected DataList object in Angular 10?

I encountered an issue while creating an Input field with DataList. My goal was to retrieve the entire object associated with the selected option, but I could only access the selected value. Previous suggestions mentioned that DataList items should be uniq ...

Tips for adjusting the search bar's position on a mobile device when it is activated by the user

I need help with an open source project where I am developing a search engine using Angular. When using smaller screen sizes, the search bar is positioned in the middle but gets hidden behind the keyboard terminal when clicked on. Can anyone advise on ho ...

Discovering the positions of HTML elements rendered with WebKit (or Gecko) technology

I am seeking a way to retrieve the dimensions (coordinates) of all HTML elements on a webpage as they appear in a browser, including their rendered positions. Specifically, I need to obtain values like (top-left, top-right, bottom-left, bottom-right) Afte ...

Animate the transition effect as soon as the block is displayed

Looking to create a smooth page transition using CSS changes with the help of Javascript (jQuery). Initially, one of the pages is set to display none. page1 = $('.page1'); page2 = $('.page2'); page1.removeClass('animate').cs ...

Steps for breaking down a given string into divisions that correspond to an A4 sheet

Within my content, there are various styles applied. For example: This is a <b>bolded</b> word. I am seeking a solution to divide this long string into smaller sections that would fit on an A4 page accurately. The goal is to maintain the integ ...

Alter the CSS display based on the user's userAgent if they are using an iPhone and window.navigator.standalone is set to true

Looking to create a unique webAPP with different content displays based on how it is accessed. If the user opens the webAPP through their Safari browser Or if they open the webAPP from a webclip on their home screen The detection is functioning, as conf ...

What is the best way to adjust text across several lines to perfectly fit within a div's width?

http://codepen.io/anon/pen/oXGMQZ Is there a way to automatically adjust the font size of each span within a parent div so that it fills the width of the parent div? <div class="box"> <span class="fit">what</span> <span class="fi ...

JavaScript Function that Automatically Redirects User or Updates Text upon Clicking "Submit" Button

Looking to create JavaScript functionality that directs users back to the homepage after submitting their name and email. The process should follow these steps: 1.) User clicks "Request a Brochure..." https://i.sstatic.net/KqH2G.jpg 2.) A window opens in ...

md-datepicker incorrect input- AngularJS

When selecting a non-existent date manually in the input, the calendar shows the date I expect but the input does not. Here is the code snippet: <md-datepicker name="startDate" class="custom-datepicker" ng-model="models.startDate" md-placeholder="Ente ...

What is the most concise way to align one table row in the middle and another at the top?

Is there a way to align different rows in a table vertically with minimal code? I have a table with 3 rows, and I want the first two rows to be aligned vertically to the top, while the third row should be vertically aligned to the middle. If I try to def ...

Display a text field when the onclick event is triggered within a for

Control Panel for($i = 1; $i <= $quantity; $i++){ $data .= '<b style="margin-left:10px;">User ' . $i . '</b>'; $data .= '<div class="form-group" style="padding-top:10px;">'; $data .= ' ...

Display or conceal a div based on the size of the screen using HTML and CSS

Hey there, I recently finished my first React Project and I’m wondering if there’s a way to hide the 'side-menu' section on mobile screens using CSS. Any suggestions? <div className='side-menu'> <SiderComponent /> < ...

Django: Troubleshooting problem with offcanvas PDF preview iterations

Hey everyone! I'm in the process of creating a webpage that features a table with metadata regarding PDF files. To enhance user experience, I want to provide users with a preview of stored files in an off-canvas format. This is my HTML file setup: & ...

Steps to implement the selection of multiple items from a drop-down or list on a React.js website

Hi there, I am a newcomer to the world of React JS web development. I am looking for guidance on how to implement a feature where users can select multiple cities from a drop-down or list, similar to the examples shown in image1. Once the user has made th ...

Inline-block divs styled with CSS3 are causing a white gap to appear at the top of

I have been searching for solutions to my problem, but I can't seem to find one that works. My goal is to create two columns that each take up 50% of the screen width. However, I am facing an issue where there is a gap at the top that I cannot seem t ...

Using Chrome or Firefox's inspector tool to make changes to HTML code

Is it possible to save changes made to HTML elements in Chrome/Firefox inspector directly to a local file on my desktop? ...

I need help with formatting a div to look like this

Looking to simplify my page by reducing the number of divs, wondering if this "tile" could be achieved without using one. Here's the example I have in mind: <a href="mks.html" class="big-tile big-tile-1"> <h1>town<br> libra ...

Import the CSV file and store it in a designated directory using JQuery

My goal is to enable users to upload a CSV file from an HTML page and have it saved to a specified local directory upon upload. Two possible scenarios could unfold: if the uploaded file already exists, it should be overwritten; otherwise, a new file shoul ...

Guide on sending information using ajax using a button within a form

I've been working on creating a form that utilizes HTML5 validations and integrates Ajax to show the status of mail sending. However, I'm facing an issue where clicking the send button does not initiate the expected action. Form HTML: <div c ...

What is the best way to convert this PHP string into an image?

Is there a way to replace the string "Overview" with an image instead? If it's possible, how can I achieve this? if (empty($lang) || !is_array($lang)) { $lang = array(); } $lang = array_merge($lang, array( 'UCP_MAIN' => 'Ov ...