Adaptable text and visual content

I'm working on creating a responsive <div> that contains a perfectly square SVG image and some accompanying text. Here is my current progress, thanks to piecing together information from various Stackoverflow replies:

<div class='outer'>
<div class='inner'>
<svg width='100%' height='100%' viewBox='-35 -35 70 70' 
     preserveAspectRatio='xMaxYMin meet' id='yadayadayada'
     xmlns='...' version='1.1' xmlns:xlink='...' xmlns:svgjs='...'>...</svg>
</div>
</div>

The above code generates the SVG image using SVG.js:

let image = SVG().size('100%', '100%')
                  .addTo('.inner')
                  .id('yadayadayada')
                  .viewBox(-35, -35, 70, 70)
                  .attr({preserveAspectRatio: 'xMaxYMin meet'});
//
// SVG drawing stuff
//

This is accompanied by the following CSS styling:

div.outer::before, div.outer::after {
    height: 5%;
    display: block;
    content: "";
    margin: 0 0 0 0;
}
div.outer {
   margin: 0 0 0 0;
   padding-left: 5%;
   padding-right: 5%;
   width: 90%;
   height: 90%;
}
div.inner  {
    width: 100%;
    height: 100%;
    position: relative;
}

This layout results in:

+------------+---------------+
|            |               |
|            |               |
|            |               |
|    Blank   |      SVG      |
|            |               |
|            |               |
|            |               |
+------------+---------------+

Essentially, a <div> filling the entire window with a 5% margin on each side, housing a square SVG image on one side. However, I am facing challenges when trying to add text next to the image within the same size constraints without displacing the image downwards.

It appears that the <svg> may not be perfectly square, causing it to protrude out of its intended container if text is introduced.

If anyone has suggestions on achieving a large square image alongside text while maintaining responsiveness, I would greatly appreciate the guidance. The goal is to ensure the design remains visually appealing even during fullscreen mode shifts or presentation scenarios where landscape orientation prevails.

Answer №1

Looking to design a responsive <div> with a perfectly square SVG image and accompanying text.

Do you want to position your text in the current location of blank?

If yes, it's recommended to utilize CSS Grid.

Begin by adding an additional container for the text content:

<div class = "outer">

  <div class = "textbox">

  </div>

  <div class = "inner">
    
    [... CONTENTS OF .inner HERE...]
  
  </div>

</div>

Then assign properties to .outer:

  • a display value of grid
  • one row
  • two equal columns

using the following CSS code:

.outer {
  display: grid;
  grid-template-rows: 45vw;
  grid-template-columns: 45vw 45vw;
}

This will automatically set the width of:

  • .textbox to 45 viewport width units (45% of the viewport width)
  • .inner to 45 viewport width units as well

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

What is the best way to align social media icons at the center of the footer section?

