Adjust the size of flexbox elements as the browser width varies

Is there a way to make the content within my flexbox adjust in size as I resize the browser window? This means having both words and images shrink proportionally.

My flexbox contains two elements: text on the left, and an image on the right.

<div id="flexbox">
    <div id="text">
        Some text
    </div>
    <img src="images/img.png" alt="" id="image" width="400px" height="414px">
</div>

#flexbox {
    background-image:url("images/board.png");
    width:100%;
    display:flex;
    flex-flow:row no-wrap;
    justify-content:space-between;
}

#text {
    margin-left:10%;
    width:40%;
}

#image {
    margin-right:10%;
}

Currently, the font size and image size are fixed, causing the image to be cut off when resizing the browser, while the text expands vertically. Is there a solution for this issue?

Answer №1

If you aim for a website with responsive design, it means making sure your web page looks good on any browser or device. To achieve this, you can start by resizing images proportionally by setting their width and height to a specific percentage of their container, which should also be sized as a percentage of its own container, and so forth. Adjusting text size based on the window's dimensions is a bit more challenging, requiring the use of media queries.

Explore a tutorial on responsive design like the one found here, and make sure to click through to the next chapters to gather all necessary information on the topic. Dive into how media queries can help you set the font-size property accordingly based on specific criteria aligned with your preferences and requirements.

Answer №2

Take a look at this DEMO

#flexbox { 
display: flex;
margin: 5%;
}

#text { 
font-size: 10vw; 
}

#image { 
height: 40vw;
width :40vw;
}
<div id="flexbox">
    <div id="text">Some text</div>
   <img src="https://upload.wikimedia.org/wikipedia/commons/8/82/Dell_Logo.png" id="image" width="400" height="414" alt="">
</div>

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

Attempting to execute JavaScript within HTML files that have been incorporated using Angular

My website has a menu designed in HTML, and instead of manually adding it to each page (which would make updating changes tedious), I am using Angular to include it dynamically (<div ng-include="menu.html"></div>). I've got some JavaScrip ...

How can a JQuery function be used with SVG to trigger a second animation immediately after the first animation is finished?

For the handwriting effect animation, I utilized the animation-delay technique by dividing the object wherever it intersected, drawing paths, and converting them into clipping masks. This involved breaking the letter "W" into four parts, creating different ...

Verify the compatibility of the device with ScreenOrientation.lock() function - An error occurred indicating that screen.orientation.lock() is not supported on this particular device

I've been trying to implement ScreenOrientation.lock() according to the documentation, but I'm having trouble getting it to work correctly. https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/lock When I use window.screen.orienta ...

Arranging Data Table

I'm working on sorting my bootstrap-datatable using the HTML5 attribute data-order, but it doesn't seem to be functioning correctly. I want the largest Work Order Number to be displayed first. Could someone assist me and point out what mistake I ...

My CSS code is not successfully positioning the items to the right, despite my best efforts

I'm currently working on a website project and facing an issue with aligning the text 'Axxon' to the left of the div-header-gradient class, and the a href positioned to the right of the header. However, my code doesn't seem to be workin ...

Unable to locate the image file

I'm facing an issue with displaying a .PNG image in a list item within an unordered list. Here's the code snippet causing the problem: $pngFilename= 'C:/xampp/htdocs/myProj/' . 'just_a.png'; echo 'pngFilename is "', ...

What is causing the QJsonValue(undefined) to be returned?

After sending a request to the API for bid price, I am receiving an undefined QJsonValue and unable to display it later. Can anyone help me pinpoint where I might be going wrong? { QApplication a(argc, argv); MainWindow w; w.show(); QNetwor ...

Having difficulty customizing the color of bullet points within a list

I've been attempting to update the color of the list points without success. Can you help me troubleshoot? <div class="mobile-menu" id="mobile-menu"> <div id="mobile-menu-links"> <h4>General:</h4> ...

Creating an X pattern on an HTML5 canvas and detecting intersections with a perimeter

I am currently developing a maze game using HTML 5. Below is the function I have implemented to draw an "X" on the canvas (the player will guide the X through the maze using touchpad). dim = 8; function rect(x,y,xdim){ ctx.beginPath(); ctx.moveT ...

Utilizing tables to perfectly position text and dropdown options within a form

Although I know using tables is not ideal, it seems to be the most practical solution in this case. I'm attempting to align text and dropdown menus in a form. The challenge arises when the text can vary from one line to two lines, making it difficult ...

Calculate the sum of a column in a table that is dynamically populated

I'm using jQuery to load a table with data: function getSales(customerId, fromDate, toDate){ $.ajax({ type: 'POST', url: 'ajax/sale_pl.php', data:{customer_id:customerId, from_date:fromD ...

The CSS attribute selector is unable to target dynamically appended class names

Utilizing React's CSS animations add-on has been a seamless process, with everything running smoothly when using the provided classnames. .quote-enter { opacity: 0.01; transition: opacity .25s ease-in; } .quote-enter.quote-enter-active { opaci ...

How can I turn off the width for carousel control buttons in Bootstrap?

I am encountering a problem with the carousel control buttons in Bootstrap, as shown in this image: https://i.sstatic.net/olfKU.png However, when I disable the width: 15% property in the devTools on Chrome, the issue resolves itself: https://i.sstatic.net ...

Display the integer value in a div element using PHP

echo "<td>".$value["rating"]."<div class=ratingOutput data-average=".$rates." **data-id="$value["id"]"**></div>".$newline.$rateHere.$starOutput."</td>"; I need the value of data-id to be an integer, however, I encountered an error ...

What could be causing the span tag to not have CSS applied and the background image to not be displaying

The header I have created, shown in the image, is facing two issues. Firstly, I am unable to add ellipsis to the span tag even though I used it. I want the ellipsis to appear when the screen resolution is small. Secondly, the image uploaded is not displayi ...

Styling dialogue boxes in SAP UI5 with CSS

I am encountering an issue with customizing the style of a dialog pop-up in my SAP UI5 application. The XML structure of the dialog is as follows: <core:FragmentDefinition xmlns="sap.m" xmlns:core ="sap.ui.core" xmlns:html="http ...

Properly nested anchor elements with semantic meaning

I'm currently working on a web application where we are implementing inline editing. To illustrate the issue I'm trying to address, let's use the example of a Facebook post. For instance: Jennifer Lopez shared a new video The name "Jennif ...

Python Application Engine - Streamlining Responses from HTML Control Arrays

In my attempt to use App Engine (Python), I am facing a challenge in sending POST values from a variable array of select controls within an HTML form. Each select control is associated with a text describing what the user is rating. For instance, let&apos ...

Challenges associated with utilizing img src in JavaScript

I am facing a simple issue. I have carInfo data retrieved from a JSON file, but I am struggling to correctly parse the img source stored in the variable $imgsrc instead of treating it as a string called "$imgsrc". This data needs to be appended to my HTML ...

Tips on positioning div elements

I have successfully created a script that shows the preview of an uploaded image on the client-side along with the option to remove it. However, I am facing an issue with the UI design as the position of the close icon is not aligned to the top-right corn ...