How to conceal overflow within a div content on the left side when resizing the browser using bootstrap

I've searched through all the SO questions and tried Google, but I still can't find an answer. I have a bootstrap layout and I want the content to hide from both sides (left and right) when the browser is resized.

  • If I use overflow-x:hidden, it only hides content from the right side

  • If I apply negative margin, the layout gets messed up

In the code snippet provided, you can see that currently only the right side image hides when resizing the browser. However, I need the page to hide content from both sides. I'm looking for a CSS-only solution, please.

body {
   overflow-x:hidden;
}
.wrapper {
  width: 1170px;
  margin: 0 auto 0 -585px;
  position:relative; 
  left:50%
}
.left-img {
  width: 600px;
  height: 700px;
 }
.right-img {
  width: 700px;
  height: 600px;
 }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>



<div class="wrapper">
  <div class="col-xs-6">
    <img src="http://www.w3schools.com/w3images/lights.jpg" class="img-responsive left-img">
  </div>
  
  <div class="col-xs-6">
    <img src="http://www.w3schools.com/w3images/lights.jpg" class="img-responsive right-img">
   </div>

</div><!-- end wrapper-->

Answer №1

To make this work, simply include the following code in your wrapper. While it may not be the most optimal solution, it does the job by causing overflow to the left of the screen, necessitating a negative margin (equivalent to half the wrapper width).

Check out the live example here

.wrapper {
   width:1270px;
   margin:0 auto 0 -635px; 
   position:relative; 
   left:50%;
}

Keep in mind that there might be issues on smaller screens, but you can address this by implementing media queries targeting specific screen sizes.

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

How can I automatically center a Vimeo iframe vertically without having to manually adjust the position?

I'm trying to adjust a popular fluid jQuery script so that it can automatically center a vimeo video vertically, without any black bars. A little horizontal cropping is acceptable. Here is my current code: HTML <div class="container"> < ...

Positioning a footer at the absolute bottom of a webpage

I am currently working with 2 divs that are absolutely positioned within a relative container. I intend to utilize JavaScript for toggling visibility. .container { position:relative; } .section1 { position:absolute; top:0; left:0; right:0; ...

Responsive full-screen background image display

Why is the background image not appearing as a full image on large screens but fitting fine on small screens? <!DOCTYPE html> <html dir="ltr"> <head> <meta charset="utf-8" dir="ltr" /> <title ...

Is it possible to leverage React/Next.js for dynamically adding HTML content based on element IDs when integrating with Netlify forms?

Sorry if this question has already been addressed somewhere. I've spent hours searching and troubleshooting without success. I'm still in the process of learning React, as it's a new concept to me. I just need to implement it for a contact ...

How can I ensure that the NextJS Image component fills its parent div completely in terms of both height and width?

Having trouble getting the Image component to behave like the img element? Can anyone provide a solution for making Image achieve the same result as shown in the example below? <div style={{ width: "100vw", height: "100vh", display ...

Obtaining varied outcomes while printing filtered information

As a beginner in React.js using hooks, I prefer to learn through hands-on coding. My query revolves around fetching data from a specific URL like ksngfr.com/something.txt and displaying it as shown in the provided image (I only displayed numbers 1-4, but t ...

Create a stylesheet document.write function that will never be true

While examining the source code of a webpage, I stumbled upon this intriguing piece of JavaScript right after the standard stylesheet declaration: <script type="text/javascript"> if('' != '') { document.write("< ...

Get an ICS file as text using JQuery

As a newcomer to JQuery and JS, I seek your understanding for any mistakes I may make. My current goal is to extract the text from an ICS file (e.g. BEGIN:CALENDAR....) using JavaScript. Here is a simple HTML file I am working with: <html> <b ...

Using the jquery slider in conjunction with the onchange event

I have integrated a jquery slider add-on into my project that updates a value in a Linux file whenever it is manipulated. The slider is connected to a text input box, which is set as readonly and therefore always blurred. The issue I am facing is that the ...

Ensuring the continuous transmission of data frames is essential for WebSocket communication

Our system utilizes websocket technology to transmit user activity events such as clicks, mouse movement, scroll, input, and more. In addition to these events, we also send a snapshot of the HTML DOM. On average, the size of the HTML snapshot is approximat ...

What is the best API for incorporating interactive maps into my Android application?

I am looking to create an Android app (using Java) with interactive maps similar to ammaps, which can be integrated with HTML5/jQuery Mobile. Check out for reference. The app will display a world map where different areas are highlighted or colored based ...

How can I adjust the size of an element without causing the other elements to move around on the

Currently, I am working on a live web page. You can view it at the following address: The issue I am facing is with the element just before the body's closing tag, the div "games_grid." When hovering over the game capsule image, it expands, causing t ...

What is the best way to ensure the website title is displayed properly on a mobile browser?

Concern I have been encountering difficulties while constructing a portfolio website using bootstrap 5. The issue arises with the navbar, causing the Title to overlap the hamburger menu and extend beyond the edge of the screen. Strangely enough, this prob ...

How do I retrieve the content within this HTML element using JavaScript based on its ID?

Is there a way to extract the string from this specific HTML element using JavaScript? The element has an id of recItemString_GPLA\|input, and within it, there is a string containing "qty" that I need to retrieve. Upon inspection of the element, the f ...

Ways to repair the mouse hover transform scale effect (animation included)

I am currently facing an issue with my GridView that contains images. When I hover over the top of the image, it displays correctly, but when I move to the bottom, it does not show up. After some investigation, I suspect that there may be an overlay being ...

Trimming content within an editable div in JavaScript: A guide

I am working on an editable div feature where users can input text for comments. My goal is to eliminate any unnecessary spaces before and after the text. For example, if a user types: "&nbsp;&nbsp;Hello&nbsp;world&nbsp;&nbsp;&nbsp ...

Left-align switch labels in Bootstrap 4 for a clean and organized look

Here is the code snippet that I am currently working with: .custom-switch { padding-left: 0; } .custom-switch .custom-control-label { left: 0; padding-left: 2.5rem; } .custom-switch .custom-control-label::before { top: 0.125rem; left: 0; ...

Having difficulty adjusting the color of the navbar in Bootstrap 4

I recently designed two navigation bars using bootstrap, but encountered an issue when attempting to change the background color of the second navigation bar. Despite following a tutorial video closely, the color did not update as expected. The main css fi ...

Tips on arranging check-boxes horizontally in this code repository

We are working with an autogen form in PHP, and the way the checkboxes are currently displayed is demonstrated in the following code: case FIELD_CHECK_BOX: $fieldHtml = printCheckbox($mode, $field->getId().'[]', $field->get ...

The issue of consistently receiving a null value when trying to choose a selection from a

The drop-down menu below failed to meet the required criteria in my validation and kept prompting me to select an option, even though one had already been chosen. <div class="col"> <label for="#">College Degree</label ...