Blocks that rely on the specific block can be found positioned to the right and below it

I am currently exploring different methods to create a specific layout using CSS only:

https://i.sstatic.net/rcPih.png

Essentially, I need the height of the "title" block to adjust according to the size of the image in the "logo" block and position this block directly next to the "logo" block. The same requirement applies to the "menu" block, which should be positioned directly below the "logo" block with identical width.

I attempted to implement it with inline styles for demonstration purposes: https://jsfiddle.net/DmitryGinzburg/kt7g1esu/

HTML:

<div id="top">
  <div id="logo">
    <img src="http://placekitten.com/200/100"/>
  </div>
  <div id="account">
    Hello, abacabaUser
  </div>
</div>
<div id="bottom">
  <div id="menu">
    <ul class="nav_bar">
      <li>Anchor1</li>
      <li>Anchor2</li>
      <li>Anchor3</li>
    </ul>
  </div>
  <div id="content">
  Duis laoreet hendrerit aliquam. Ut cursus pellentesque ex in vehicula. Integer aliquet velit sed neque ultrices, id condimentum nibh accumsan. Sed maximus molestie nulla, et viverra eros sollicitudin id. Sed in dapibus mi, eget faucibus urna. Ut nulla lacus, cursus in lorem ut, rhoncus tempus velit. Vivamus lobortis egestas finibus. Proin eget mauris ut nisi euismod aliquam quis nec odio. Nulla ac turpis ac urna euismod porttitor. Proin lacus lectus, bibendum in mauris ac, sollicitudin laoreet mi...
  </div>
</div>

CSS:

div {position: absolute;}

.nav_bar {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

#account {left: 500px;}

#menu {top: 100px;}

#content {
  top: 100px;
  left: 200px;
  width: 400px;
}

The challenge lies in creating dependency among blocks within the same parent element, which proves difficult as fixing one parameter (height/width) limits the other. How can this be achieved effectively?

P.S: While I am aware of the table approach, I aim to explore alternative methods as advised in various resources on this subject.

Answer №1

Using CSS layout tables would be the best approach in this scenario, steering clear of traditional HTML tables and opting for a more flexible table layout.

.nav_bar {
  list-style-type: none;
  margin: 0;
  padding: 0;
}
#logo,
#menu,
#account,
#content {
  display: table-cell;
}
#account {
  vertical-align: middle;
  text-align: center;
}
#top,
#bottom {
  display: table-row;
}
<div id="top">
  <div id="logo">
    <img src="http://placekitten.com/200/100" />
  </div>
  <div id="account">
    Hello, abacabaUser
  </div>
