Is there a way to overlay a rounded image tag on top of two div elements in React Native?

I am looking to design a profile page featuring a rounded image placed on top of two divs in a 30:70 ratio. The top div will be empty while the bottom div will display some items. I have experimented with various code snippets found online.

<View style={{ flex: 1, flexDirection: 'column', backgroundColor: 'green', justifyContent: 'flex-start', alignItems: 'flex-start' }}>
        <View style={{ flexDirection: 'column', justifyContent: "flex-start", alignItems: "flex-start", alignSelf: "flex-start" }}>
            {/* <View style={{ flex: 1, flexDirection: 'row', alignItems: 'flex-end', alignSelf: 'flex-start', margin: 1 }}> */}
                <View style={{ backgroundColor: 'white', borderRadius: 10, flexDirection: 'column', height: "30%", width: "100%" }}></View>
            {/* </View> */}
            <View style={{ flex: 1, flexDirection: 'row', alignItems: 'flex-start', alignSelf: 'flex-start', margin: 1 }}>
                <View style={{ backgroundColor: 'white', borderRadius: 10, flexDirection: 'column', height: "70%", width: "100%" }}></View>
            </View>
        </View>

        <View style={{ justifyContent: 'center', alignItems: 'center', alignSelf: 'center', position: 'absolute' }}>
            <View style={{
                backgroundColor: 'blue',
                borderRadius: 10, height: 100, width: 100, borderRadius: 100 / 2
            }}></View>
        </View>
    </View>

reference image

Answer №1

After reviewing the image provided... Two different perspectives can be considered when setting the profile avatar style to:

{
  position: 'absolute',
  alignSelf: 'center',
  etc..
}

For a quick demonstration, visit:

App.js

import React, { Component } from 'react';
import { Text, View, StyleSheet, ImageBackground, Image } from 'react-native';
import { Ionicons, FontAwesome } from '@expo/vector-icons';

import Constants from 'expo-constants';
import { avatar, background } from './data';

export default class App extends Component {
  renderRow({ action, icon, fontAwesome = false }) {
    return (
      <View style={styles.actionRow}>
        {fontAwesome 
          ? <FontAwesome name={icon} size={25} /> 
          : <Ionicons name={icon} size={32} />}
        <Text style={styles.text}>{action}</Text>
      </View>
    );
  }

  render() {
    return (
      <View style={styles.container}>
        <ImageBackground source={background} style={styles.background}>
          <Image source={avatar} style={styles.avatar} />
        </ImageBackground>
        <View style={styles.content}>
          {this.renderRow({ action: 'Scanner', icon: 'ios-camera' })}
          {this.renderRow({
            action: 'Profile',
            icon: 'user-circle-o',
            fontAwesome: true,
          })}
        </View>
      </View>
    );
  }
}

Your styles:

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  background: {
    width: '100%',
    height: 130,
  },
  content: {
    flex: 1,
    marginTop: 80,
    marginHorizontal: 10,
  },
  avatar: {
    width: 100,
    height: 100,
    borderRadius: '50%',
    borderWidth: 0.7,
    borderColor: 'black',
    position: 'absolute',
    alignSelf: 'center',
    marginTop: 80,
  },
  actionRow: {
    width: '100%',
    height: '50',
    flexDirection: 'row',
    alignItems: 'center',
    margin: 10,
  },
  text: {
    marginLeft: 15,
    fontWeight: '500',
  },
});

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

Utilizing the Primevue theme for a fresh new look

Update: Since I couldn't resolve the issue, I decided to switch back to Vue2 and opted for Vuetify instead of Primevue. I'm new to Vue and chose Vue3 for my project, which is related to my master's thesis. Due to a lack of UI libraries comp ...

Attempting to create a slider utilizing jQuery

I'm currently working on creating a slider using jquery. I have downloaded the cycle plugin for the slider and included it in my file. The slider consists of 7 pictures. Below is the code I am using, can someone please help me identify any issues? &l ...

Is one round the limit for my JavaScript image slider?

After studying the JavaScript Chapter on W3Schools, I attempted to create an image slider. Initially, everything worked perfectly for the first cycle. For instance, when I clicked the next button, the slides continued to slide until the end of the slidesho ...

Arrange the header and input within a div using flexbox to achieve different alignments

