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>

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

Is there a way to achieve a flex layout without having to modify the HTML structure?

I am working on achieving a specific layout using CSS: https://i.stack.imgur.com/xg7ZA.png This is the HTML structure I have and it cannot be altered, along with what I have managed to add with CSS. It's almost there but missing something: .conta ...

Perform the subtraction operation on two boolean values using Typescript

I'm working with an array: main = [{ data: x, numberField: 1; }, { data: y, numberField: 2; }, { data: x, numberField: 3; }, { data: z, numberField: 4; }, { data: ...

Learn how to showcase a modal pop-up in AngularJS by utilizing the ng-if directive

Hello, I am new to working with AngularJS. My question is how can I display a modal pop-up box when the ng-if statement evaluates to false? Can you please provide guidance on how to solve this issue? Here is an example of the code snippet in HTML: <di ...

Interaction issue with Material UI and React tabs: hovering fails to open and close tabs correctly

I am currently immersed in a project that involves React and Material UI. My goal is to create tabs that trigger a menu upon hovering, but I seem to be facing some challenges with this functionality. That's why I'm reaching out here for assistanc ...

``There is an issue with the onsubmit property that prevents the opening of

I have encountered an issue with my forms that has me stumped. Despite searching online for help, I can't seem to figure out why my implementation is not working as intended. The concept is straightforward. I've embedded a form within a JSP page ...

What is the process of overriding methods in a function-based component in React?

Overriding in a parent component works when it is a class-based component // Parent Button Class class Button extends React.Component { createLabel = () => { return <span>{this.props.label}</span>; }; render() { return <butt ...

Strange issue encountered when utilizing Worklight along with XSL transformation on a JSON response

I'm facing an unusual issue that I can't seem to resolve. Here is an example of a JSON response that I am dealing with. "values": [ { "time": "2014-02-26T09:01:00+01:00", "data": [ "A", "B" ] }, // additional objec ...

What is the best way to eliminate the input border?

click here for image I'm currently working on designing a straightforward login page. However, I've noticed that there are black borders around the input fields. Can anyone help with how to remove these borders? ...

Struggling with getting the JavaScript, scss, and CSS television animation to turn on and off properly? Seeking assistance to troubleshoot this

After finding this javascript code on Codepen and seeing that it worked perfectly in the console there, I tried to run it on my computer with jQuery but it didn't work outside of Codepen. Even when attempting to use it on JSfiddle or compile the SCSS ...

What could be the reason that Ng Repeat fails to work when a button is triggered from a separate form

I have an HTML table that includes an ng repeat directive and two buttons. The first button opens a modal with a form to create a new user. When I click save, it adds the new user to the list. The second button is within the same form and also adds a user. ...

Is there a way to retrieve a single value using AJAX instead of returning the entire HTML page?

(edited after initial version) I'm facing an issue where my AJAX call is returning the header.php page instead of just the $result value which should be 0 or 1. The AJAX function calls generateTicket.php, where I want to generate tickets only if no o ...

Exploring Angular modules has shed light on a certain behavior that has left me puzzled - specifically, when diving into JavaScript code that includes the

I am currently working with angularjs version 1.4.3 and I find myself puzzled by a certain segment of code in the Jasmine Spec Runner that has been generated. Upon generation, Jasmine (using ChutzPath) creates this particular piece of code: (function ...

Utilizing the controller specified in the template that has been included

Within this snippet of code, I am attempting to utilize a controller named FooCtrl that is defined in the included template app/foo.html, using the directive common.script. angular.module('common.script', []).directive('script', func ...

Creating a URL using Form Fields with Javascript or jQuery - Reg

Creating a Custom URL with Form Fields using JavaScript or jQuery I am looking to generate an external link by incorporating a form with a dynamic variable as shown below: (Where 2500 can be customized based on user input) The final URL will be display ...

Looking for a JavaScript function that can utilize AJAX to execute PHP code and display the PHP output on the webpage

I've been trying to use JavaScript to execute some PHP code and then display the results on the page. I came across a piece of code that achieves this using ajax and by placing the PHP code in an external file. However, the code I found seems to show ...

What is causing my vue.js table to not display properly?

Struggling to render a table using vue.js? You're not alone. Many developers face challenges when trying to use v-for to iterate through data and display it in a table format. It can be frustrating when everything seems fine in the console, but the ta ...

using reactjs to dynamically render elements based on the selected condition in a select box

Is there a way to dynamically change an element based on the selected value of a dropdown in React? I'm looking for help with rendering conditions. Here's a snippet of my code: <Col span={12}> <Form.Item label='Qu ...

Tips for Aligning Form Elements in the Middle using Bootstrap

What could be the issue? I can clearly see the container border, indicating the space available for my work. However, when I insert the row (div) and offset (div), the content gets left-justified. <div id="page" class="container" style="border:soli ...

Utilize text wrapping to ensure a fixed maximum height for content display

I am in need of a div that contains text spanning multiple lines, with both a fixed width and a maximum height. Currently, I have applied the CSS property overflow: hidden;. However, my issue arises when the last line of text exceeds the maximum height of ...

New methods for Sequelize ES6 models do not currently exist

Encountering issues while using Sequelize JS v4 with ES6 classes, I'm facing difficulty with the execution of instance methods. Despite being defined in the code, these methods appear to be non-existent. For instance - Model File 'use strict&a ...