2016-04-27 20 views
3

Ich habe den folgenden Code (JSFiddle):verteilen Tasten in div gleichmäßig

HTML:

<div id="content"> 
    <div id="mainBox" class="textBox"> 
    <div id="mainMenuBar"> 
     <button class="jqueryUIButton">New Diagnosis</button> 
     <button class="jqueryUIButton">My Diagnosises</button> 
     <button class="jqueryUIButton">My Account</button> 
    </div> 
    </div> 
</div> 

CSS:

#mainMenuBar { 
    background: linear-gradient(to bottom right, #30273a, #8d78a5); 
    padding: 5px; 
    -webkit-border-radius: 0px; 
    -moz-border-radius: 0px; 
    border-radius: 0px; 
    resize: none; 
    border:1px solid #30273a; 
    box-shadow: 0 0 10px #8d78a5; 
    border-radius: 15px 15px 15px 15px; 
} 

#content { 
    margin: 0 auto; 
    margin-top: 100px; // former 250px 
    padding: 0; 
    width: 750px; 
    max-width: 80%; 
    padding-bottom: 40px; 
    text-align: center; 
} 

JS:

$(".jqueryUIButton").button(); 

Jetzt befinden sich die drei Tasten in der horizontalen Mitte der DIV-Box. Aber ich möchte, dass sie gleichmäßig über die ganze Breite verteilt sind. Wie kann ich das machen?

Ich würde jeden Tipp lieben. Vielen Dank!

Antwort

4

einfach the flexbox model verwenden:

display: flex; 
justify-content: space-around; 

Sie auch space-between und spielen mit Margen und Polsterung für eine fein abgestimmte Optik verwenden können.

Modified fiddle

+0

Dank! Das hat es gelöst. Perfekt! :-) – progNewbie

+0

Nur eine Warnung: Es ist nicht auf alten Versionen von IE verfügbar. Sie müssen prüfen, ob es ein Problem ist oder nicht. –

+0

Danke für die Warnung. Aber wenn es nur alte IE-Versionen sind, sollte dies kein Problem sein. :-) – progNewbie

0

FlexBox zur Rettung:

#mainMenuBar { 
 
    background: linear-gradient(to bottom right, #30273a, #8d78a5); 
 
    padding: 5px; 
 
    -webkit-border-radius: 0px; 
 
    -moz-border-radius: 0px; 
 
    border-radius: 0px; 
 
    resize: none; 
 
    border:1px solid #30273a; 
 
    box-shadow: 0 0 10px #8d78a5; 
 
    border-radius: 15px 15px 15px 15px; 
 
    display: flex; 
 
    justify-content: space-around; 
 
} 
 

 
#content { 
 
    margin: 0 auto; 
 
    margin-top: 100px; // former 250px 
 
    padding: 0; 
 
    width: 750px; 
 
    max-width: 80%; 
 
    padding-bottom: 40px; 
 
    text-align: center; 
 
}
<div id="content"> 
 
    <div id="mainBox" class="textBox"> 
 
    <div id="mainMenuBar"> 
 
     <button class="jqueryUIButton">New Diagnosis</button> 
 
     <button class="jqueryUIButton">My Diagnosises</button> 
 
     <button class="jqueryUIButton">My Account</button> 
 
    </div> 
 
    </div> 
 
</div>

1

Das ist für Flexbox eine typische Anwendung ist:

https://jsfiddle.net/aj88xck2/

Fügen Sie einfach display: flex; und justify-content: space-around; (oder Leerzeichen dazwischen) zum Container hinzu.

+1

Wie unterscheidet sich das von Denys? –

+0

@PraveenKumar offensichtlich schrieb ich etwas langsamer, so dass die andere Antwort zuerst angezeigt wurde. – Johannes

+0

4 Minuten Unterschied? : P –

-2

<button class="jqueryUIButton" style="height:20px; width:145px">New Diagnosis</button>

Works 100%

** The length of the bar is 440px, divided by 3 you get 145px; ** 
+0

Auch ist 146 näher an der Realität. –

Verwandte Themen