What could be causing the flexbox code to not take effect and the text to refuse wrapping?

I've been utilizing flexbox to style my content, and it worked seamlessly on the first three divs. However, when I attempted to apply the same styling to the fourth one, it didn't quite work out as planned. Despite trying options like flex-wrap to align my image and text side by side, they stubbornly remained stacked.

Despite experimenting with different flex properties, I couldn't seem to get the desired outcome. My goal is to stick to using flexbox for this layout.

#content {
  background: #ccc;
  padding: 30px 30px 30px 0;
  display: flex;
  flex-wrap: wrap;
}

#content article img {
  margin-right: 30px;
}

#content h1, #middle h1 {
  font-family: FuturaStdBoldCondensed;
  font-size: 30px;
  margin-bottom: .5em;
  color: #5c5c5c;
}

#content p,
#middle p {
  margin-bottom: 1em;
  line-height: 1.5em;
}
<section id="content">
  <article>
    <img src="images/frontPagePhoto.jpg" alt="photo">

    <h1>PROJECT: Cellular Network</h1>

    <p>In Kenya we are creating a cellular network, which poses several challenges, but will also come with many rewards. We are hoping that by the end of the year, all areas of this country will have coverage. We are working with local authorities to put
      service in reach of every villiage and community.</p>

    <p>Read more about it, or get involved...</p>
  </article>
</section>

The accompanying text can be found below the image.

Answer №1

Remove the image from the article element and place it within a figure element to enhance its semantic value. Additionally, style it as a flex item within the main container.

#content {
  display: flex;
}
<section id="content">
  <figure>
    <img src="http://i.imgur.com/60PVLis.png" width="150" height="150" alt="">
  </figure>
  <article>
    <h1>PROJECT: Cellular Network</h1>
    <p>In Kenya we are creating a cellular network, which poses several challenges, but will also come with many rewards. We are hoping that by the end of the year, all areas of this country will have coverage. We are working with local authorities to put
      service in reach of every villiage and community.</p>
    <p>Read more about it, or get involved...</p>
  </article>
</section>

Answer №2

The reason your text in <h1> and <img> elements is not on the same line is because the default display style property of the h1 tag is set to block.

In your current code, changing the parent element to a flex container does not solve the issue. One simple way to fix this is by adding display: inline-block; to your h1 element.

If you want to learn more about the differences between block and inline style properties, you can visit this link: CSS display: inline vs inline-block

#content {
    //background:#ccc;
    padding: 30px 30px 30px 0;
    display: flex;
    flex-wrap: wrap;
}

#content article img {
    margin-right:30px;
}

#content h1, #middle h1 {
    display: inline-block; // <-- THIS
    font-family:FuturaStdBoldCondensed;
    font-size:30px;
    margin-bottom:.5em;
    color:#5c5c5c;
}

#content p, #middle p {
    margin-bottom:1em;
    line-height:1.5em;
}
<section id="content">
    <article>
        <img src="https://via.placeholder.com/100" alt="photo">
        <h1>PROJECT: Cellular Network</h1>
        <p>In Kenya we are creating a cellular network, which poses several challenges, but will also come with many rewards. We are hoping that by the end of the year, all areas of this country will have coverage. We are working with local authorities to put service in reach of every villiage and community.</p>

        <p>Read more about it, or get involved...</p>
    </article>
</section>

Alternatively, if you prefer using flexbox to achieve this layout, you can assign flex: 1 to both the img and h1 elements and place them within a flex container. Additionally, setting flex-grow: 0 for the img element would be beneficial.

Answer №3

By assigning the flex property to a section tag that is not directly above the h1, p, and img elements, you are preventing the flex property from affecting those specific tags. Instead, try applying the flex property to the article tag, as it is the immediate parent in this scenario and should have the desired effect. I hope this explanation clarifies things for you. Thank you.

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

picture protrudes from the frame [WordPress template]

Check out my website: If you scroll to the bottom of the site, you'll see an image of a bride sitting on a couch. I recently added this code to the stylesheet: .novia img {min-width:1000px; float:none;} This code was meant to maintain a fixed heigh ...

What is the best way to create this using html and css?

Struggling to recreate a design I was given: I currently have this setup: How can I insert vertical lines spanning the full height between the options? <ul id="navigation"> <li><a href="#">Log In</a></li> <li> ...

The background of an HTML button does not appear in IE8

My buttons are not showing up in IE8. I tried adding background: transparent url('..'), but it didn't help. Here is the code: .wpcf7 input.wpcf7-submit { background: url("/wp-content/themes/ASC/images/<?=ICL_LANGUAGE_CODE;?>_submi ...

