Style the item with flexbox to have a border around it without increasing its height

In this scenario, the border is not surrounding the blue box but rather extends over the entire window height.

Is there any advice on how to create a border around the blue box?

Important Points:

  • The HTML and body definitions cannot be altered.
  • The padding in "div1" must remain unchanged.
  • I have attempted various combinations involving "display: inline-block," etc., with no success.
  • It's likely that this question has been asked before. However, my search for an answer has been fruitless. Any suggestions of a good "duplicate" source would be appreciated.

html {
height: 100%;
}

body {
height: 100%;
margin: 0; 
display: flex;
flex-direction: row;
}

#div1 {
padding: 2em; 
border: 1px solid green;
}

#blueDiv {
width: 5em;
height: 5em;
background-color: blue;
}
<!DOCTYPE html>
<html>
<body>
<div id="div1">
<div id="blueDiv"></div>
</div>
</body>
</html>

Answer №1

Is it possible to apply outline and outline-offset directly to the element with id #blueDiv?

html {
height: 100%;
}

body {
height: 100%;
 margin: 0; 
display: flex;
flex-direction: row;
}

#div1 {
padding: 2em;
}

#blueDiv {
width: 5em;
height: 5em;
background-color: blue;
/* OUTLINE */
outline: 1px solid green; 
outline-offset: 5px; 
}
<!DOCTYPE html>
<html>
<body>
<div id="div1">
<div id="blueDiv"></div>
</div>
    <p>The blue box now has a green outline positioned 5 pixels away from its border.</p>
</body>
</html>

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

"Composing perfect sentences: The art of incorporating quotes

I am attempting to include text with quotes in a DIV, like so: "All is well that ends well" The text is generated dynamically and I'm using a JavaScript font replacement plugin (CUFON) to add quotes around the text. Sometimes, the ending quote drops ...

Image positioned above the text in the mobile layout following the text

Can the layout be adjusted so that on desktop, the image is on the right and text on the left in the lower box, but on mobile, the image appears above the text? https://i.sstatic.net/hbPxa.png I understand that placing the image tag after the text tag in ...

Incorporating a YouTube or Vimeo video while maintaining the proper aspect ratio

On my video page, I embed Vimeo videos dynamically with only the video ID. This causes issues with the aspect ratio as black bars appear on the sides due to the lack of width and height settings. The dynamic video ID is implemented like this: <iframe ...

Showing Predefined Date on an HTML Form in an iOS Application

Is there a method to dynamically show the current date within the button that triggers the date picker in an HTML form on an iOS device? This is what currently appears: This is what I want it to automatically display: Below is the code I have implemente ...

Unable to access the jumbotron in Angular with Bootstrap 5

Recently, I set up a brand new Angular installation and included Bootstrap 5 using the following command: npm install bootstrap --save After that, I updated the lines in the angular.json file to: "styles": [ "node_modules/bootstra ...

Change the css code to override the color of the background material

Hey there, I'm facing an issue with overriding the background color of a material element. I've tried several methods but can't seem to get it to change. After inspecting the element on the web browser, I found the CSS code that controls th ...

"Enhance Your Website with Creative Image Hover Effects using HTML

I'm looking to add a simple hover effect to the images AboutUsLink.png and AboutUsColourLink.png, but I'm unsure of the process. Here is the HTML code: <section class="link1"> <a href="#SecondLink"><img src="images/LogoAndLin ...

Suggestions for resetting the input field IDs in a cloned div after deletion

In the given HTML code snippet, there is a <div> containing two input fields as shown below: <button type = "button" id = "add-botton" >Add Element </button> <div id = "trace-div1" class = "trace"> <h4><span>Trac ...

Using javascript code to encode images to base64 and save the output to a text file

How can I modify the code below: <p id="demo"></p> <script> var openFile = function(event) { var input = event.target; var reader = new FileReader(); reader.onload = function(){ var dataURL = read ...

Angular List Selector: A versatile multiple selection component with a stylish list design

I'm in need of a select component similar to the one shown in https://i.sstatic.net/mo6NH.png The issue is that Material Angular doesn't have this specific component, so I opted to use the default HTML select inside my component. Everything was ...

Center-align the text vertically in relation to the icon

A query has arisen, regarding a div that contains text and an icon. The issue at hand is that on larger screens the text is not vertically aligned in the center. For further reference, please visit this bootply link: http://www.bootply.com/CHKeRxKOX6 http ...

How can a single value (the clicked one) be retrieved from a for loop using addEventListener in a Django project with JavaScript

Struggling to integrate JS into my Django project, I received the following message in the console: HTMLCollection(2) [p.currency-one, p.currency-one] HTMLCollection(2) [input.amount-one, input.amount-one] app.js:21 Uncaught TypeError: c1.addEventListener ...

Restrict the number of dynamic form elements to a maximum of 10 entries

I am working on a feature where users can refer their friends and the data will be saved in a database. <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type='text/javascript' sr ...

Update the header on the vis.js timeline for better visibility on the page

The updated library now includes fixed headers within the chart itself, which is a great improvement. However, we feel that it only solves half of the issue at hand. Customizing the headers is still a challenge, so I implemented a separate row to display ...

In Vue.js, the 'select' option is consistently set as the default choice

Encountering an unusual issue with a select field in vue.js. Desired outcome: a select field with no default option selected. In regular html, this is easily achievable. Here is the jsfiddle Link: https://jsfiddle.net/odsf3awr/ <select id="test" s ...

Troubleshooting the issue of Bootstrap 4 scrollspy failing to update active navbar items

I have been working on a Bootstrap 4.0 landing page and trying to implement ScrollSpy without success. The active menu items are not changing as expected. Here is the code snippet from index.html: <body> <!-- Navbar --> <nav id="main-nav" ...

A method to incorporate the profile_pic attribute from a different model into a single model

I need to display the profile picture in the Blog View page that is stored in the Profile model models.py class Profile(models.Model): user = models.OneToOneField(User,null=True, on_delete=models.CASCADE) bio = models.TextField() profile_pic = ...

Encountering a ModuleBuildError while setting up Tailwind CSS in Laravel 8

I am currently learning Laravel version 8 and encountered an issue while trying to install Tailwind CSS using the npm command. npm install tailwindcss@npm:@tailwindcss/postcss7-compat @tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9 Here is a detai ...

What is the best way to bridge the distance between a shrunken iframe and the following element?

https://i.sstatic.net/AZ7T4.png My iframe was resized to 65%, but the containing "div" still occupies the original iframe size, creating a large gap between the iframe and the next element. I'm not sure how to remove this gap. I want the next element ...

Why does the value of my input get erased when I add a new child element?

I seem to be facing an issue when I try to add an element inside a div. All the values from my inputs, including selected options, get cleared. Here's a visual representation of the problem: https://i.sstatic.net/UpuPV.gif When I click the "Add Key" ...