Tips for creating a condensed header

As a newcomer to HTML, I am facing challenges in creating a simple header similar to the one displayed on this website or the example in the image below. Below is the snippet of HTML that I have attempted:

<header class="header">
  <div class="dropdown_menu">
    <div class="small_header">
      <ul id="menu-small-menu" class="small_menu">
        <li id="menu-item-10429" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-10429">12 Royal Street California USA</li>
        <li id="menu-item-6305" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-6305">001-122-134-555</li>
        <li id="menu-item-6211" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-6211"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="82e1edecf6e3e1f6c2e6edefe3ebecace1edef">[email protected]</a></li>
      </ul>
    </div>
  </div>
</header>

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

Answer №1

Hello and welcome to Stack Overflow! In order for us to assist you better, please provide a Minimal, Reproducible Example of the issue you are facing. Additionally, make sure to specify exactly what difficulties you are encountering. If you simply wish to create a .smallHeader row, you can use the following basic CSS:

.smallHeader {
    font-size: small; /* smaller compared to 'medium' (default size is around 16px) */
    line-height: 1.2; /* standard default value that also vertically centers text */
                      /* Increasing this value will add top/bottom space between lines of text or use 'padding' */

Refer to MDN: font-size, MDN: line-height, and MDN: padding for more information.

It's important to note that using `padding` for top/bottom spacing might be preferred when dealing with long texts as each wrapped line maintains the same `line-height` which may not always be desired. This ensures proper spacing around the block of text.

The provided CSS snippet gives an example demonstrating the difference between `line-height` and `padding`. To see the effect, run the snippet in 'Full page view' and resize your browser accordingly...

ul,li {
   padding: 0; list-style-type: none /* override default styles */
}
ul {
    margin: 0 /* ditto */
}

.smallHeader {
    font-size: small; 
    line-height: 1.6; 

    /* eye-candy styling */
    background-color: grey; color: white;
    text-align: center;
}
li.menu-item {
    display: inline; 

    /* eye-candy styling */
    padding: 0 1em; 
}

.bigHeader {
    font-size: x-large; 
    padding: 1em 0; 

/* eye-candy styling */
    background-color: black; color: white;
    text-align: center;
}

[class^="test"] { background-color: rgba(0,0,0,.1) } 

.test-lh { line-height: 1.5em }
.test-pd { padding: 1.5em }
<header>
 <div class="smallHeader"> 
    <ul id="menu-small-menu" class="small_menu">
        <li id="menu-item-10429" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-10429">12 Royal Street California USA</li>
        <li id="menu-item-6305" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-6305">001-122-134-555</li>
        <li id="menu-item-6211" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-6211"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2f4c40415b4e4c5b6f4b40424e4641014c4042">[email protected]</a></li>
      </ul>
 </div>
 <div class="bigHeader">extra large text</div>
</header>

<div class="test-lh">
    <p>Lorem ipsum dolor sit amet, exerci dolorem est ad. Sumo rebum prompta vim ad. Legendos expetendis id sed....
</div>
<div class="test-pd">
    <p>Lorem ipsum dolor sit amet, exerci dolorem est ad. Sumo rebum prompta vim ad. Legendos expetendis id sed...
</div>

Answer №2

If you want to easily achieve this layout, you can utilize the power of display:grid. For instance, if your HTML file looks something like this;

HTML

<header>
 <div class="smallHeader"> 
    <ul id="menu-small-menu" class="small_menu">
        <li id="menu-item-10429" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-10429">12 Royal Street California USA</li>
        <li id="menu-item-6305" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-6305">001-122-134-555</li>
        <li id="menu-item-6211" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-6211"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8bbb7b6acb9bbac98bcb7b5b9b1b6f6bbb7b5">[email protected]</a></li>
      </ul>
 </div>
 <div class="bigHeader"></div>
</header>

CSS

header{
display:grid;
grid-template-columns: auto;
}

This code snippet will help you create a grid structure inside your header where each div occupies one row within the grid. Additionally, you can customize the height and color of these divs as per your requirement.

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

unable to render a vector layer in openlayers 6

Currently, I am facing an issue with displaying a vector layer on an openlayers map using the source of local geojson and gpx files in my Vuejs project. Unfortunately, even when testing outside of Vue.js, the vector layer is not being displayed. Here is t ...

Retrieve the designated element from an array of JSON data in SPLUNK

As a newcomer to the world of Splunk, I am facing a challenge with handling JSON data. Here is an example of the JSON data I am working with: "request": { "headers": [ { "name": "x-real-ip", "value": "10.31.68.186" ...

Creating JSON data that is completely valid using client-side JavaScript

I've been working on creating a JSON explorer/editor. Successfully managed to parse the initial JSON into the div and customize the formatting. Here's the function I utilize to loop through the initial JSON: _iterate(_tab, raw_json){ var tab ...

Employing PHP conditions alongside JavaScript to conceal the div elements

I have been struggling with a problem for the past few hours and still haven't found a solution. I am new to php. What I am trying to achieve is to display and hide a div based on a PHP condition. Here is the scenario: Please note: By default, the DI ...

Bootstrap alert JS refuses to slide down

Here is the JavaScript code to make a blue bar slide down on click: $('#comment').click(function(e) { e.preventDefault(); $('#comment').slideDown(); }); ...

Analyzing and tallying JSON attributes using JavaScript

I have a JSON object with items that I need to analyze in JavaScript. When I view the JSON in the console, there is an element called items that contains an array of relevant information. console.log(json) {current_page: 1, per_page: 100, total_entries: ...

Utilizing $resource within a promise sequence to correct the deferred anti-pattern

One challenge I encountered was that when making multiple nearly simultaneous calls to a service method that retrieves a list of project types using $resource, each call generated a new request instead of utilizing the same response/promise/data. After doi ...

Change from using fs.writeFileSync to fs.writeFile

I have a question about changing fs.writeFileSync to fs.writeFile const users = { "(user id)": { "balance": 28, "lastClaim": 1612012406047, "lastWork": 1612013463181, "workersCount": 1, ...

Pair of dimensions painting with d3 version 4

I am having trouble converting my code from d3 v3 to d3 v4 Below is the original code snippet: var brush = d3.svg.brush() .x(x) .y(y) .on("brushstart", brushstart) .on("brush", brushmove) .on("brushend", brushend); However ...

Modifying a Nested Component with react-icons

As I work on creating a rating component that utilizes react-icons to display icons, I have encountered an interesting challenge. Currently, I am using the FaStarhalf icon which represents a pre-filled half star that can be flipped to give the appearance o ...

How to show or hide a textbox in JavaScript?

Within my user control, there is a panel with two controls: ddlType, a drop-down list, and txtOthers, a text box. Initially, txtOthers is set to be invisible. The goal is for txtOthers to become visible when the user selects an option in ddlType that corr ...

How to declare a variable using new String() and s = '' in Typescript/Javascript

What is the correct way to declare an array of characters or a string in JavaScript? Is there a distinction between an array of characters and a string? let operators = new String(); or let operators = ''; ...

Is it possible to create a masonry-style layout with two columns that is responsive without

Is there a way to organize multiple divs of varying heights into two columns that display immediately one after the other, without relying on JavaScript or libraries like packery or masonry? I've experimented with using display: inline-block in this ...

"Enhance your website with the powerful combination of SweetAlert

I'm having trouble getting my ajax delete function to work with SweetAlert. I can't seem to find the error in my code. Can someone help me figure out how to fix it? function deletei(){ swal({ title: 'Are you sure?', ...

Bootstrap 5's ScrollSpy functionality seems to be malfunctioning

I attempted to implement the scroll-spy feature of Bootstrap 5 in order to highlight the corresponding navbar item as active while scrolling through different sections of my HTML page. However, I encountered an issue where the navigation-link item would be ...

What is the best way to create a sticky/fixed navbar that conceals the div above it while scrolling on the page?

When I am at the top of the page, I want to display the phone number and email above the navigation bar. However, as soon as I start scrolling down, I want the phone number and email to disappear and only show the navigation bar. I have attempted using fix ...

Oops! An issue has occurred where I am unable to access certain properties (specifically 'Symbol(__APOLLO_CONTEXT__)') while utilizing the Apollo provider

When attempting to implement a query in my upcoming app, I encountered an error that reads: Error: Cannot read properties of undefined (reading 'Symbol(APOLLO_CONTEXT)') This is the setup of my Apollo client: import { ApolloClient, InMemoryCache ...

The onCall function in Firebase's realtime database does not provide a response data object when executing the remove() operation

When using onCall to perform a remove operation from a realtime database, I encountered an issue where the response only returned null instead of the expected data object. Strangely, I have used onCall for other operations like update and always received a ...

Having trouble with getting the second JavaScript function to function properly?

I am facing an issue with the second JavaScript function. When I click the 'Send Mail' button, it should call the second function and pass it two values. However, the href line (second last line in the first function) is not rendering correctly. ...

The AXIOS method in Express.js is designed to return a Promise object that may contain an

I am currently learning ExpressJS and Axios I have created a folder named utils and placed the axios.js file const axios = require('axios'); loadDataPesan=async function(opts){ axios.get('localhost/getData', { params ...