</div>
<div id="bottom">
  <div id="menu">
    <ul class="nav_bar">
      <li>Anchor1</li>
      <li>Anchor2</li>
      <li>Anchor3</li>
    </ul>
  </div>
  <div id="content">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam tempor turpis orci, a sodales arcu laoreet sit amet. Vestibulum nibh enim, iaculis sed risus in, egestas auctor mi. Ut a aliquam mauris, vel posuere est. Fusce a nisi vitae urna convallis
    porta. Suspendisse sed tristique augue. Proin at mollis quam. Aliquam odio elit, auctor sed tortor sed, malesuada dignissim nulla. Ut ultrices neque urna, eu accumsan turpis viverra id. Nunc rhoncus ex eget urna facilisis tempor. Nullam id pretium
    elit. Vestibulum libero lorem, semper sed ex sed, interdum dignissim tortor. Aliquam sollicitudin neque diam, non pharetra est hendrerit a. Vivamus hendrerit venenatis orci et scelerisque. Class aptent taciti sociosqu ad litora torquent per conubia
    nostra, per inceptos himenaeos. Integer commodo risus libero, nec elementum orci hendrerit sed. Nunc eleifend sapien ac vehicula porttitor. Vivamus laoreet purus lectus, faucibus pretium erat fringilla ut. Etiam accumsan justo at metus porttitor condimentum.
    Quisque vel lorem a lacus volutpat ornare vitae quis turpis. Suspendisse potenti. Nam cursus odio sed ipsum semper, sed interdum mi sollicitudin. Suspendisse rutrum justo at eleifend vestibulum. Maecenas ut urna nibh. Mauris eget turpis metus. Aenean
    lobortis fermentum augue, vitae interdum justo ullamcorper nec. Donec viverra, nisl scelerisque iaculis suscipit, lectus odio fringilla massa, nec tincidunt neque velit vitae mi. Proin pharetra fringilla ligula. Class aptent taciti sociosqu ad litora
    torquent per conubia nostra, per inceptos himenaeos. Aliquam porta leo in dolor commodo, faucibus pretium elit fringilla. In eleifend lorem quis enim feugiat, id fringilla ipsum malesuada. Morbi non feugiat urna, ullamcorper tincidunt nibh. Nam lacinia,
    velit sed ultrices faucibus, erat tortor tincidunt tellus, cursus imperdiet turpis ante eu arcu. Integer sed facilisis libero, vitae mattis nisl. Proin cursus, sem at tempor convallis, ligula ligula egestas erat, eget molestie justo elit vitae dui.
    Praesent leo velit, luctus vitae suscipit id, placerat a velit. Proin posuere enim vel lobortis gravida. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur bibendum dui quis velit ornare rhoncus.
    Phasellus blandit vulputate ligula, at molestie ligula consequat sit amet. Mauris faucibus luctus mauris, in gravida nulla facilisis pellentesque. Nunc vitae odio rutrum odio hendrerit mattis eu eu tellus. Vivamus tincidunt, nulla et varius mollis,
    dolor ligula viverra nibh, sed porttitor urna nisl nec quam. Duis laoreet hendrerit aliquam. Ut cursus pellentesque ex in vehicula. Integer aliquet velit sed neque ultrices, id condimentum nibh accumsan. Sed maximus molestie nulla, et viverra eros
    sollicitudin id. Sed in dapibus mi, eget faucibus urna. Ut nulla lacus, cursus in lorem ut, rhocus tempus velit. Vivamus lobortis egestas finibus. Proin eget mauris ut nisi euismod aliqucaqm quis nec odio. Nulla ac turpis ac urna euismod porttitor.
    Proin lacus lectus, bibendum in mauris ac, solliciitudin laoreet mi. Quisque posuere lobortis imperdetiitt. Etiam id quam eu mauris congue faicbus sit amet non libreo. Sed et massa in claus poseure imperdiet vitse in laduis. Nulla maruis nlsif veenenatiis
    eu grvida sit amet, ultriecies eu tellus.
  </div>
</div>

While utilizing CSS table layout is suitable for non-tabular data, it may not offer the perfect solution. If the menu's width exceeds that of the image, issues may arise due to current layout constraints. It might be worth considering CSS Grids as an alternative once they are fully supported.

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

Using Express.js to serve simple SVG files (Technique involving Cheerio.js)

