2016-12-01 1 views
0

Ich habe unterhalb des HTML-Snippets eingefügt, das ein div mit einer Containerklasse aus vier Subdivs mit einer Klasse namens 'city' hat.Textfelder (CSS-Rahmen) von div-Tags können nicht in einer geraden Linie ausgerichtet werden.

Ich versuche, sie in einer Zeile durch Anwenden von Bootstrap auszurichten.

Ich habe mein Stylesheet unter den HTML-Code eingefügt. Ich habe dies seit über einer Stunde versucht, indem ich den rechten/linken Rand vergrößert und verkleinert habe, aber es nicht richtig machen kann.

<!DOCTYPE html> 
 
<html lang="en-us"> 
 
<head> 
 
    <link rel="stylesheet" type="text/css" href="./index.css"> 
 
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css"> 
 
</head> 
 
<body> 
 

 
<div class="container"> 
 
    <h1 id="cities">Cities Of The World</h1> 
 
    <div class="city"> 
 
    <h2>London</h2> 
 
    <p>London is the capital city of England.</p> 
 
    <p>It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p> 
 
    </div> 
 

 
    <div class="city"> 
 
    <h2>Paris</h2> 
 
    <p>Paris is the capital of France.</p> 
 
    <p>The Paris area is one of the largest population centers in Europe, with more than 12 million inhabitants.</p> 
 
    </div> 
 

 
    <div class="city"> 
 
    <h2>Tokyo</h2> 
 
    <p>Tokyo is the capital of Japan.</p> 
 
    <p>It is the center of the Greater Tokyo Area, and the most populous metropolitan area in the world.</p> 
 
    </div> 
 

 
    <div class="city"> 
 
    <h2>New York</h2> 
 
    <p>The City of New York is the most populous city in the United States.</p> 
 
    <p>New York is an important center for international diplomacy and has been described as the cultural and financial capital of the world.</p> 
 
    </div> 
 
</div> 
 
</body> 
 
</html>

#cities { 
    text-align: center; 
    padding: 20px; 
} 
.city { 
    display: inline-block; 
    margin: 10px; 
    padding: 15px; 
    max-width: 250px; 
    height: 300px; 
    border: 1px solid black; 
} 

Antwort

0

Verwenden CSS Flexbox:

Wickeln Sie Ihre .city in ein Elternteil <div> (in meinem Fall .city-holder) einen flexiblen Behälter. Wie:

.city-holder { 
    display: flex; 
} 

Werfen Sie einen Blick auf das Snippet unten:

.city-holder { 
 
    display: flex; 
 
}
<!DOCTYPE html> 
 
<html lang="en-us"> 
 
<head> 
 
    <link rel="stylesheet" type="text/css" href="./index.css"> 
 
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css"> 
 
</head> 
 
<body> 
 

 
<div class="container"> 
 
    <h1 id="cities">Cities Of The World</h1> 
 
    <div class="city-holder"> 
 
    <div class="city"> 
 
    <h2>London</h2> 
 
    <p>London is the capital city of England.</p> 
 
    <p>It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p> 
 
    </div> 
 

 
    <div class="city"> 
 
    <h2>Paris</h2> 
 
    <p>Paris is the capital of France.</p> 
 
    <p>The Paris area is one of the largest population centers in Europe, with more than 12 million inhabitants.</p> 
 
    </div> 
 

 
    <div class="city"> 
 
    <h2>Tokyo</h2> 
 
    <p>Tokyo is the capital of Japan.</p> 
 
    <p>It is the center of the Greater Tokyo Area, and the most populous metropolitan area in the world.</p> 
 
    </div> 
 

 
    <div class="city"> 
 
    <h2>New York</h2> 
 
    <p>The City of New York is the most populous city in the United States.</p> 
 
    <p>New York is an important center for international diplomacy and has been described as the cultural and financial capital of the world.</p> 
 
    </div> 
 
    </div> 
 
</div> 
 
</body> 
 
</html>

Oder verwenden Bootstrap Grids:

Verwenden col-xs-*, Blick auf das Snippet unten:

<!DOCTYPE html> 
 
<html lang="en-us"> 
 
<head> 
 
    <link rel="stylesheet" type="text/css" href="./index.css"> 
 
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css"> 
 
</head> 
 
<body> 
 

 
<div class="container"> 
 
    <h1 id="cities">Cities Of The World</h1> 
 
    <div class="row"> 
 
    <div class="col-sm-3 city"> 
 
    <h2>London</h2> 
 
    <p>London is the capital city of England.</p> 
 
    <p>It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p> 
 
    </div> 
 

 
    <div class="col-sm-3 city"> 
 
    <h2>Paris</h2> 
 
    <p>Paris is the capital of France.</p> 
 
    <p>The Paris area is one of the largest population centers in Europe, with more than 12 million inhabitants.</p> 
 
    </div> 
 

 
    <div class="col-sm-3 city"> 
 
    <h2>Tokyo</h2> 
 
    <p>Tokyo is the capital of Japan.</p> 
 
    <p>It is the center of the Greater Tokyo Area, and the most populous metropolitan area in the world.</p> 
 
    </div> 
 

 
    <div class="col-sm-3 city"> 
 
    <h2>New York</h2> 
 
    <p>The City of New York is the most populous city in the United States.</p> 
 
    <p>New York is an important center for international diplomacy and has been described as the cultural and financial capital of the world.</p> 
 
    </div> 
 
    </div> 
 
</div> 
 
</body> 
 
</html>

hoffe, das hilft!

+0

Ja. Das hilft. Danke. –

Verwandte Themen