What is the best way to arrange elements and create a cohesive layout?

I am currently working on a website and facing challenges in grasping the concept of alignment using CSS. I am struggling to align both text and image horizontally, ensuring they fit properly within the screen dimensions. Despite my attempts to modify different elements for alignment purposes, I have not achieved successful results.

https://i.sstatic.net/uxG7u.jpg

Below is the excerpt from my code:

<!doctype html>
<html lang="en">
  <head>
    <head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Bootstrap Biopage</title>
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b2d0ddddc6c1c6c0d3c2f2879c819c829fd3dec2dad380">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-aFq/bzH65dt+w6FI2ooMVUpc+21e0SRygnTpmBvdBgSdnuTN7QbdgL+OapgHtvPp" crossorigin="anonymous">
  <link rel="stylesheet2" href="/bio_style.css">
</head>

<body>
<nav class="navbar navbar-expand-lg bg-body-tertiary">
  <div class="container-fluid">
    <a class="navbar-brand" href="index.html">Joseph Albers</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="bio.html">Bio</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="artworks.html">Artworks</a>
        </li>
        
      </ul>
    </div>
  </div>
</nav>

<h1 class="heading"> Biography </h1>

<div class="general"> 
Josef Albers was born in Bottrop, a coal-mining city in the industrial Ruhr Valley, on 19 March 1888. His father was a general contractor who was proficient in carpentry, house-painting, plumbing, and other crafts; for the rest of his life, Josef would consider that the way his father trained him in the materials and techniques of these crafts was of vital importance to him. Josef became a school teacher, initially instructing young children in all subjects, and then an art teacher. He painted, made drawings of the region, and became a printmaker; as a teacher, he had an exemption that kept him out of the army during World War I.

<img class="young_albers" src="_assets/picture1.jpeg" width=308px class="rounded float-end" alt="Young Joseph Albers">
</div>



<h3>Bauhaus</h3>

<img src="_assets/picture2.png" alt="Bauhaus Students">

<div>
  <h5>Josef Albers arrived at the Weimar Bauhaus in 1920, the year after it was founded. He was supported by the Westphalian Regional Teaching System with the understanding that after a year he would return to the Bottrop region and resume his old job. But at the Bauhaus he became too intrigued with making assemblages out of discarded glass shards and bottle bottoms that he found in the town dump to consider leaving, and although he was told he had to try other media, he gained such respect from the Bauhaus masters that in 1925 he was one of the first students to be appointed a master. In 1922, Annelise Fleischmann had arrived from Berlin; she met Josef soon thereafter. She was initially turned down in her efforts to be admitted to the Bauhaus, but Josef helped her for a second set of tests, and she was admitted to the weaving workshop. They married in 1925. Anni would eventually direct the weaving workshop; Josef would work in carpentry, metalwork, glass, photography, and graphic design. At the Dessau Bauhaus, they lived in one of the Masters’ Houses, and in 1932, when the city government of Dessau stopped paying teachers’ salaries, they joined others at the Bauhaus when the school moved to makeshift headquarters in Berlin. In 1933, when the Bauhaus faculty, Josef among them, elected to close the school rather than comply with the Third Reich, the Alberses were left without jobs and with complete uncertainty about the future, especially because they already realized the significance of Anni being Jewish in the Nazi era.
    </h5>
</div>
</body>

<style>

.general {
  width: 80vw;
  overflow-wrap: break-word;
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 100vh;
  margin: 2vw;
  text-align: left;
  font-size: 24px;
}
.heading {
  padding: 20px;
  padding-left: 0%;
  margin-left: 2vw;
}


</style>

I experimented with adjusting sizes and margins to resolve the issue, however, those modifications did not yield the desired outcome.

Answer №1

To create a more flexible layout, adjust the parent container to display both text and image with flex properties. Then, add margins to ensure they are not too close to the edges. Remember to set the position of the text and image as absolute.

Once you have completed these steps, apply the following code to the parent container:

justify-content: space-evenly /*or alternatively, you can use space-between*/

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

Play a diverse selection of audio variables at random

As I prepare to transition into the view, I would like the controller to select a random audio file and play it. I'm feeling a bit lost on where to even begin with this task. Controller: var audioOne = new Audio("img/1.mp3"); var audioTwo = new Audi ...

Error: The $filter function in AngularJS is not recognized

