1

In React I have an inline-flex parent element that contains a hyperlinked image and a support email URL. I want the support email URL element's width to MANDATE the width of the parent element and subsequently of the image as well. Meaning all the element width's must be the same as the support element's width.

This is what I have so far but it's not working. I'm not very good at CSS:

import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';

const ProviderContainer = styled.div`
    margin: auto
    align-items: center;
    justify-content: center;
    display: inline-flex;
    flex-direction: column;
    font-family: Lato;
    font-size: 22px;
    font-weight: normal;
    font-style: normal;
    font-stretch: normal;
    line-height: normal;
    letter-spacing: normal;

    border: 2px solid;
    border-color: #747162;
`;

const ProviderSupport = styled.a`
    margin:10px 0;
    display: inline-table;

    border: 2px solid;
    border-color: #747162;
`

const ImageContainer = styled.div`
    border: 2px solid;
    border-color: #747162;
    flex-basis: 100%
`

const Provider = (props) => (
    <ProviderContainer>
        <ImageContainer>
            <a href={props.ProviderLink}>
                <img style={{width:'100%'}} src={props.ProviderLogo}></img>
            </a>
        </ImageContainer>
        <ProviderSupport href={`mailto:${props.ProviderSupport}`}>{props.ProviderSupport}</ProviderSupport>
    </ProviderContainer>
);

Provider.propTypes = {
    ProviderLink: PropTypes.string,
    ProviderLogo: PropTypes.string,
    ProviderSupport: PropTypes.string
};

export default Provider;

The borders are just so I can get an idea of the box size
This is the issue that can pop up if the image is too big:enter image description here

Here's a transpiled fiddle example: https://jsfiddle.net/uj5d4621/2/

Izak Joubert
  • 906
  • 11
  • 29

2 Answers2

1

Borrowed from this Q&A

.parent {
  background: pink;
  display:inline-flex;
  flex-direction:column;
  margin:1em;
  vertical-align:top;
}

a, img {
  width:0;
  min-width:100%;
}
<div class="parent">
  <a href="#"><img src="http://www.fillmurray.com/300/200" alt=""></a>
  <div class="description">
    http://www.fillmurray.com/
  </div>
</div>

<div class="parent">
  <a href="#"><img src="http://www.fillmurray.com/300/200" alt=""></a>
  <div class="description">
    http://www.longhyperlinknamegoeshere.com/
  </div>
</div>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
0

I do not work with react so I have a little trouble reading your code but in my opinion it is enough to add a width to your element.

const ProviderSupport = styled.a`
    margin:10px 0;
    display: block;
    width: 100%;
    border: 2px solid;
    border-color: #747162;
`
ag-dev
  • 213
  • 2
  • 12