Items on the list will not be displayed side by side

I am facing an issue for which I cannot find a solution.

While creating a Drupal site, I am trying to arrange these list items side by side. Each item has a width of 45%, so theoretically it should be possible to have 2 items next to each other. However, I am unable to figure out how to do it.

I have attempted using display:inline and inline-block on multiple ULs and LIs, but nothing seems to change.

Can anyone advise me on what steps I should take?

Answer №1

To achieve the desired layout, simply utilize the float property in your CSS:

ul {
  width: 940px;
}
li {
  margin: 6px;
  float: left;
  list-style: none;
}
.clearfix::after {
  content: '';
  display: table;
  clear: both;
}
<ul>
  <li>
    <img src="//lorempicsum.com/futurama/450/200/2" alt="" />
  </li>
  <li>
    <img src="//lorempicsum.com/futurama/450/200/2" alt="" />
  </li>
  <li>
    <img src="//lorempicsum.com/futurama/450/200/2" alt="" />
  </li>
  <li class="clearfix">
    <img src="//lorempicsum.com/futurama/450/200/2" alt="" />
  </li>
</ul>

Answer №2

Without providing any code, it can be challenging to identify where the issue lies.

One possibility is that you haven't changed the display type, resulting in the elements remaining as blocks. In this case, even if the width is adjusted, each element will still be displayed on its own row.

To have the list items appear next to each other, consider using float or display:inline;.

For a demonstration of various methods and why some may not work, check out this fiddle.

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

Ensuring that the text snippet is positioned centrally inside a container

I am currently developing a dynamic slideshow feature. My challenge is to ensure that any text I input dynamically is centered both horizontally and vertically within a designated box. My current code snippet looks like this: HTML <body> < ...

Can you explain the significance of the "row" class in Bootstrap, how it differs from containers, and how it interacts with col-***-*?

I've been browsing through the guide found at http://getbootstrap.com/css/ and I'm having trouble grasping the purpose of the "row" class. I experimented with some examples provided in the guide like: <div class="row"> <div class="c ...

Designing a popup using Angular, CSS, and Javascript that is capable of escaping the limitations of its parent div

I'm currently working on an Angular project that involves components nested within other components. My goal is to create a popup component that maintains the same size and position, regardless of where it's triggered from. One suggestion I rece ...

Overlay one image on top of another

Recently, I've been working on this code snippet. I am attempting to center the profile picture even when the screen width is reduced. The issue lies with using position:absolute, preventing margins:auto from functioning properly. As a workaround, I ...

Tips for creating a vintage, weathered font appearance on a web browser

Is it possible to create unique, randomly outwashed letters using a standard font? Instead of relying on pre-designed outwashed fonts available at , I am interested in achieving the same effect with a regular font that appears washed out when displayed in ...

Is it possible to use a shell script to replace the external CSS file link in an HTML file with the actual content of the CSS file

Seeking a solution for replacing external CSS and JS file links in an HTML document with the actual content of these files. The current structure of the HTML file is as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C ...

css - adjust flex box to cover half of the screen and increase its size

I'm having trouble getting my CSS Flex-box to stretch the full height of the right side of the screen from the center. I want it to cover the entire right half of the screen at full height. https://www.cajsoft.co.uk/test/visitor2.html Any help with m ...

Universal CSS styling for scrollbar design across platforms

I'm feeling extremely frustrated right now because I can't seem to create a basic scroll bar with a specific color and thickness that will display properly on various web browsers and smartphones. Are there any resources available to help me fig ...

The Typewriter Effect does not appear alongside the heading

For my portfolio website, I am using React to create a unique typewriter effect showcasing some of my hobbies. Currently, the code is set up like this: "I like to" [hobbies] However, I want it to display like this: "I like to" [h ...

Does the color of <hr> tags in Bootstrap 5 look different?

Encountering a problem with Bootstrap 5 version where adding background-color to <hr> is not displaying accurately: Comparison using Bootstrap 4: https://i.sstatic.net/QIY0P.png Comparison using Bootstrap 5: https://i.sstatic.net/Drlow.png Despite ...

Is there a way to configure gulp-sass to compile the actual bootstrap CSS styles instead of just echoing the import statement?

I recently embarked on a project where I wanted to utilize the Sass bootstrap source (.SCSS), apply some customizations (through another .SCSS file), and generate a CSS output. To achieve this, I decided to employ Gulp in VS2019 with gulp-sass. After goin ...

What is the best way to pinpoint particular text within a paragraph that includes numerous line breaks?

So here is the puzzling situation I'm grappling with. Here's a peek at the HTML snippet: <p>This paragraph has <br><br> two unusual line breaks <br><br> and it happens TWICE!</p> The problem arises when tryi ...

Is this the correct method for constructing a class in CSS?

What is the correct way to style a class with CSS and write HTML code? .first{ color:red; } Here is an example of HTML code: <class id=first> <p> some text </p> <p> some other text </p> ...

Exploring the beauty of background color curves in React Native

Struggling to figure out how to create a curved background color on the top (header part) of my design. Check it out https://i.sstatic.net/nNGPK.png I'm looking to achieve this curved design for my header part https://i.sstatic.net/K8wKV.png Here is ...

Exploring the differences between the meta viewport and font size

My website includes the following code in the section: <meta name="viewport" content="width=990"/> This setting helps to display my webpage well on mobile devices, as using width=device-width causes issues with elements that have 100% width. Howeve ...

The div functions seem to stop working properly after they have been multiplied

Initially, I use JavaScript to multiply the div but then encounter issues with the function not working properly. function setDoorCount(count) { $('.doors').html(''); for (var i = 0; i < count; i++) { var content = " ...

Connection to external sources has been deactivated

I am experiencing an issue on my website at . When attempting to click on a link, it seems to be disabled. I suspect this is due to the presence of two images at the end of the navigation bar. Removing these images causes the navigation bar to fall apart, ...

Tips for enhancing webpage load times by optimizing CSS and jQuery file handling

As a beginner in HTML and CSS, I am facing slow loading times when testing my pages on a local server. This makes me concerned about the potential loading time on the internet. Currently, I have all the files included in the <head> tag at the top of ...

The background of the ACTK Modal Popup vanishes after multiple instances of scrolling up and down

The issue I'm facing is with the AJAX Control ToolKit Modal Popup's background (the blind curtain) disappearing after scrolling up and down several times. I have attempted to resolve this by applying various CSS styles, but unfortunately, none of ...

Is it possible for me to include &x&y&z in my Sass code?

When working with Sass, I have the following code: asdf{ &-b&-c {font-size: 16px;} } And I want the generated CSS to look like this: asdf.asdf-b.asdf-c{ font-size: 16px; } Is it possible to achieve this in Sass without having to repeat th ...