How can I make inline-block items align with the top of the parent element?

Take a look at: http://jsfiddle.net/kdcmq/86/

#parent {
position: relative;
width: 500px;
height: 500px;
background: red;    
}

#child {
display:inline-block;
width: 100px;
height: 100px;
background: blue;
top: 0;
left: 100%    
}

Is it possible to align the smaller blue elements right below the border of the parent div so they start when the bigger one starts?

Your help is much appreciated!

Answer №2

To achieve the desired layout, ensure that #child has the position: absolute property applied. It is recommended to use left: 0 instead of using a percentage value.

Additionally, there is no necessity for #child to have the inline-block display; consider changing it to block.

By the way, this information directly addresses your query. Whether the implementation aligns with best practices is open for further discussion...

Answer №3

Here are several issues that need to be addressed:

  1. You should consider changing the 'child' elements from id to class for consistency.
  2. For the top and left attributes to work properly, ensure the element has position:absolute set.
  3. To eliminate spacing between inline-block elements, refer to this helpful resource: http://css-tricks.com/fighting-the-space-between-inline-block-elements/

Answer №4

Try out floating your elements for a different layout

.child {
float:left;
width: 100px;
height: 100px;
margin:0 10px 0 0;
background: blue;   
}

Check it out here!

(Updated duplicate IDs to classes)

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 is the best way to emphasize a div depending on a query outcome?

A new application is in the works for a gaming project. This app is designed to display the location of a specific monster, utilizing a database containing information about monsters and their corresponding maps. Currently, the application functions almos ...

What is the best method for incorporating meta data, titles, and other information at dynamic pages using Node.js and Express?

I am currently exploring methods to efficiently pass data to the html head of my project. I require a custom title, meta description, and other elements for each page within my website. Upon initial thought, one method that comes to mind is passing the da ...

Tips for including multiple spaces within a cell of a table

I've come across an issue while working on a table and attempting to insert text with multiple spaces. For example, I want to add the text HELLO<1stSPACE><2ndSPACE>WORLD. However, when I enter it as HELLO WORLD, it only displays with a si ...

Show a list of groups using JSON information

Looking to showcase a list of individuals using JSON data structures? <pre> <ul class="list-group"> <span class="badge badge-primary badge-pill">A</span> <li class="list-group-item d-flex justify-content-between align ...

How to Customize the Size and Color of secureTextEntry Inputs in React Native

When it comes to styling a password input like the one below: <TextInput name="Password" type="password" mode="outline" secureTextEntry={true} style={styles.inputStyle} autoCapitalize="none" autoFocus={true} /> I also ap ...

The CSS dropdown navigation bar designed for mobile devices functions properly, however, it is not visible on iPhones

After building this website from scratch using only HTML and CSS, I encountered an issue with the dropdown menu not appearing on iPhones. Despite testing it extensively across different browsers and devices, the problem persists on Apple products. While i ...

Implementing text formatting for user comments within my NodeJS application

Is there a way to incorporate an interactive text formatting feature into the comment form on my nodejs app? After searching for options online, I couldn't find exactly what I was looking for. Can anyone point me in the right direction? I'm refe ...

What is the method for making text uppercase within the Heading feature of Grommet?

Currently implementing grommet in my React project and exploring how to capitalize text within a few <Heading /> components. ...

Why is it proving difficult to eliminate margin and padding from the top of the page?

Struggling to remove padding or margin from the top, I attempted to adjust the main container settings: margin-top:0px !important; padding-top:0px !important; Unfortunately, this did not have the desired effect. The code is too lengthy to include in thi ...

How to align text vertically in columns by utilizing the column-count CSS property?

Utilizing the CSS column-count property, I have divided text into four columns on an HTML page. The issue is that the first column always seems to be slightly lower than the other three columns. To illustrate the problem in a straightforward manner, chec ...

Tips for implementing a toggle feature for an ion-card element

I am looking to create a toggle effect on ion-card, where clicking on the card will highlight it until either unclicked or another card is clicked. Similar to this - https://i.sstatic.net/MH5WA.png How can I achieve this effect on ion-card? Here is my H ...

Designing a split navigation bar in Django using unique styling for each section (HTML, CSS, and Javascript)

In my endeavor to design a search button within a responsive navigation bar, I encountered an issue. The navigation bar contains a media query in the CSS file that adjusts it to a dropdown list based on the reader's screen dimensions. Here is the HTM ...

How can I keep the cursor from automatically moving to the beginning of an input field when the type changes?

Currently in the process of creating a Password field that allows users to hide or display their password in React/Ionic. I am aiming to maintain focus on the password field when switching the input type, similar to how it is done on the PayPal Login page ...

Customize the appearance of the bootstrap nav-bar by assigning unique background colors to each dropdown menu

I'm looking to set unique background colors for each dropdown in a Bootstrap nav-bar using CSS. .mynavbar .dropdown ul.dropdown-menu:nth-child(1) { background-color: #59b057; } .mynavbar .dropdown ul.dropdown-menu:nth-child(2) { background-col ...

What is the best way to extract data from various HTML files using RVEST and save it into an Excel spreadsheet?

I am struggling to find a solution for my current problem as I am not fluent in R. My challenge is working with 800 html files and accessing all the h2 elements within each file. Currently, I have managed to do this with individual website URLs using the ...

I would like the background image to perfectly fit the dimensions of the parent container

https://i.sstatic.net/PlCYU.png Is there a way to prevent the background image from overflowing and causing a horizontal scroll bar to appear? The layout of the page consists of two columns, with each column taking up 50% of the width. The left column con ...

Stop the window from scrolling downwards

My website has a full-width slider as the main background and I am using jQuery to show or hide divs depending on the clicked link. However, when some sections are longer than the initial view, my page automatically scrolls to the bottom after a click. How ...

Looking to conceal content on the navbar background using Bootstrap

From the image above, it is apparent that the text is appearing behind the navigation bar. I'm seeking guidance on how to conceal this text from the navbar when scrolling up the content. Should I create a custom CSS class with properties, or is there ...

Unable to access /Login or unable to submit /Login later on

Can someone please assist me? I am trying to create and submit an HTML form using express but keep encountering the error "Cannot GET /Login" or later on "Cannot POST /Login" <form name="myForm" onsubmit="return validateForm()" metho ...

Perform basic arithmetic operations on the output of SQL queries or on information stored in a datatable

Consider a scenario where a query yields results like the following... **TYPE** **TOTAL** A 2 B 4 Now, if you want to perform calculations such as A/(A+B) -> 2/(2+4) and display the result on your website, would it b ...