How to align multiple divs in the center on a single row?

I have created a series of navigational buttons for my website using Photoshop, but I'm facing an issue with centralizing them. When applying various CSS margin or float statements to centralize the buttons, they end up arranged in a 1 x 4 column instead of all on the same row (I have 4 buttons).

The banner on my site is centrally positioned, and I want the buttons to be aligned directly below it. Below is the code I am currently working with:

HTML

<div id="home" class="home">
<img title="Home" src="images/images/home.jpg">
</div>

<div id="iwb" class="iwb" align="center;">
<img title="IWB" src="images/images/iwb.jpg">
</div>

<div id="presentations" class="presentations">
<img title="Presentations" src="images/images/presentations.jpg">
</div>

<div id="internet" class="internet">
<img title="Internet" src="images/images/net.jpg">
</div>

CSS

.home {
display: block;
width: 188px;
height: 50px;
background: url(images/images/home.jpg) bottom;
text-indent: -99999px;
}

.home:hover {
background-position: 0 0;
}

.iwb {
display: block;
width: 188px;
height: 50px;
background: url(images/images/iwb.jpg) bottom;
text-indent: -99999px;
}

.iwb:hover {
background-position: 0 0;
}

.presentations {
display: block;
width: 188px;
height: 50px;
background: url(images/images/presentations.jpg) bottom;
text-indent: -99999px;
}
.presentations:hover {
background-position: 0 0;
}

.internet {
display: block;
width: 188px;
height: 50px;
background: url(images/images/net.jpg) bottom;
text-indent: -99999px;
}
.internet:hover {
background-position: 0 0;
}

How can I center them all in one row directly beneath my header? I want there to be no vertical white space between my header and navigation buttons if possible.

Thank you.

Answer â„–1

To ensure they appear in the same row, consider using display: inline-block or float: left instead of display : block.

Refer to examples here for using inline-block.

UPDATE:

When utilizing display:inline-block, remember to include font-size:0 as shown below.

http://jsfiddle.net/xXVCg/1/

If you prefer not to use font-size:0, then consider using float:left as demonstrated below.

http://jsfiddle.net/xXVCg/

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

An angular component that is functioning properly when connected to a live server, however, it is experiencing issues when trying to run `

I tried integrating versitka into my Angular component by placing the version HTML file and all necessary assets in the appropriate directories. However, when I run ng serve, only the HTML file seems to be working, while the CSS and images fail to load. I ...

Safari iOS does not properly support responsive images when using srcset and sizes

I am facing an issue with the following code snippet: <img src="/img/footer/logo_white.png?v=2.0" srcset="/img/footer/logo_white.png?v=2.0 1x, /img/footer/logo_white2x.png?v=2.0 2x" > This ...

What is the reason behind genNewColor function's malfunction?

I'm having trouble with this code that is supposed to generate a random color. The CSS formatting works perfectly, but I suspect there might be an issue with the function itself. When I try to run the code, it doesn't produce any error messages â ...

Struggling to align rotated text within the Bootstrap 4 Grid system

I have been working on a grid layout using Bootstrap 4's Grid system, and I am aiming for a design similar to the following: https://i.sstatic.net/sU7kV.png While I have made significant progress and got almost 100% of it complete, I am facing an is ...

Interactive Javascript dropdown helper on change

I am currently experimenting with a JavaScript onchange method, as I am relatively new to coding. My goal is that when I select "ID Type," the input text should change to "passport," and when I select "South African ID," the input should switch to "South ...

Create a scrollable horizontal list of items

I am encountering an issue with my mat chip list in Angular Material. I have a mat chip list filled with mat-chips that I want to display in a single row. If there are more items than can fit on the screen, I would like the area to be scrollable horizonta ...

Tips for limiting access to data from various tabs when the web page first loads

div#tabCtrl div#page1 This table showcases the information for tab1 div#page2 This table showcases the information for tab2 ...

difficulties arise when adjusting font size in html and css

When I first created an all HTML/CSS website, I used clickable images as a menu that scaled perfectly on all monitors and browsers. Now, for my new project, I wanted to use a background image for the menu with hyperlinked text on top. I thought setting the ...

Is it feasible to utilize VAST for delivering HLS streams? Can m3u8 files be incorporated into VAST tags for delivery?

We are integrating a video player that supports VAST pre-roll, mid-roll, and post-roll video ads. I'm wondering if it's feasible to include m3u8 files in VAST tags? I've reviewed the vast specification and examples, but haven't come ac ...

CSS transition effect to show content: display: block

After experimenting with different styles for another element, I added padding, height, and opacity to the div. However, there seems to be no transition effect with the current CSS code. Can anyone explain why? When a button is clicked, the class .show is ...

What could be causing issues with mysqli connection to the database?

Here is the content of my connect.php file: $mysql_hostname = "localhost"; $mysql_username = "root"; $mysql_password = "xxxxxxxx"; $mysql_database = "marrybrown_clean"; $bd = mysqli_connect ($mysql_hostname, $mysql_username, $mysql_password) or die (&apos ...

Guide to extend the width of h1 container to fill the entire parent div

Here is a snippet of code showcasing parent and child elements along with their current styling main #main-content-wrapper div { padding: 0; margin: 0; } img { border-radius: 8px; } .overlay1 { position: absolute; top: 0; right: .1px; bo ...

Issues arise when using ng-repeat in conjunction with ng-click

I am facing some new challenges in my spa project with angularjs. This is the HTML snippet causing issues: <a ng-repeat="friend in chat.friendlist" ng-click="loadChat('{{friend.friend_username}}')" data-toggle="modal" data-target="#chat" d ...

Glitch found in Safari involving innerText of elements

Hey everyone, I posted this question not too long ago but now I have some images to share regarding the issue with Safari. When checking the console in Safari, the following text is displayed: <div id="rot3posDisp" class="rotDisp">C</div> Ho ...

Tips on how to horizontally center align a div when using the flex direction column technique

In my design, there is a container that consists of both a table and a div. The div has its display property set to flex with the flex-direction as column. I am trying to horizontally center align the div within the container. Below is the code snippet: ...

Unable to see Bootstrap 5.2 Modals in action with documentation demo

Here is an example that I copied and pasted from the documentation on https://getbootstrap.com/docs/5.2/components/modal/: <!-- Button trigger modal --> <button type="button" class="btn btn-primary" data-bs-toggle="modal&q ...

The Gulp task is not being recognized when I open the project in Visual Studio Code

Whenever I open gulp, I encounter an error related to minifying css and js files using gulp tasks. Despite my efforts to find a solution, the problem remains unresolved. Error Message: assert.js:374 throw err; ^ AssertionError [ERR_ASSERTION]: Task fu ...

jQuery Hierarchical Select Menu

I am working on creating a complex hierarchy of dropdown options. The goal is to display only the options that are related to the previously selected choice. For example, if "Device Groups" is selected, the second dropdown will default to "Group Details" a ...

Using CSS to create hover effects for specific classes of elements

Is there a way to make the button change color on hover when hovering over anywhere in the navigation bar (.topNav) instead of just when hovering over the individual button elements (.top, .middle, .bottom classes)? I tried using span to achieve this, but ...

Tips for creating a full-screen asp website

I'm looking to develop a fresh website that showcases all pages in full screen mode, with the ability for users to access the desktop view only by entering a specific password. My initial thought is to design it as a single page, but I'm open to ...