2016-04-04 1 views
1

Verwirrt, wie man den Namen des Eingabefeldes mit dem "Choose file" -Dialog & der vorherigen Uploads ordentlich ausrichtet. Irgendwelche Tipps?Flexbox Ausrichtungstyp = Dateikästen

Auf der Suche nach einer einfachen, eleganten Lösung.

.inputs { 
 
    display: flex; 
 
    flex-direction: column; 
 
    margin: 3em; 
 
    align-items: left; 
 
    justify-content: left; 
 
} 
 
label { 
 
    padding: 1em; 
 
    margin: 0.3em; 
 
    border: thin solid black; 
 
    border-bottom-right-radius: 1em; 
 
}
<div class=inputs> 
 
    <label>Form 1 
 
    <input type=file name=form24><a href=#>Previous upload 1</a> 
 
    </label> 
 

 
    <label>Form something else 
 
    <input type=file name=form24><a href=#>Named upload</a> 
 
    </label> 
 

 
    <label>Form blah 
 
    <input type=file name=form24><a href=#>Previous upload</a> 
 
    </label> 
 

 
</div>

Antwort

1

.inputs { 
 
    display: flex; 
 
    flex-direction: column; 
 
    margin: 3em; 
 
    /* align-items: left;   <-- "left" is not a valid value */ 
 
    /* justify-content: left;  <-- "left" is not a valid value */ 
 
} 
 

 
label { 
 
    display: flex;     /* establish nested flex container */ 
 
    padding: 1em; 
 
    margin: 0.3em; 
 
    border: thin solid black; 
 
    border-bottom-right-radius: 1em; 
 
} 
 

 
label > * { 
 
    flex: 1;      /* distribute container space evenly among flex items */ 
 
}
<div class=inputs> 
 
    
 
    <label> 
 
    <span>Form 1</span><!-- wrap text in a span so it can be targeted by CSS --> 
 
    <input type=file name=form24> 
 
    <a href=#>Previous upload 1</a> 
 
    </label> 
 

 
    <label> 
 
    <span>Form something else</span> 
 
    <input type=file name=form24> 
 
    <a href=#>Named upload</a> 
 
    </label> 
 

 
    <label> 
 
    <span>Form blah</span> 
 
    <input type=file name=form24> 
 
    <a href=#>Previous upload</a> 
 
    </label> 
 

 
</div>

+0

Danke, obwohl ich bemerkte, dass es leicht außerhalb der Grenze gehen, vor allem, wenn es mehrere vorherigen Uploads, z.B. https://hendry.jsbin.com/ganoru/ – hendry

+0

, um Ihre Etiketten außerhalb der Grenzen zu beheben hinzufügen, flex-wrap: wrap; in Ihrer Label-Klasse und das wickelt alles in kleinere Auflösungen/Geräte –

+0

@hendry, ziehen Sie in Betracht, die 'flex-basis' -Eigenschaft anstelle von' flex-grow' zu verwenden, um stabilere Breiten für die Flex-Elemente zu setzen. Mit 'flex-basis' können Sie eine präzise Ausrichtung zwischen den Spalten sicherstellen: https://jsbin.com/rujodevaki/1/edit?html,css,output –