CSS: Specify child element to have a full width of 100%, but appear only 50% wide

Looking at this page, it seems that the header photo is not displaying full width.

#wrap {
  width: 990px;
}
#content-wrap {
  display: flex;
}
.image-header {
  display: block;
  width: 100%;
}
.image-header img {
  width: 100%;
  height: auto;
}
.container {
  position: relative;
  width: 960px;
  margin: 0 auto;
  padding: 0;
}
<div id="wrap">
  <div id="content-wrap" class="fluid clearfix" data-content="content">
    <!-- /#start content-wrap -->
    <div class="image-header">
      <img src="https://staging.orsgroup.com.au/eapportal/wp-content/uploads/sites/2/2016/07/ORS-Internals-960x211-EmployServOccu21.jpg" alt="Home Page" title="Home Page">
    </div>
    <div class="clear"></div>
    <div class="container">
      <div id="content" class="sixteen columns">
        <section class="post-9 page type-page status-publish hentry">

          <h1>Home Page</h1>

          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam mollis tortor vel diam volutpat luctus. Proin placerat nisl nulla, in mattis ex consectetur quis. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec vitae enim
            vel nibh hendrerit dignissim a et ante. Mauris eget tempus nunc. Donec dignissim elit sed ullamcorper semper. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas facilisis, risus eu varius lacinia, diam tortor volutpat ipsum,
            eu luctus neque massa quis leo. Phasellus blandit pellentesque justo non ornare. Cras et elit sit amet quam consequat viverra vel a diam. Pellentesque rutrum, dolor sit amet condimentum dapibus, lorem est dapibus orci, a congue ante ante ac
            lectus. Donec maximus pretium venenatis. Cras ex leo, pellentesque in libero sit amet, auctor congue sapien. Aliquam nec mi commodo ipsum sagittis tincidunt. Vestibulum sollicitudin laoreet eros vel finibus. Integer accumsan consectetur neque
            eget sodales.</p>
        </section>
        <!-- #post-## -->
        <!-- You can start editing here. -->
      </div>
      <!-- /#content-wrap -->
      <div class="clear"></div>
    </div>
  </div>
</div>

It appears that the .image-header element is only taking up around 50% of the width of the #content-wrap.

I attempted to add width: 100% to #content-wrap, but the issue persists.

I would like to maintain the flex model layout.

Your assistance is greatly appreciated.

Answer №1

Reason for this Issue

The issue is arising due to the utilization of the flexbox model, which aims to distribute elements on the same line. To rectify this behavior, there are several approaches you can take:

Make the Content Wrap

By default, the flex-wrap property is set to nowrap. Changing it to wrap will prompt the text content to move to the following line when space runs out.

#wrap {
  width: 990px;
}
#content-wrap {
  display: flex;
  flex-wrap: wrap;
}
.image-header {
  display: block;
  width: 100%;
}
.image-header img {
  width: 100%;
  height: auto;
}
.container {
  position: relative;
  width: 960px;
  margin: 0 auto;
  padding: 0;
}
<div id="wrap">
  <div id="content-wrap" class="fluid clearfix" data-content="content">
    <!-- /#start content-wrap -->
    <div class="image-header">
      <img src="https://staging.orsgroup.com.au/eapportal/wp-content/uploads/sites/2/2016/07/ORS-Internals-960x211-EmployServOccu21.jpg" alt="Home Page" title="Home Page">
    </div>
    <div class="clear"></div>
    <div class="container">
      <div id="content" class="sixteen columns">
        <section class="post-9 page type-page status-publish hentry">

          <h1>Home Page</h1>

          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam mollis tortor vel diam volutpat luctus. Proin placerat nisl nulla, in mattis ex consectetur quis. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec vitae enim
            vel nibh hendrerit dignissim a et ante. Mauris eget tempus nunc. Done...
        </section>
        <!-- #post-## -->
        <!-- You can start editing here. -->
      </div>
      <!-- /#content-wrap -->
      <div class="clear"></div>
    </div>
  </div>
</div>

Alter the Flex Direction

By default, the flex-direction property is set to row. Changing it to column will arrange the content from top to bottom rather than left to right.

#wrap {
  width: 990px;
}
#content-wrap {
  display: flex;
  flex-direction: column;
}
.image-header {
  display: block;
  width: 100%;
}
.image-header img {
  width: 100%;
  height: auto;
}
.container {
  position: relative;
  width: 960px;
  margin: 0 auto;
  padding: 0;
}
<div id="wrap">
  <div id="content-wrap" class="fluid clearfix" data-content="content">
    
    ...
    
  </div>
</div>

Answer №2

From my understanding, it seems like everything should work smoothly if you simply follow these instructions:

.banner {

    width: 100% !important;
    position: absolute; /* If it's unnecessary, feel free to exclude it. Otherwise, add a margin to prevent text overlap */
    height: 300px;
    margin-left: auto;
    margin-right: auto;

}

Answer №3

#content-wrap {
  display:flex 
}

There is a potential issue with this part of the code because the flex property specifies the length of the item relative to other flexible items within the same container. To address this issue, it is recommended to remove the flex property from your code and observe the changes.

Alternatively, you can try using the following CSS:

#content-wrap {
  -webkit-flex-flow: row wrap;
}

.image-header,.container {
  -webkit-flex: 1 100%;
}