Focusing on a particular iframe

I am currently using the "Music" theme from Organic Theme on my WordPress site and have inserted this code to prevent SoundCloud and MixCloud oEmbeds from stretching the page width: iframe, embed { height: 100%; width: 100%; } Although the fitvid ...

Steps to include a HTML webpage within another page

I need assistance with a scenario involving two separate HTML pages on different servers. Merchant Form - Server A Payment Form - Server B Here's the desired scenario: The user completes all necessary fields on the Merchant Form and clicks submit. ...

Utilizing a dropdown feature in Bootstrap for creating X columns of lists instead of a traditional single list

Check out my Fiddle. Beneath Dropdown1 lies a single-column list of actions. I'm looking to expand this list across multiple columns, like 5 or the width of the page. I'm hoping there's a Bootstrap CSS class I can use for this, but I migh ...

Resolving Div Alignment Issues in Internet Explorer with jQuery CSS AddClass and RemoveClass

I've set up an HTML table with a hover highlight feature using jQuery and CSS. Here's how my hover event is structured: $('#' + element.id + ' tr:not(:first,[class="summary_row"])').die('mouseover mouseout').live(&a ...

When trying to load AJAX, it does not function properly unless the page is refreshed

I'm currently working on a web page and encountering some difficulties. Within my HTML, I have two divs that are refreshed using AJAX. The issue is that the content loading seems to be inconsistent unless I manually refresh the page or implement a tim ...

Can you transform a component with inputs into plain HTML code?

Within my Vue component named component-z, I am looking to pass specific parameters when using it in my Vue's HTML. Here is an example of how I typically do this: <component-z id="component" data1="data" data2="moreData"></component-z> N ...

Tips for centering a video vertically within a cell

I need assistance with aligning a video in the center of a fixed height cell while hiding the overflow at the top and bottom. Here is what I have so far: <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height ...

JavaScript animation is not functioning as expected

I created a div with the id of "cen" and gave it a height and width of 50px. $(document).ready(function() { $("#cen").animate({ height: 500px, width: "500px", }, 5000, function() { // Animation complete. }); }); Unfort ...

Steps for embedding a webpage within a div element

I am facing an issue while trying to load a web page within a div using an ajax call. Unfortunately, it's not working as expected and displaying the following error message: jquery.min.js:2 [Deprecation] Synchronous XMLHttpRequest on the main thread ...

Ways to turn off textarea resizing

Is there a way to prevent horizontal resizing on a textarea while still allowing vertical resizing? I find that the textarea often disrupts the design of my contact us page. If anyone has a solution for disabling the horizontal resize feature, please shar ...

Do individual JavaScript script tags operate independently of one another in terms of error handling?

My main goal is to establish a connection to my server using websockets and send messages to the browser for remote page reloads. I want to ensure that this code runs independently of any other errors on the page, allowing me to remotely refresh the page i ...

CSS-Enabled Panels held in place with Draggable Feature

Currently immersed in my first ASP.net/HTML/CSS Application, I am exploring the realm of draggable panels using the Ajax-Control-Toolkit. So far, it's been a successful endeavor as I have managed to implement a single panel into my application! As de ...

What is the best way to arrange 4 divs with 2 on each line?

Consider the divs provided below: <body> <div id="f1">{{ f1|safe }}</div> <div id="f2">{{ f2|safe }}</div> <div id="f3">{{ f3|safe }}</div> <div id="f4"> ...

Tips for concealing scrollbar track without the use of overflow

Issue with Mystery Scrollbar A strange phenomenon is occurring on all pages every time the user reloads - a mysterious scrollbar track appears out of nowhere. Initially, there is no sign of this scrollbar track, making it even more puzzling. Despite the ...

Is the PHP configuration correct for Apache on your local server?

I'm currently facing an issue with connecting to a MySQL server in order to retrieve data for a flash application using PHP. I created a test .php file to check if everything is working correctly: <html> <body> <?php $link = mysql_con ...

Incorporate zoom feature into the jQuery polaroid gallery

Currently, I am utilizing a jQuery and CSS3 photo gallery found on this website. My goal is to allow the images to enlarge when clicked, however, the method provided by the author isn't very clear to me, as I'm not an expert in jQuery. I attempt ...

Image not found in PDF created from HTML to PDF conversion

I am currently utilizing the HTML-pdf library to convert an HTML page into a PDF format. While the dynamic content is being displayed in the generated PDF, there seems to be an issue with the image not appearing as expected. Despite trying various methods, ...