How do I center text between two floating divs (one floated left and one floated right) even when the window size

Can anyone help me figure out how to center a piece of text between two divs that are floated left and right?

See my code below:

<style type="text/css">
.left {
    float:left;
    padding-left:10px;
}
.right {
    float: right;
    padding-right:10px;
}

</style>
<div id="header">
    <div class="left">
        <p>Content on the left</p>
    </div>

    <span>Centered Text or Image/Logo</span>

    <div class="right">
        <p>Content on the right</p>
    </div>
</div>

Answer №1

Building the HTML structure:

<div id="header">
    <div class="left">
        <p>Content on the left</p>
    </div>
   <div class="center">
        <p>Content in the center</p>
    </div>
    <div class="right">
        <p>Content on the right</p>
    </div>
</div>

The corresponding CSS styles:

.left {
    float:left;    
    width:25%;
}
.right {
    float:left;    
    width:25%;
}
.center {
    float:left;  
    width:49%;
}

To see a live demo, follow this link: http://jsfiddle.net/cyR5W/

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

Tips for positioning a React component above another component

I am currently facing a challenge while working on a table with an expand more option to display additional details for each specific row. I have implemented a slider to facilitate the expansion of the table. Presently, my ExpandToggle component is embedde ...

Repetitive Anchor IDs and Web Standards Compliance

Today, I encountered the task of converting outdated attributes on a page to make it more XHTML friendly. This led me to consider the anchor tag and its usage: Initially, I had anchor tags in the form of <a name="someName"></a>. However, upon ...

Display or conceal 5 divs simultaneously

A while back, I stumbled upon this amazing code that has been incredibly helpful. However, I am unable to locate the original author (whoever you are, THANK YOU)... http://jsbin.com/amituh/11/ It's truly awesome, but I would like to add another butt ...

Styling with CSS: A guide to reducing paragraph margins within a div element

My current project involves using javascript to dynamically insert paragraphs inside a div element. Essentially, the script grabs the value entered into an input form when a button is clicked and adds it as a new paragraph within a specific div. However, I ...

ng-class not functioning properly when invoked

In my controller, I have the following function: $scope.menus = {}; $http.get('web/core/components/home/nav.json').success(function (data) { $scope.menus = data; $scope.validaMenu(); }).error(function () { console.log('ERRO') }); ...

Setting the height of a Bootstrap radio button

My Bootstrap radio buttons are set to a width of 200px. However, when the text inside the button exceeds this width, it wraps onto two lines leading to changes in button height. How can I ensure that all other buttons displayed scale to the same height? h ...

JavaScript file does not execute onload function

Whenever I try to execute the window.onload function from my .js file, it seems to not be firing as expected. <script type="text/javascript" src="{% static 'jsfile.js' %}"></script> window.onload = function() { alert(' ...

How to turn off a sticky header on Mobile using CSS

Below is the code I am using to create a fixed header on my website. <?php } ?> <header id="header" class="<?php if ( theme_option( THEME_OPTIONS, 'enable_header_fixed' ) == 'true' ) : ?> fixed_header <?php else : ?&g ...

Efficiently repositioning Kendo Mobile Buttongroup to a new row as needed

In my current project, there is a specific requirement to display three button groups in a row. If there are more than three buttons, they should move to the next row dynamically as the data will be fetched from the server. For reference, below is a sampl ...

reduce the width and adjust the top margin

Unique responsive design featuring a bold red column on the left and a sleek blue column on the right. The red column contains a striking black element with margin-top:30px As the website is resized, causing the blue column to shift below the red column, ...

Issue with Bootstrap4 toggler malfunctioning and not displaying links upon resizing the page

My Bootstrap navbar isn't displaying the links when I click the hamburger menu after resizing the window. Here's the code snippet: <div class="fixed-top"> <nav class="navbar navbar-dark navbar-expand-lg cusSticky&q ...

The Line Break <br/> element does not display properly in Java Servlet code

I recently developed a dynamic web application using servlet. The main component is a form on the index.html page that triggers the servlet's doGet method. Check out an excerpt of my code for the doGet Method below. String firstName = request.getParam ...

Why is the background image not loading properly on first hover with CSS?

Whenever we load a page with a large image set as the background for a div, there seems to be a delay in displaying the image when we hover over the div. Is there a solution to this issue? I would prefer not to use a sprite image because I need to make alt ...

What is the method for retrieving the font size of elements in the native view using appium?

Can the font size of text in the native view be retrieved using appium? I am aware of using driver.findElement(By.id("by-id")).getCssValue("font-size"); for web views. Is there a similar method for native views? ...

Automatically play the elements within a div using jQuery

I have various sections within different divs that I want to display without the need for manual clicking on tabs. While I've been able to toggle the visibility of these sections by clicking, I would prefer them to display automatically in a loop usin ...

The v-select menu in Vuetify conceals the text-field input

How can I prevent the menu from covering the input box in Vuetify version 2.3.18? I came across a potential solution here, but it didn't work for me: https://codepen.io/jrast/pen/NwMaZE?editors=1010 I also found an issue on the Vuetify github page t ...

Choose all of the IDs from various sections using Jquery

I am facing an issue with having 2 identical IDs inside 2 separate sections. When the button is clicked, I want it to select the ID within this section and apply a style, then also select the ID in the other section and apply that same style. The code sni ...

The request is unsuccessful due to the absence of the 'Access-Control-Allow-Origin' header

I've set up a form using Get Response (the email client) and I'm attempting to implement ajax in order to display a custom success or failure message upon submission. The code seems to be functioning correctly. However, as soon as I connect the a ...

The Autoprefixer script crashes with the error message: TypeError - Patterns can only be a string or an array of strings

After successfully installing autoprefixer and postcss-cli, I embarked on setting up a simple build process with NPM scripts using my command prompt and VS code. As someone with only 2 months of coding experience, I was following a tutorial on CSS/SASS top ...

What is the best way to apply a background color to text seamlessly? (Using HTML5 and CSS3)

<!-- 6장 연습문제 4 --> <html lang = "ko"> <head> <meta charset = "UTF-8"> <style> img{margin-left: auto; margin-right: auto; display: block;} .hyper{ text-decoration-line: ...