I've been working on trying to center the social media icons in the footer, but no matter what changes I make in the code, there's been no visible difference. Can anyone offer some assistance? footer { background-color: #FFF; color: white; ...

"Pressing the 'back' button on your browser takes

Is there a way to navigate back to the main page by clicking on an image? After selecting First, Picture1 will be shown. How can I go back to the selection page for further choices? <a href="picture1.jpg"> <h3>First</h3></a> <a ...

Invoking functions with JavaScript objects

Can anyone help me figure out what is wrong with the following JavaScript code? <form> What is 5 + 5?: <input type ="number" id ="num_answer;"/> </form> <script> function basic_math(){ var num_val = document.getElem ...

How to Exclude ress.css in Vuetify.js

How can I prevent ress.css from conflicting with Bootstrap and my custom styles in Vuetify? I attempted to remove it from the Vuetify directory within node_modules, but that did not resolve the issue. ...

Issue with Edge browser: child element exceeds parent's defined width

We need to meet a specific requirement that involves displaying a prefix inside a textbox that cannot be edited. Check out the HTML/CSS code on JSFiddle. The issue arises when we resize the window. HTML: <div class="customNameContainer" dir="ltr"> ...

Tips for creating a table with HTML

https://i.sstatic.net/f2nTP.png I'm looking to create a table that resembles the image above. If anyone has suggestions or ideas on how I can achieve this design, please feel free to share. Thank you, Ashraf ...

When the button is clicked, the input values in Javascript vanish

I'm currently working on a project where I need to simulate data entry for a form using vanilla Javascript. Unfortunately, I am unable to edit the HTML itself. Everything seems to be working fine with my code until I click the final save button and a ...

Are there any methods to achieve smoother font icons on Firefox?

When it comes to using icons on different browsers, I've noticed an issue. Icons appear sharp on Google Chrome and Opera, but when viewed on Firefox they tend to look blurry if the font-size is less than 20px. Strangely enough, once the font size reac ...

What's the best unit of measurement to use when designing a business card online: pixels or cent

Looking for advice on designing business cards online with specific dimensions - 8.5 cm x 5.5 cm. The dilemma lies in choosing between using pixel or centimeter units in CSS for width and height. What's the best approach? Ultimately, I'll need ...

React application: Issue with second container not adjusting to the full height of the first container

My application consists of two containers. One container is a ReactPrismEditor, while the other is simply a container displaying text. However, I am facing an issue where the height of the second container does not adjust according to the content inside t ...

Preventing automatic image adjustment in CSS during zooming in or out

<div class="footer"> <img class="fisk" src="fisk1.jpg" alt="fisk"> </div> I am facing an issue with keeping the size of an image constant when zooming in and out. Despite trying various methods, I have not been successful in achieving ...

Is it possible to have scrollbars on opposite sides of a div?

My table has a multitude of columns, prompting me to enclose it within a div with overflow:auto to facilitate horizontal scrolling. Currently, the scrollbar is situated at the bottom of the div. Is it possible to have two scrollbars present, one at the t ...

Selecting a specific value in Vue.jsNeed help in

My HTML code includes these lines: <v-select v-model="user2_id" :options="[{!! $users !!}]" class="select"> </v-select> <input type="hidden" v-model="user2_id" name="user2_id"> The variable $users is defined as follows: <?php $l ...

Experiencing difficulties with my .css formatting following the installation of bootstrap in Angular

I've been immersing myself in Angular and encountered an issue that has me stumped. Despite using the latest version of Bootstrap in my Angular project, I'm facing challenges with my styles.css file that was defined prior to installing Bootstrap. ...

Using jQuery to change the background color of table cells to various shades

I am seeking assistance with a table I have created, and I want to implement a feature where the background color of cells with prices will change when clicked (using addClass(on)). The goal is to also change the background color of surrounding cells (usin ...

Troubles with executing JavaScript code within HTML script tag

My goal is to access the names of files within a specific path. I have successfully written JavaScript code that achieves this when executed separately, but encounters issues when integrated into HTML. fs = require('fs'); var directory = 'I ...

What is the best way to conceal the URL of a link leading to a file?

My website is built with C#, Kendo MVC, Razor and features a Kendo grid where one of the cells contains a hyperlink to a PDF file. The issue I'm facing is that when users click on the link, the URL is visible in the browser and can be altered to acces ...

The red solid outline of 1px is not functional when attempting to enlarge on hover

Recently, I stumbled upon a PSD design that really caught my eye. https://i.sstatic.net/R46Ko.jpg It inspired me to create a website similar to . One feature I particularly liked was how a circle appeared when hovering over a link. Plus, I plan on using ...

Avoiding the impact of links to anchors within a child div on the main URL

Take a look at the code snippet below: <div id="help"></div> <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> <script> var loadPage = function (){ $("#help").load("http:/ ...

What could be the reason that angularjs html template requests aren't appearing in the top websites when viewed in a

After referring to the link , I discovered a way to determine which programming tools different sites use for application development. However, when I debug HTTP requests using Firebug, I noticed that HTML requests are not explicitly shown in the log. Alt ...