I need help aligning the header section vertically and ensuring responsiveness. Using margin-top isn't fully responsive, so I want to align the header at the beginning of the input field.https://i.sstatic.net/w3xSP.jpg { margin: 0px; paddin ...

Tips for integrating a vertical menu with button icons and subcategories

Currently working on a project with Twitter Bootstrap and looking to create a specific sidebar setup. My goal is to include subcategories using an accordion and a collapsible menu for mobile devices. I came across a similar implementation at http://jsfiddl ...

Top method for customizing w2ui grid appearance

While utilizing the w2ui grid to showcase data in a table, I've found it to be quite effective. However, I'm not entirely happy with the appearance of the table itself. Are there any methods available for styling the table that don't involve ...

When you apply margins in CSS and HTML, it can cause elements to break out of the row alignment

I'm struggling with my html code that contains elements arranged in rows: <div class = "row"> <div class="col-sm-3 cont-box"> <h1>Title1<h1> </div> <div class="col-sm9 cont-box"> <img src="onepic.jpeg" class=" ...

What is the correct way to reset the styling of a web browser element, such as a <button>?

I have come across many sources advising me to reset HTML by manually resetting numerous individual properties, as demonstrated here: https://css-tricks.com/overriding-default-button-styles/ Another approach I discovered in CSS is simply using: button: {a ...

Arranging divs in a stack and implementing a toggle function for displaying and hiding them

I am currently enrolled in a web development course and am eager to explore beyond the limitations of the class. I successfully created a jQuery slide show in one div, and now I want to showcase additional features in two other divs, stack them together in ...

Maximizing the number of divs arranged horizontally in HTML while utilizing the full line width

My website consists of several fixed-width div elements that are styled to flow inline using the display type inline-block. This layout creates empty space at the end of the line where subsequent div elements cannot be accommodated and have to wrap to the ...

Adding CSS files to a JSP page in a Struts2 application

Hello, I am currently learning Java and working on a Struts2 project. I have added a stylesheet in the following path: /WEB-INF/common/css/style.css and also included Bootstrap in this directory: /WEB-INF/common/css/bootstrap/bootstrap.min.css I ...

Is using tables still considered a recommended practice for organizing a layout such as the one shown in the [IMG]?

Looking for recommendations on arranging images in the footer, in line with the design mockup using HTML/CSS. Wondering if tables are still a viable option for this purpose? ...

Update the hover functionality to only trigger on small screens when clicked

Is there a way for the text content to change from appearing on hover of an image to opening with a click in the mobile version? <div class="program prog-image" style="background-image: url(https://imagevars.gulfnews.com/2019/07/23/Timberwolf_16c1de355 ...

Images with full-width will scroll horizontally

Is there a way to fix the horizontal scroll issue? <!DOCTYPE html> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="https:// ...

Something isn't quite right - Mobile Compatibility not functioning

I have been developing a website and running into an issue with the header. It works fine on desktop and is responsive, but on mobile devices, the Bootstrap functionality seems to be missing. I've included my code below, could someone please help me i ...

How can I create responsive buttons with icons using material-ui?

I'm working with a material-ui Button that has a startIcon, and I need to hide the button text on smaller screens while still showing the icon. One common solution would be to use the useMediaQuery hook to identify the browser size and render a diffe ...

Displaying error message dynamically using ajax

I am looking to customize the way error messages are displayed on my form. Instead of having one generic div above the whole form, I want the error messages to appear next to each input field. <div id="response"><!--This section will show error ...

Exploring the possibilities of toggling between a personalized CSS design and a Bootstrap CSS layout

Is it possible to implement a dropdown menu on my sample-page using javascript/jquery in order to switch between a custom layout and a bootstrap layout? ...

The fixed div transforms its content when other divs move through it during scrolling

I am looking to create a fixed div at the top of a layout that will display information about a blog post, such as the date posted, number of notes, and permalink. As users scroll past different posts, I want this fixed div to update with the relevant in ...

Creating an accessible order for the next and back buttons

Currently, I am working on designing the user interface for a checkout flow. Towards the end of the page, there are 3 buttons available - Next, Back, and Cancel. When viewed on a desktop, the button layout appears as follows: (Back) (Next) Cancel http ...