I have been attempting to inject a filter into my controller and utilize it in the following manner: angular .module('graduateCalculator', []) .filter('slug', function() { return function(input) { ...

How can I make the element.setAttribute() method function properly in Internet Explorer?

I am using JavaScript to set the style attribute of a text element with the element.setAttribute() method, giving it a name of "style" and a value of "my modifications to the style of text." While this method works well in most browsers, it is not functio ...

I am puzzled by the behavior of the $.getJSON request. I am uncertain about how to properly format the request with the callback=? parameter

Out of the three jQuery JSON requests, one is encountering cross-domain errors due to my lack of understanding how to include the callback=? parameter (or the reason why it signifies JSON vs JSONP). I am working on two requests to the same API; however, o ...

Highcharts is experiencing a duplication issue with the Y-Axis Series

This is a snippet from my code: $.get('https://dl.dropboxusercontent.com/u/75734877/data.csv', function (data) { var lines = data.split('\n'); $.each(lines, function (lineNo, line) { var items = line.split(',& ...

Dynamic row addition in Material Design Lite table causes format to break

Here's the HTML markup for creating a checkbox using material-design-lite: <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="checkbox"> <input type="checkbox" id="checkbox" class="mdl-checkbox__input" /> <span c ...

What are some of the potential drawbacks of utilizing the same template ref values repeatedly in Vue 3?

Is it problematic to have duplicate template ref values, such as ref="foo", for the same type but different instances of a component across views in a Vue 3 application? Let's consider the following example pseudocode: // ROUTE A <te ...

What is the most effective way to prevent a <pre> element from overflowing and instead horizontally scrolling when placed within a table cell that is not

I am faced with the following situation: <table> <tbody> <tr> <td> <pre style="overflow: scroll;"> (very long lines of text) Find my JSFiddle here: https://jsfiddle ...

When implementing jQuery AJAX, remember to properly encode script tags to prevent any

Looking for a way to avoid script tags in content loaded through AJAX? Check out this approach: $.ajax({ cache: false, type: 'GET', url: 'index.html', success: function(response) { $(response).find('<sc ...

Exploring Elasticsearch with Ajax Query Syntax

Attempting to send a post request via AJAX to my Elasticsearch index but encountering some issues. Here's the cURL result: [~]$ curl -XGET 'http://localhost:9200/firebase/_search?q=song:i%20am%20in' {"took":172,"timed_out":false,"_shards": ...

Navigate to a list item once Angular has finished rendering the element

I need to make sure the chat box automatically scrolls to the last message displayed. Here is how I am currently attempting this: akiRepair.controller("chatCtrl", ['$scope', function($scope){ ... var size = $scope.messages.length; var t ...

The React parent encountered difficulty updating a child component within a JSX list that had been mapped

Kindly note that you have the option to view and modify the code on CodeSandbox. In the main file below, I have created a list of child components called ProgressBar using the useState hook: import React, { useState } from 'react'; import Progre ...

The reverse lookup for 'export2' without any parameters could not be located

Although my code is similar to this, I am encountering an error when trying to access a different view. My code works fine, but no matter what I do, I keep getting the same error. As a beginner in Django 2.1, I apologize if the solution is obvious. views. ...

vue.js libs requiring "new ..." are being scolded by eslint for their misspelling

When working with Vue libraries, such as Swiper, that require the use of 'new …' in the script section, I encounter ESlint errors no matter how I try to write it. Even though 'new ...' works perfectly fine in the frontend, ESlint cont ...

Tips for maintaining the nested collapsible table row within the main table row in a React MUI table

I am working on implementing a Material UI (MUI) table that includes collapsible table rows. The challenge I am facing is maintaining consistent border and background colors across all the rows, even when some are collapsed. Currently, the separate rows ar ...

Looking for help with Bootstrap - attempting to make a two-column table using list-group-item styling

Novice programmer seeking assistance with bootstrap4. I'm attempting to set up a list group item to showcase user reviews.see image description here I've tried adjusting every possible element. At first glance, it appears straightforward, but ...

NodeJS Puppeteer encountering problem with setting download behavior

When attempting to specify a custom download path, Chrome seems to ignore the downloadPath option and continues to save files in the default C:/Users/Me/Downloads folder regardless. const puppeteer = require('puppeteer'); (async () => { c ...

ESLint is not performing linting even though the server is operational

I found a frontend template online and successfully installed all the packages using yarn. However, although I have an .eslint.json file in place and the ESLint extension is installed in Visual Studio Code, I am not seeing any linting errors. Below is the ...

Can information be transferred to a CSS document?

Currently working on developing a content management system (CMS) using PHP and exploring the possibility of passing a URL to an image. In my PHP pages, I am utilizing Twig templates and the {{ image1url }} to display the image URL. Is there a way to pas ...

having trouble accessing a JavaScript array in AngularJS

Hey there, I'm currently working on a web application using AngularJS and I'm facing an issue with querying arrays. Check out the code snippet below: var angulararray = []; bindleaselistings.bindleaselistingsmethod().then(function(response) { ...