Steps for positioning an element to the left and center of a div

I'm having trouble aligning my two elements in a simple horizontal menu to the middle left. I want them to have a margin of 5px on the left and right sides. Here is a screenshot and CSS style: https://i.stack.imgur.com/vzO5D.png

.body_clr {
  width: 100%;
  height: 100%;
  display: block;
  background-color: black;
  height: 60px;
  
  /* ADDED to see the text */
  color:white;
}

.clear {
  width: 0;
  height: 0;
  padding: 0;
  margin: 0;
  display: block;
  visibility: hidden;
  overflow: hidden;
  font-size: 0;
  line-height: 0;
  clear: both;
}

.col1 {
  width: 33.33%;
  height: 100%;
  display: block;
  float: left;
  padding: 0 10px;
  box- sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
}

.ff {
  width: 100%;
  height: 60px;
  display: block;
  text-align: left;
  display: table- cell;
  vertical-align: middle;
}

.left {
  width: 100%;
  height: 60px;
  display: block;
  text-align: left !important;
  display: table-cell;
  vertical-align: middle;
  margin-left: 5px
}

.right {
  width: 100%;
  height: 60px;
  display: block;
  text-align: right;
  display: table-cell;
  vertical-align: middle;
  margin-right: 5px
}


}
<form id="form1" runat="server">
  <div class="body_clr">

    <div class=" col1">
      <div class="left">
        LinkButton
        <asp:LinkButton ID="LinkButton1" runat="server">Hello I am a link button
        </asp:LinkButton>
      </div>
    </div>
    <div class="col1">
      <div class="ff"></div>
    </div>
    <div class="col1">
      <div class="right">
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label> |
        <asp:Button ID="btnSignout" runat="server" Text="Sign out" BackColor="Black" ForeColor="White" OnClick="btnSignout_Click" />
      </div>
    </div>
  </div>
</form>

Answer №1

To align text in the center, you have a few options:

    <div class="outer-wrap">
       <div class="outer-wrap-inner">
          <a href="#" title="">Text Center</a> 
          <a href="#" title="">Text Center</a> 
         </div>
    </div>
.outer-wrap{ height: 100% ; width: 100% ; position: relative; }
.outer-wrap .outer-wrap-inner{ text-align: center; position: absolute; left: 50%; top: 50%; -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%); }
.outer-wrap .outer-wrap-inner a{ margin: 0 5px; }

Alternatively,

You can also utilize bootstrap classes for centering:

<div class="center-outer-wrap d-flex justify-content-center align-items-center">
    <a href="#" title="">Text Center</a> 
    <a href="#" title="">Text Center</a> 
</div>
.center-outer-wrap{ width: 100%; height: 100%; }
.center-outer-wrap a{ margin: 0 5px; }

Answer №2

One way to achieve this is by utilizing flexbox properties like space between for elements and align-items for the center element

    display: flex;
    justify-content: space-around;
    align-items: center;

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

What could be the reason that the painting application is not functioning properly on mobile devices?

I am facing an issue with my painting app where it works perfectly on desktop browsers but fails to function on mobile devices. I tried adding event listeners for mobile events, which are understood by mobile devices, but unfortunately, that did not solve ...

Attempting to eliminate the parent container of a slide generated by the Slick Slider Plugin

I have developed a filter mechanism that hides specific classes within a slick slider based on the data-tag associated with the objects and the value of checkboxes. However, when these classes are hidden, they still occupy space because I should be hiding ...

Creating a menu category for a restaurant using CSS

I'm trying to set up a menu with categories like this: enter image description here However, my result ends up looking like this: enter image description here The description section keeps stacking on top of the photo section; it's strange beca ...

After parsing through the HTML content and displaying itynamic spacing will be added

My index.php file contains code that will echo a string created by a function in functions.php using a returned .html file. Here is the code in index.php: require_once('functions.php'); echo create_page(); In functions.php, there is a functio ...

Div refuses to clear floats

