Basic CSS text overlay on top of images

Hey there! I'm in need of some assistance with displaying text over an image. Specifically, I'd like the text to appear on the left side of the two people in the image and remain proportional when transitioning from desktop to tablet view using media queries.

Below is my HTML:

<figure><img src="Sources/USE/colors.png">

    <figcaption><h1>Your P<span class="orange">a</span>rtner in<br><br><span class="all"="colorstxt"><span class="green">C</span><span class="yellow">o</span><span class="orange">l</span><span class="red">o</span><span class="pink">r</span><span class="purple">s</span></h1></figcaption>

    </figure>

And here is my CSS code:

#hero_container figure{
    position: static;
}   

#hero_container figure figcaption{
    position: relative;
    top: 200px;
    left: 100px;
}

I've experimented with both absolute and relative positioning, but unfortunately, it causes other elements on the page to shift around below the image. If anyone has any solutions or suggestions for this simple issue, I would greatly appreciate it!

Answer №1

Just a little more to go...

Don't forget to set the figure to have a position: relative; and make sure the caption is absolutely positioned.

#hero_container figure{
    position: relative;
}   

#hero_container figure figcaption{
    position: absolute;
    bottom: 10%;
    left: 10%;
}

Answer №2

By default, HTML elements are in static positioning. To have more control over the placement of a figure caption, consider using relative positioning on the figure element.

#hero_container figure{
position: relative;
} 

Answer №3

By default, the position of an element is static. To properly position a figure, use relative positioning, and for the caption, use absolute positioning as shown:

#main_image_container figure{
    position: relative;
}   

#main_image_container figure figcaption{
    position: absolute;
    top: 150px;
    left: 50px;
}

Answer №4

Check out the updated code below:

HTML

<div class="picture">
    <img src="Images/placeholder.jpg" alt="" />
    <h2><span>Your Trusted<span class='space'></span><br /><span class='space'></span>Partner</span></h2>
</div>

CSS

.image {
   position: relative;
   width: 100%; /* required for IE 6 */
}

h2 {
   position: absolute;
   top: 200px;
   left: 0;
   width: 100%;
}


h2 span {
   color: white;
   font: bold 24px/45px Helvetica, Sans-Serif;
   letter-spacing: -1px;
   background: rgb(0, 0, 0); /* default color */
   background: rgba(0, 0, 0, 0.7);
   padding: 10px;
}

h2 span.space {
   padding: 0 5px;
}

Answer №5

Have you considered using a div with a float left and a higher z-index instead? It might be a more straightforward solution.

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 other option is there instead of using a span tag?

Take a look at this illustration. <span id="s1">Goodbye</span> <span id="s2">cruel</span> <span id="s3">world</span> <span id="s4">this</span> <span id="s5">is</span> <span id="s6">a</sp ...

CSS - owl carousel automatically stretches images to full width

Here is the code snippet that I am working with: $(document).ready(function() { $('.owl-carousel').owlCarousel({ loop:true, items:4, autoplay:true, autoplayTimeout:2000, autoplayHoverPause:true }); }); #owl-demo ...

Splitting the string into individual characters using string.split("").map may cause layout issues on small devices

Shoutout to @pratik-wadekar for the amazing help in creating a working text animation. However, I encountered an issue when testing it on various screen sizes and mobile devices - the animated word plants breaks into pieces like PLA on one line and NTS on ...

using CSS to position elements that are generated dynamically

Hey there, I'm facing a little issue with my elements. These elements are being generated dynamically and I'd like to display them in a 4 column layout. The challenge is that they arrive separately and I can't simply wrap them in a div and u ...

Moving from one page to another

I am attempting to create a transition effect between sections within a single-page application. All the sections are contained on the same page, with only one section displayed at a time while the rest are set to display none. When a specific event is tri ...

Turn off automatic compilation for LESS styling

In my Eclipse environment, I am looking to have LESS compile only when explicitly triggered by mvn package. Currently, any changes made in my less file immediately update the CSS. How can I prevent this automatic behavior? <plugin> <groupId> ...

What could be causing my mobile page to require two scrolls?

I've encountered a peculiar issue where users need to scroll twice or the page gets stuck on mobile devices that are less than 600px wide. I've attempted the following solutions with no success. I am a complete novice, so please excuse my lack of ...

Responsive design is key in ensuring that Bootstrap columns adjust accordingly

I am attempting to create a responsive block in the center of my webpage with the help of Bootstrap. However, I am having trouble getting the columns to respond correctly to my bootstrap setup. Can anyone point out what I might be doing wrong? <lin ...

Displaying a variable in HTML using PHP before it's actually declared

I have a webpage named search.php My goal is to customize the title/tab tag of the page to display the number of items found along with "Mysearch". Here's what I want it to look like: <head> <title><?php echo $number_count; ?> it ...

Retrieving inline CSS value using jQuery

How do I retrieve the inline-css value of the second child within div #one using jQuery. <li id="one"> <h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia, velit!</h2> <div style="width: 1425px; height: 1080px ...

Hiding a related field using a designated delimiter can be achieved with JavaScript

I am looking to create a function that hides the corresponding textarea field of a dropdown. This functionality will be utilized in multiple instances, hence the need for it to be within a function. <div id="formElement1" class="field"> <labe ...

Modifying the href attribute of a hyperlink with jQuery

Is it possible to modify the href attribute of a hyperlink using jQuery? ...

Transforming a datetime-local Element into a Date Object

I am currently utilizing the HTML5 element datetime-local with the requirement of having two different formats for the date. One format will be stored as a date object in the database, while the other format will be used as a string to set the datetime-loc ...

Is there a way to access a CSV file containing a comprehensive list of days and months?

I am in the process of designing a booking form for a website, and the client has specified that they prefer a drop-down menu for selecting dates rather than a traditional calendar. To achieve this, I plan to utilize gravity forms. For the date options, I ...

Implementing the right-to-left direction for several inline spans

My issue involves two inline spans containing English letters that I need to display in a right-to-left (RTL) direction. Unfortunately, the webpage is not rendering the spans correctly. Here is the text in the first span: <span>4 Series Gran Coupe&l ...

Grab the SVG and resize it to a smaller scale

I have a small application built using Raphael.js that creates a node network with SVG and reorganizes it based on user selections. My goal is to capture the SVG image I've created and display it in a "mini-map" format at the bottom of the screen. Si ...

SCORM: moving between SCOs by clicking a button in the presentation

Currently, I am developing a website that allows users to create presentations. One of the website's features is the ability to export presentations in SCORM format (either 1.2 or 2004). This is my first time working with SCORM and I am currently impl ...

Creating an interactive Bootstrap 4 accordion with Vue.js: Step-by-step guide

I am currently utilizing Bootstrap 4 (jQuery is also installed) to develop an accordion feature in combination with Vue.js The challenge I am facing is related to using the v-for directive on the card I intend to replicate for each item in a JSON file. Th ...

Ways to create a scrolling effect for a datalist dropdown menu

My HTML datalist shows various career paths, but the number of options is too long. I want to add a scrolling effect to it. I have looked for ways to do this, but I read that CSS cannot be applied to datalists. Is it possible to apply styles using jQuery i ...

Mastering Kendo UI in Vue: The Ultimate Guide to Managing Child Checkboxes in TreeView

I am currently utilizing Telerik's Vue wrappers for Kendo UI. With the TreeView control, both the jQuery version and MVC wrappers have a feature that allows a property to automatically check child checkboxes when the parent checkbox is checked. ...