Float: right; is causing distortion to the appearance of Div elements

I would like to style this image and text so that they float to the right with some spacing around them. However, when using float: right;, they end up extending beyond the default resolution excessively.

#pageMain {
  margin: 100px;
}

#aboutGame {
  float: right;
  width: 420px;
  padding: 10px;
}

#aboutGame span {
  width: ;
  font-size: 20px;
  font-family: 'Lato', sans-serif;
}

#aboutGame img {
  border: 3px solid black;
}
<section id="pageMain">
  <div id="aboutGame">
    <span>
As if awakening from a deep sleep, you find yourself in a strange, contradictory world of ancient ruins and advanced technology. Tasked by your creator with solving a series of increasingly complex puzzles, you must decide whether to have faith, or to ask the difficult questions: Who are you? What is your purpose and what are you going to do about it?</span>
    <img src="http://cdn.akamai.steamstatic.com/steam/apps/257510/ss_ded5cd1a34df5b4d9015f71caf35db247b2579c4.1920x1080.jpg?t=1498680189" height="500px" width="800px" />
  </div>
</section>

Answer №1

#pageMain {
  margin: 100px;
  overflow: hidden;
}

#aboutGame {
  float: right;
  width: 420px;
  padding: 10px;
}

#aboutGame span {
  width: ;
  font-size: 20px;
  font-family: 'Lato', sans-serif;
}

#aboutGame img {
  border: 3px solid #000;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 20px 0;
}
<section id="pageMain">
  <div id="aboutGame">
    <span>
As if emerging from a deep slumber, you awaken in a mysterious world of ancient remains and cutting-edge technology. Assigned by your maker to unravel a series of increasingly intricate puzzles, you must choose whether to have faith or confront the tough questions: Who are you? What is your purpose, and how will you respond? </span>
    <img src="http://cdn.akamai.steamstatic.com/steam/apps/257510/ss_ded5cd1a34df5b4d9015f71caf35db247b2579c4.1920x1080.jpg?t=1498680189" height="500px" width="800px" />
  </div>
</section>

I believe this achieves what you intended, as I included some styling for the image tag and added overflow:hidden to the parent #pageMain div to address clearing issues caused by its floated children elements.

Answer №2

Your inquiry seems a bit unclear, but let me know if this solution works for you

#pageMain {
  margin: 100px;
}

#aboutGame {
  float: right;
  width: 420px;
  padding: 10px;
}

#aboutGame span {
  width: 100%;
  text-align:right;
  display: block;
  font-size: 20px;
  margin-bottom: 50px;
  font-family: 'Lato', sans-serif;
}

#aboutGame img {
  border: 3px solid black;
  width:100%;
  height: auto;
}
<section id="pageMain">
  <div id="aboutGame">
    <span>
    As if awakening from a deep sleep, you find yourself in a strange, contradictory world of ancient ruins and advanced technology. Tasked by your creator with solving a series of increasingly complex puzzles, you must decide whether to have faith or to ask the difficult questions: Who are you? What is your purpose and what are you going to do about it? </span>
    <img src="http://cdn.akamai.steamstatic.com/steam/apps/257510/ss_ded5cd1a34df5b4d9015f71caf35db247b2579c4.1920x1080.jpg?t=1498680189" />
  </div>
</section>

Updates made in your code:

1. Eliminated the width and height attributes from image tag as per recommendation by showdev since it was causing the image to appear larger than the container itself.

2.

#aboutGame span {
    width: 100%; //Determines the width taken by the span
    text-align:right; //Right aligns the text, other options include left/center/justify based on your requirements
    display: block; //Displays elements as blocks 
    margin-bottom: 50px; //Adds space between image and text
  }

  #aboutGame img {
    height: auto; //Adjusts height according to the width
  }

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

The icon on the left displaying peculiar conduct

Currently in the process of developing an application using Bootstrap and incorporating a user feed for admins which is inspired by the Dark Admin theme. The structure of my HTML resembles the demo provided, with CSS styling being compared to ensure consis ...

Showing the total quantity of products, reminiscent of a virtual shopping basket

I am trying to show a number similar to how a shopping cart displays items. The php code I was given currently shows a cookie value, which is mostly functional. However, if you encounter errors while adding items to the cart, it increases the cookie count ...

Create a `div` element that transforms into a box when hovered over and displays text

Sorry for repeating a common question, but I'm struggling with CSS and need some help. I am new to this, so any assistance is greatly appreciated. I want to display 14 "element boxes" each with their own background, etc. When hovered over, I would li ...