By implementing the above CSS, you should be able to resolve the problem and effectively utilize the flex box model in your project.

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

Utilize Custom Field to incorporate background videos from websites like Youtube or Vimeo into your content

I've been working on implementing a video background for my website. I came up with a custom code to embed URL links from Youtube and Vimeo using "oEmbed". The process is functioning well, but I'm facing some challenges in setting the background ...

The link generated through ERB using link_to cannot be clicked on

When using the ERB link_to helper method to generate a hypertext link to an individual article, I am encountering an issue where the link appears as clickable in the view but is not actually clickable (the cursor does not change to a pointer). I have atte ...

Guide: Previewing uploaded images with HTML and jQuery, including file names

Any constructive criticism and alternative methods for accomplishing this task are welcomed. I am currently working on writing jQuery code that will allow users to preview file(s) without reloading the DOM. To achieve this, I have been using .append() to ...

The data-toggle function is not functioning properly with the code provided

Could someone shed some light on why my tabs and navigation bar dropdown button are not functioning properly? <div class="col-12"> <h2>Corporate Leadership</h2> <ul class = "nav nav-tabs&q ...

Angular is unable to eliminate the focus outline from a custom checkbox created with Boostrap

Have you noticed that Angular doesn't blur out the clicked element for some strange reason? Well, I came up with a little 'fix' for it: *:focus { outline: none !important; } It's not a perfect solution because ideally every element sh ...

Eliminate the standard cell padding in nested HTML tables

In my setup, there is a parent table where each td tag in the tr tag contains a child table. Specifically, as shown in the example with Data WS-C3.... in the picture. [![<table class="table table--bordered table--nostripes table-top"> <thead& ...

Implementing automatic page breaks in Laravel using the mpdf libraryLet me know

I am attempting to automatically add a page break if the data exceeds 10. I am using mpdf in conjunction with Laravel and Vue. Below is my CSS code: <style> div.breakNow { page-break-inside:avoid; page-break-after:always; } </style> This is t ...

Creating a dropdown menu and adjusting the content below

Feeling stuck in one place with my code here: link The side navbar animation is almost what I want, but clicking one option opens all of them. Hoping for a similar effect like this page: link $(document).ready(function() { $('.interfejs, .proces ...

Slower CSS rendering as Javascript finishes its tasks

I am currently dealing with a jQuery plugin that is quite large and complex, but I will not be sharing it here to keep things simple. The issue I am facing is relatively straightforward, so I will focus on the essential code snippets: There is a click eve ...

Creating a centered div in HTML for WordPress

<div id="logo" style="center"><img src="logo1.png"></img></div><br><br><br><br><br><br><br></div> It seems like there is an issue with the styling of the div element. The syntax might ...

Utilize jQuery to create a dynamic image swapping and div showing/hiding feature

I'm having trouble implementing a toggle functionality for an image and another div simultaneously. Currently, when the image is clicked, it switches to display the other div, but clicking again does not switch it back. Can someone please advise on wh ...

Utilizing jQuery for animating SVG elements with dynamic color changes and scaling effects upon hover

Seeking assistance from coding experts! I have created an icon and am attempting to modify it so that the color changes when hovered over. Additionally, I want the white square to scale down by 50% starting from the top-left corner of its current position. ...

Struggling to locate the src/site/globals/site.variables file to customize the font-family in Semantic UI React. Is there an alternative method to achieve this?

I've been attempting to modify the overall font-family for my application, but so far, I haven't had any luck. Since I'm working with Semantic-UI-React, I initially thought that could be the issue. However, when I tried to locate src/site/g ...

Discrepancy in Angular Material Buttons with theme design

I recently installed Angular 10 along with Angular Materials using the command ng add @angular/material I opted for the custom theme: Purple/Green The next step was to add a Toolbar by simply copying and pasting code from Google's site. However, I a ...

Setting a div's background using JavaScript works flawlessly on jsfiddle.net, but encounters issues when implemented in actual code

contains the files you need. For reference, here is the link to the code on I have attempted to remove all unnecessary elements from the actual project, but it has not made a difference. document.getElementById("image").style.backgroundImage = "url(" + d ...

bulk purchase discount with HTML/JavaScript/PHP

I am looking to add a slider feature to my "Prices" page in order to provide customers with an instant quote based on the quantity they select. The slider should range from 1 to 500 or even up to 1000, but having an input box for customers to enter the qu ...

Equal-height rows and columns using Flexbox

I've been working on a row layout with two columns, each set to 50% width. The left column contains an image, while the right column displays text. Here is my HTML: .row{ display:flex; ...

What is the best way to utilize the @Import CSS rule in my code?

After using CSS for a considerable amount of time, I have successfully utilized the @import rule in the past. However, I am currently encountering an issue with it on a new project. Is there anyone who can offer assistance? Here is the code: @import url(&a ...

Unable to conceal HTML5 video in mobile devices through media query

I've been struggling to find a solution for hiding a video on mobile devices. Despite going through numerous posts and attempting different methods, I haven't been successful in using @media queries to hide the video and show an image instead. He ...

Get Your Business Rolling with the Shopify Cruise Theme

I'm currently utilizing the ride theme on my Shopify website and I've embedded a video in an index.json file: "video_url": "https:\/\/www.youtube.com\/watch?v=KlxiEKrhWIQ", Is there a way to make the video aut ...