My goal is to manipulate SVGs before sending them through Express.js. The code snippet I am using is as follows: app.get("/iconic/styles/:style/:base/:icon", function (req, res) { var style = req.params.style; var base = req.params.base; var i ...

<td> issue with IE not rendering overflow:hidden properly

In an effort to display text in a TD, I've implemented the overflow property set to hidden for the td element. Surprisingly, this code works flawlessly in Chrome, Safari, and Mozilla browsers, but unfortunately falls short in IE. Despite attempting to ...

Does anyone know a workaround for addressing the issue of the "n items remaining" problem specifically on Internet Explorer?

When using my ASP.Net app, which heavily relies on javascript and jQuery, along with master pages and .Net Ajax components, I consistently encounter an issue in IE 6 (and sometimes IE 7) where the status bar displays messages like "2 items remaining" or "1 ...

Arrange three input fields horizontally with labels positioned above each

I am facing a minor problem with aligning three input fields in the same row while maintaining equal spacing between each of them. I attempted to accomplish this using display: flex and space-between, but then the label appears to the left of the input in ...

What is the best way to eliminate the extra space above a span when the parent element's font size is very large?

Dealing with a situation where the parent DOM-element has a large em-value which results in all inline child elements having a significant margin above them despite their smaller font-size: Here is the source (http://jsfiddle.net/rapik/w87m7/2/): <div ...

Place various <select> choices in numerous rows

Currently, I have an HTML form that contains a select field with multiple options that allow selecting multiple values. Previously, I was using the implode function to insert these selected values into a MySQL table separated by commas. However, I now need ...

Leveraging PHP to construct a TABLE based on JSON data

Recently, I delved into learning PHP and successfully retrieved the JSON data I needed. However, I hit a roadblock when attempting to construct a table using this data. Despite my trial-and-error approach, I find myself stuck at this point. The current st ...

Issue: Inability to scroll on div overflow section

My website consists of one static page with an HTML and CSS file. Oddly enough, when testing the page and inputting content into a multiline textarea until it overflows, the browser fails to display a scrollbar. Despite inspecting the div with the id &apos ...

The hover effect seems to be disabled in the third-level submenu

I need help creating a dropdown menu that shows an image when hovering over a specific item. I have checked my CSS code and HTML structure, but the image is not appearing as expected when I hover over the "Afyon White" list item. Any ideas on how to fix th ...

The use of dates (YYYY-MM-DD) as identifiers in HTML/Angular 2 is causing issues

I have successfully created a calendar using html in Angular 2, and now I am looking to incorporate events into it. These events should be able to color specific days, add a dot inside the cell, or something similar. I have a json file that contains the ev ...

Arrange images in a fluid manner around other images

Check out the website I'm currently working on: metroweb.tk I'm in the process of designing a website that mimics the Windows 8 metro UI. However, I've encountered an issue with larger app icons such as notes and clocks sticking out. Is the ...

Applying a specified style to a pseudo element using the ::after selector to display an

Can anyone help me with adding a pseudo element ::after containing an icon (from FontAwesome) to my Bootstrap Vue ProgressBar? I want this icon to be dynamic and move along the progress bar line when I click. Here is my current implementation, where the Pr ...

What is preventing npm sass from compiling properly?

https://i.stack.imgur.com/ekbNW.png While making edits to my code, I've noticed that the sass-compiler isn't indicating any errors (red lines) or successful compilations (green lines). Can someone help me identify where I might be going wrong? ...

Guide to sending an HTML document containing images using the express framework

Is there a way to send an HTML file along with images using express? I have the following code that handles sending the initial page (index.html) to users. However, this page contains elements such as images and css files which are not being transferred p ...

Is it possible to adjust the background size using jQuery?

When attempting to set backgroundSize with jQuery using the code provided, I consistently encounter an error on the fourth line: "unexpected identifier." bigwidth = 200; bigheight = 100; $(e.target).css({backgroundImage: 'url(' + ...

What is the best way to toggle and slide two forms within a single page?

In this scenario, the goal is to display multiple forms on a single page, like a Login Form and Reset Password Form shown below. One form is initially hidden until a link is clicked, triggering an effect. The current setup includes a .toggle() effect that ...

There seems to be an issue with the functionality of the operators in the Calculator Javascript

I'm currently working on a Javascript calculator project for FreeCodeCamp and encountering an issue with the code. Whenever I input an operator like "-", "+", "x", etc., the numbers in the history section start repeating themselves. For example, if I ...

Validation in Angular10 Reactive Forms can be triggered on blur and submit events

Seeking to validate the form both on blur and when the submit button is pressed, but facing a limitation with the options available: updateOn: ['blur', 'submit'] The current choices are either updateOn: 'blur' or updateOn: &a ...

JavaScript is not designed to run a second time

Currently, I have a script set up using $(document).ready(). It works perfectly upon initial loading. However, I also need this script to execute whenever the user changes an HTML select control. Ideally, upon page load, I want the filter and sort functio ...

Issue with Javascript/Jquery functionality within a PHP script

I have been attempting to incorporate a multi-select feature (view at http://jsfiddle.net/eUDRV/318/) into my PHP webpage. While I am able to display the table as desired, pressing the buttons to move elements from one side to another does not trigger any ...