Guide to displaying a table enclosed in a div based on a selected value in a select dropdown?

I am attempting to retrieve the table options using the select question-picker: Here is what I have tried: $(document).ready(function() { var question_container = $('.question-picker option[value="1"]').parent(); console.log(question_cont ...

Display a still image in cases where the browser does not support 3D images

I need to display a 3D image in my HTML page if the browser supports canvas, otherwise I want to show a static image. The image should be loaded dynamically when the page loads. <!DOCTYPE html> <html class="no-js" lang="en"> <head> ...

Highlighting the current menu item by comparing the URL and ID

Looking to make my navigation menu items active based on URL and ID, rather than href. None of the suggested solutions (like this one, this one, or this one) have worked for me. This is how my Navigation is designed: <nav id="PageNavigation"& ...

Analyzing comma-separated values file and transforming the information into a modifiable format

Need advice on parsing CSV and using foreach loop.. <?php //output Array ( [0] => Array ( [company] => A Company [address] => A Address [telephone] => A Telephone ) [1] => Array ( ...

extracting values from an HTML document to populate a Java email template

I'm currently working on a contact form that lets users input their information and sends an email to the specified email address. I've been struggling with extracting the parameters from the HTML file and linking them to the email components. Fo ...

Guide to eliminating the arrow from a dropdown menu in Bootstrap 4

I am working with Bootstrap 4 and attempting to eliminate the dropdown arrow in my design. Unfortunately, the solutions that were effective for Bootstrap 3 no longer apply. You can read more about this issue here. To see the problem in action, check out ...

Conflicts in SwiperJS Timeline Management

Having a Timeline on my Website using SwiperJS presents challenges with conflicting functions. The goal is to navigate swiper-slides by clicking on timespans in the timeline. The desired functionality for the timeline includes: Sliding to the correspondi ...

Tips for extracting the src attribute from a dynamically generated iframe

My dilemma stems from a function that generates an iframe with content on my website, which unfortunately I cannot control as it is loaded remotely. The function initially creates: <span id="myspan"></span> Once the JavaScript function fu ...

"Enhance Your Design with Hovering CSS Backgrounds

Seeking assistance with changing the background image on span hover. If anyone can assist, I have included the complete code for the website below. Take a look at the full website code here: Pastebin CSS Pastebin JavaScript ...

Issues with ng-bind-html in AngularJS and JavaScript are preventing it from functioning

I am experimenting with creating a dynamic webpage that can change its contents without being limited to predefined templates (potentially offering infinite template options). Below is the code I am currently testing: <!DOCTYPE html> <html lang= ...

`How can I use JavaScript to display a modal?`

I am currently a student immersing myself in the world of coding, particularly focusing on learning javascript/jquery. In my recent project, I have developed a chess game using RoR and now I am tackling the promotion move. The idea is that when a Pawn piec ...

Does a pointer event match the 'click' event?

When it comes to mouse events, the 'click' event is triggered after both the mousedown and mouseup events occur. But with pointer events having a wider range of uses, I'm curious if there is an equivalent 'click' event for pointer ...

Can you explain how to set a title to align with the object on the far left within a Grid component using justify="space-between" in Material UI?

I am currently working on a Grid layout project that involves a Grid container with four Grid items. The first Grid item takes up the full width and contains a title, while the other three Grid items contain avatars. My goal is to align the avatars to the ...

The new button placed on a <div> was not initialized to trigger my greasemonkey functions

Recently, I implemented a button via GreaseMonkey: var input = document.createElement('input'); input.type = 'button'; input.value = 'Off'; input.onclick = turnTheWheelsofTime; Initially, the button functioned flawlessly whe ...

Ways to conceal text links on mobile devices using Bootstrap 4

Is there a way to hide the text of a link on mobile screens using Bootstrap 4? How can this be achieved? HTML <li> <a href="#"><i class="fa fa-icon"></i> Text Link</a> </li> I want to show only the icon on mobile de ...

Eliminate any space from the navigation bar on my website

I just started learning HTML and I'm struggling with some whitespace issues on my navigation bar. Can anyone help me figure out what's causing it? div.nav { background-color: black; color: white; font-size: 20px; font-weight: bold; ...

How to position Bootstrap inline checkboxes to the left or right within a form well?

I am currently incorporating Twitter Bootstrap inline checkboxes into a form-horizontal well well-small setup. When I attempt to add pull-left or right to the checkboxes, they are correctly aligned but end up outside of the well element despite being nest ...