Working on an app at and encountering an issue with the main container not clearing floats, causing overflow on the content. Attempted to use this CSS: .clearfix:after { content:""; display: table; clear: both; } Added the class to the main ...

Unexpected border-bottom styling issue observed on adjacent div elements

This is my unique code: <!DOCTYPE html> <html> <head> <style> </style> </head> <body> <div style="border-bottom:1px solid black"> <div style="width=50%;float:left">A new paragraph with u ...

What is the best method for adding space between elements in flexbox layout?

I am struggling to align the child flexboxes within my parent flexbox in a single row, both vertically and horizontally centered. I want to add space between them using the gap property in CSS, but the images and embedded videos inside these child flexboxe ...

Tips on extracting values from HTML utilizing a CSS selector in instances where only class and style attributes are present. The class in question is generic and may be utilized elsewhere as well

''' 29/11/2021 ''' I have a code snippet that retrieves dates from a table on a webpage, but it also fetches other values along with the date. I am looking for a way to extract just the d ...

Flask: BadRequestKeyError: 400 Bad Request: The server was unable to comprehend the request sent by the browser (or proxy)

When I try to link to the edit view in my birthday reminder app, I keep getting a key error. The get_Gift function returns an object with the key field present and the HTML form has all the necessary fields, so I'm not sure why this error is occurring ...

The position of the scroll bar remains consistent as you navigate between different websites

Is it possible for me to click on a link within my HTML website and have the other website load with me in the exact same position? For example, if I'm halfway down a webpage and click a link, can I be taken to that same point on the new page? If so, ...

Is there a way to ensure that my text is centered on top of an image while maintaining responsiveness?

I'm trying to make the text adjust its center to the height of an image that changes size when the page is resized. Here's what I have so far: HTML <section id="eyeCatcher"> <div id="catchContainer" > <div id="eyeCatchQ ...

Tips for sending several values using multiple select input

I am seeking advice on the best way to insert multiple values into a table using a multiple select input that includes more than one value. Would it be better to use a single value separated by "|", or to use data attributes like data-id, data-price, etc? ...

Can the placement and dimensions of the audio controls be customized?

I am working on an audio tag that initially hides the controls, and only shows them when a user clicks on a specific link. Here is the code snippet: var audio = document.getElementById(audioId); if (audio.paused) { audio.src = clip; audio.play(); ...

Unable to delete borders within the container

Is there a way to eliminate the borders within this container? Visit this link for reference. I've tried using firebug but I can't seem to locate it... Appreciate any assistance you can provide. Thank you! ...

Positioning the jQuery mobile navBar to be fixed on iOS 4 devices

Currently working on a mobile app with jquery using iOS4 and iOS5 compatibility as the final hurdle. While fixing the navigation bar is simple on iOS5 with position:fixed, it's not as straightforward on iOS4! I've experimented with various soluti ...

Applying custom styles to the initial 5 elements post clicking the button with Jquery

I have a set of HTML codes containing multiple buttons. <div class="main"> <div class="button hide">1</div> <div class="button hide">2</div> <div class="button hide">3</div> <div class="button h ...

Is it possible to swap images by clicking on them?

Let's say I'm working with 3 images. Image A, B and C. A is the main image initially. If I click on image B, it will become the main image and image A will take its place in the old position. The same condition applies when B is the main image a ...

What is the best way to eliminate the space between columns?

I have a simple structure on BootStrap. <div class="container"> <div class="row"> <div class="col-md-4 blue-section" ><p>Some content</p></div> <div class="col-md-4 red-section"><p>Some content&l ...

The ng-repeat function is unable to fetch data from a JSON file

Within my AngularJS framework template, I have the following snippet of html code: <ul class="sb-parentlist"> <h1 class={{headerClass}}> Popular</h1><div data-ng-repeat="data in data track by $index"> <li> ...

Show a pop-up when hovering over each row of a Material UI table and address the problem with the box

Working on a react app using React v18.2 and Material UI V5, I successfully created a table with MUI Table component where I want to display a popover for each row when hovered over. To achieve this, I added a simple popover component to the last cell of ...