div 클래스를 사용하여 블록을 정렬하는 방법은 무엇입니까?

Przemek Wojtas

대학 과제를위한 웹 사이트를 만들고 있습니다. 선생님은 CSS 코드를 줄이기 위해 div 클래스를 사용하라고했지만 여기에 문제가 있습니다. 이미지에 대한 div 클래스가 있으며 같은 행에서 서로 옆에 있어야합니다.

나는 이미지가있는 div 아래에 있어야하는 텍스트에 대한 또 다른 3 div 클래스 상자가 있으며 그중 하나는 왼쪽에 있고 다른 하나는 오른쪽에 있어야하므로 이탈리아 국기를 만듭니다. 할 수있는 모든 것을 시도했지만 여전히 제대로 작동하지 않습니다. 누구든지 도울 수 있습니까?

이것이 제가 대략 달성하고 싶은 것입니다.

http://jsfiddle.net/p2uwm8ye/

<!DOCTYPE html> <!-- This is standard HTML code that tells the browser it is a HTML page-->
<html lang="en-GB"> <!-- This tells the browser what language html is using-->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="CSS/style.css" rel="stylesheet" type="text/css"> <!-- This is linking style sheet (css)into this HTML page-->
    <title>Main Page</title> <!-- This is a code that displays title of the page-->
</head>
<body>
<header id="pageHeader"><!-- This header tag is used to create a navigation bar-->
    <nav id="site"><!-- This is a navigation tag which allows to link different webpages together-->
    <ul>
        <li><a href="index.html">Home Page</a></li>
        <li><a href="html/tables.html">Tables</a></li>
        <li><a href="html/forms.html">Feedback</a></li>
        <li><a href="html/text.html">About Us</a></li>
        <li><a href="html/references.html">References</a></li>
        <li><a href="html/validation.html">Validation</a></li>
    </ul> 
    </nav>
</header>
    <div id="welcome"><!-- This is a div tag that is used to create a welcome message on my website-->
    <h1>Papa Italiano</h1>
</div>
            <div class="images"><!-- This div class I have used to put three images using just one piece of css code which reduced the code-->
            <figure>
                <img src="images/image11.jpg" alt="photo" />
                <figcaption>Food 1</figcaption>  
            </figure>
        </div>
        <div class="images">
            <figure>
                <img src="images/image22.jpg" alt="photo" />
                <figcaption>Food 2</figcaption>
            </figure>
        </div>
        <div class="images">
            <figure>
                <img src="images/image32.jpg" alt="photo" />
                <figcaption>Food 3</figcaption>
            </figure>
        </div>
            <div class="text"></div><!-- similar to div class for images however this is for text-->
            <div class="text"></div>
            <div class="text"></div>
    <div class="clearing"></div><!-- this div class is basically making sure that my other div classes will not go into each other-->
</div>
        <div id="background">
            <figure>
                <img src="images/background1.jpg" alt="background photo" />
            </figure>
        </div>
        <div id="background2">
            <figure>
                <img src="images/background2.jpg" alt="background photo" />
            </figure>
        </div>
</body>
</html>

그리고 여기에 CSS가 있습니다.

header#pageHeader{
    position: absolute;
    top: 0px;
    left: 0px;
    width: 1024px;
    height: 80px;
    background-color: black;
    opacity: 0.5;
}/* this is my css for a navigation bar*/
nav#site li{
    list-style:none;
    display:inline-block;
    zoom:1;
    width:160px;
}/*This is used to style my links*/
nav a{
    text-decoration: none;
    color: #FF0;
}/* This is used to style look of the links*/
.images{
    float: left;
    width: 250px;
    border-style: solid;
    border-width: 3px;
    padding: 10px;
    margin: 30px;
    z-index: 1;
    vertical-align: middle;
}/*This is telling my all div class images how they need to be styled*/
#welcome{
    position: relative;
    top: 100px;
    left: 300px;
    width: 300px;
    height: 80px; 
    font: arial;
    font-size: 23px;
    color: green;
    margin-bottom: 75px;
}/*This is telling browser how to style my div welcome*/
.text{
    position: relative;
    height: 300px;
    width: 250px;
    left: 0px;
    float: left;
    border-style: solid;
    border-width: 3px;
    margin: 100px;
    display: inline-block;
}/*Similar to .images however this piece of codes is used for my text*/
#background{
    height: 80px;
    width: 250px;
    left: 0px;
}
#background2{
    height: 80px;
    width: 250px;
    right: 0px;
}
.clearing{
    clear: both;
}
비니

나는 당신이 원하는 모든 것을 이해했는지 확신하지 못하지만 도움이 될 것입니다. 코딩 기술을 향상 시키려면 다음에 대해 자세히 알아봐야합니다.

다음 코드를 연구하고 함께 플레이하여 어떻게 함께 작동하는지 더 잘 이해하십시오. 행운을 빕니다. 즐겁게 배우세요!

솔루션 1 (를 사용한 인라인 블록 해킹 <!--)

#pageHeader {
    background-color: grey;
    /* As there is nothing behind your #pageHeader, it is better to choose a grey color with no opacity */
    min-height: 80px;
}
nav {
    width: 90%;
    margin: 0 auto;
    /* This code will center your navigation bar. The 90% width will give it space. */
}
nav ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
}
nav li {
    display:inline-block;
    width: 16.6666666%;
    /* 100% (full-width) / 6 (as you have 6 elements in your nav bar) */
    text-align: center;
    vertical-align: middle;
}
nav a {
    text-decoration: none;
    color: #FF0;
}
nav a:hover {
    /* always define a style for your links when they are hovered. This is a suggestion of style. */
    border-bottom: 1px solid #FF0;
    padding-bottom: 3px;
}
.main { /* This is for your italian flag in the background. If you need to support more browser just use a compress image instead. Note that this code is not cross-browser, check required code on Mozilla Developer Network */
    background-image: -webkit-linear-gradient(to right, green 0%, green 33%, #fff 33%, #fff 66%, red 66%, red 100%);
    background-image: linear-gradient(to right, green 0%, green 33%, #fff 33%, #fff 66%, red 66%, red 100%);
}
.wrapper {
    /* you wrap your main elements so that you don't have to reproduce this style every time */
    width: 90%;
    margin: 0 auto;
    text-align: center;
}
h1 {
    font: arial;
    font-size: 23px;
    color: green;
    padding: 20px 0 75px;
    margin: 0;
}
.images {
    display: inline-block;
    width: 32%;
    /* 100% / 3 images per row */
    background-color: #e3e3e3;
    vertical-align: top;
}
.images figure {
    margin: 0;
}
img {
    width: 100%;
    height: auto;
}
figure figcaption, figure p {
    text-align: left;
}
<header id="pageHeader">
    <nav>
        <ul>
            <li><a href="index.html">Home Page</a></li><!-- 
            --><li><a href="html/tables.html">Tables</a></li><!-- 
            --><li><a href="html/forms.html">Feedback</a></li><!-- 
            --><li><a href="html/text.html">About Us</a></li><!-- 
            --><li><a href="html/references.html">References</a></li><!-- 
            --><li><a href="html/validation.html">Validation</a></li>
        </ul>
    </nav>
</header>
<section class="main">
    <div class="wrapper">
         <h1>Papa Italiano</h1>

        <div class="images">
            <!-- This div class I have used to put three images using just one piece of css code which reduced the code-->
            <figure>
                <img src="http://lorempixel.com/300/250/food" alt="photo" />
                <figcaption>Food 1</figcaption>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
            </figure>
        </div>
        <div class="images">
            <figure>
                <img src="http://lorempixel.com/300/250/food" alt="photo" />
                <figcaption>Food 2</figcaption>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
            </figure>
        </div>
        <div class="images">
            <figure>
                <img src="http://lorempixel.com/300/250/food" alt="photo" />
                <figcaption>Food 3</figcaption>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
            </figure>
        </div>
    </div>
</section>

솔루션 2 (를 사용한 인라인 블록 해킹 margin-right: -4px;)

#pageHeader {
    background-color: grey;
    /* As there is nothing behind your #pageHeader, it is better to choose a grey color with no opacity */
    min-height: 80px;
}
nav {
    width: 90%;
    margin: 0 auto;
    /* This code will center your navigation bar. The 90% width will give it space. */
}
nav ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
}
nav li {
    display:inline-block;
    width: 16.6666666%;
    /* 100% (full-width) / 6 (as you have 6 elements in your nav bar) */
    text-align: center;
    vertical-align: middle;
    margin-right: -4px; /* 2nd trick to remove space between inline-blocks) */
}
nav a {
    text-decoration: none;
    color: #FF0;
}
nav a:hover {
    /* always define a style for your links when they are hovered. This is a suggestion of style. */
    border-bottom: 1px solid #FF0;
    padding-bottom: 3px;
}
.main { /* This is for your italian flag in the background. If you need to support more browser just use a compress image instead. Note that this code is not cross-browser, check required code on Mozilla Developer Network */
    background-image: -webkit-linear-gradient(to right, green 0%, green 33%, #fff 33%, #fff 66%, red 66%, red 100%);
    background-image: linear-gradient(to right, green 0%, green 33%, #fff 33%, #fff 66%, red 66%, red 100%);
}
.wrapper {
    /* you wrap your main elements so that you don't have to reproduce this style every time */
    width: 90%;
    margin: 0 auto;
    text-align: center;
}
h1 {
    font: arial;
    font-size: 23px;
    color: green;
    padding: 20px 0 75px;
    margin: 0;
}
.images {
    display: inline-block;
    width: 32%;
    /* 100% / 3 images per row */
    background-color: #e3e3e3;
    vertical-align: top;
}
.images figure {
    margin: 0;
}
img {
    width: 100%;
    height: auto;
}
figure figcaption, figure p {
    text-align: left;
}
<header id="pageHeader">
    <nav>
        <ul>
            <li><a href="index.html">Home Page</a></li> 
            <li><a href="html/tables.html">Tables</a></li> 
            <li><a href="html/forms.html">Feedback</a></li> 
            <li><a href="html/text.html">About Us</a></li> 
            <li><a href="html/references.html">References</a></li> 
            <li><a href="html/validation.html">Validation</a></li>
        </ul>
    </nav>
</header>
<section class="main">
    <div class="wrapper">
         <h1>Papa Italiano</h1>

        <div class="images">
            <!-- This div class I have used to put three images using just one piece of css code which reduced the code-->
            <figure>
                <img src="http://lorempixel.com/300/250/food" alt="photo" />
                <figcaption>Food 1</figcaption>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
            </figure>
        </div>
        <div class="images">
            <figure>
                <img src="http://lorempixel.com/300/250/food" alt="photo" />
                <figcaption>Food 2</figcaption>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
            </figure>
        </div>
        <div class="images">
            <figure>
                <img src="http://lorempixel.com/300/250/food" alt="photo" />
                <figcaption>Food 3</figcaption>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
            </figure>
        </div>
    </div>
</section>

해결 방법 3 ( floated block요소 만 사용 )

#pageHeader {
    background-color: grey;
    /* As there is nothing behind your #pageHeader, it is better to choose a grey color with no opacity */
    min-height: 80px;
}
nav {
    width: 90%;
    margin: 0 auto;
    /* This code will center your navigation bar. The 90% width will give it space. */
}
nav:after { /* To clear elements after the nav. As you use floated li you have to clear after) */
  content: "";
  display: table;
  clear: both;
}
nav ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
}
nav li {
    float: left; /* Third way to align li elements */
    width: 16.6666666%;
    /* 100% (full-width) / 6 (as you have 6 elements in your nav bar) */
    text-align: center;
}
nav a {
    text-decoration: none;
    color: #FF0;
}
nav a:hover {
    /* always define a style for your links when they are hovered. This is a suggestion of style. */
    border-bottom: 1px solid #FF0;
    padding-bottom: 3px;
}
.main { /* This is for your italian flag in the background. If you need to support more browser just use a compress image instead. Note that this code is not cross-browser, check required code on Mozilla Developer Network */
    background-image: -webkit-linear-gradient(to right, green 0%, green 33%, #fff 33%, #fff 66%, red 66%, red 100%);
    background-image: linear-gradient(to right, green 0%, green 33%, #fff 33%, #fff 66%, red 66%, red 100%);
}
.wrapper {
    /* you wrap your main elements so that you don't have to reproduce this style every time */
    width: 90%;
    margin: 0 auto;
    text-align: center;
}
h1 {
    font: arial;
    font-size: 23px;
    color: green;
    padding: 20px 0 75px;
    margin: 0;
}
.images {
    display: inline-block;
    width: 32%;
    /* 100% / 3 images per row */
    background-color: #e3e3e3;
    vertical-align: top;
}
.images figure {
    margin: 0;
}
img {
    width: 100%;
    height: auto;
}
figure figcaption, figure p {
    text-align: left;
}
<header id="pageHeader">
    <nav>
        <ul>
            <li><a href="index.html">Home Page</a></li> 
            <li><a href="html/tables.html">Tables</a></li> 
            <li><a href="html/forms.html">Feedback</a></li> 
            <li><a href="html/text.html">About Us</a></li> 
            <li><a href="html/references.html">References</a></li> 
            <li><a href="html/validation.html">Validation</a></li>
        </ul>
    </nav>
</header>
<section class="main">
    <div class="wrapper">
         <h1>Papa Italiano</h1>

        <div class="images">
            <!-- This div class I have used to put three images using just one piece of css code which reduced the code-->
            <figure>
                <img src="http://lorempixel.com/300/250/food" alt="photo" />
                <figcaption>Food 1</figcaption>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
            </figure>
        </div>
        <div class="images">
            <figure>
                <img src="http://lorempixel.com/300/250/food" alt="photo" />
                <figcaption>Food 2</figcaption>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
            </figure>
        </div>
        <div class="images">
            <figure>
                <img src="http://lorempixel.com/300/250/food" alt="photo" />
                <figcaption>Food 3</figcaption>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
            </figure>
        </div>
    </div>
</section>

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

jQuery를 사용하여 클래스 / div없이 섹션을 정렬하는 방법은 무엇입니까?

분류에서Dev

Beautifulsoup을 사용하여 Python에서 다른 특정 div 클래스를 포함하는 div 클래스를 얻는 방법은 무엇입니까?

분류에서Dev

jquery를 사용하여 div의 여러 클래스에서 지정된 클래스 이름을 얻는 방법은 무엇입니까?

분류에서Dev

여러 div에 동일한 클래스 이름이 없을 때 BeautifulSoup을 사용하여 특정 div를 선택하는 방법은 무엇입니까?

분류에서Dev

div 내용을 정렬하는 방법은 무엇입니까?

분류에서Dev

다양한 크기의 블록 div를 원활하게 정렬하는 방법은 무엇입니까?

분류에서Dev

$ (this) 선택기를 사용하여 동일한 클래스의 div에 애니메이션을 적용하는 방법은 무엇입니까?

분류에서Dev

jquery를 사용하여 클래스의 CSS 스타일을 재정의하는 방법은 무엇입니까?

분류에서Dev

자바 스크립트만을 사용하여 다른 두 div 사이에 div 콘텐츠 블록을 추가하는 방법은 무엇입니까?

분류에서Dev

div를 사용하여 곡선을 그리는 방법은 무엇입니까?

분류에서Dev

jQuery를 사용하여 클래스를 통해 div 부모에서 입력 값을 얻는 방법은 무엇입니까?

분류에서Dev

JQuery를 사용하여 표시 속성 블록이있는 div 수를 얻는 방법은 무엇입니까?

분류에서Dev

JQuery를 사용하여 표시 속성 블록이있는 div 수를 얻는 방법은 무엇입니까?

분류에서Dev

VB의 클래스를 사용하여 목록에 항목을 추가하는 방법은 무엇입니까?

분류에서Dev

insertRow ()를 사용하여 삽입 된 테이블을 정렬하는 방법은 무엇입니까?

분류에서Dev

SQL 쿼리를 사용하여 목록 목록을 정렬하는 방법은 무엇입니까?

분류에서Dev

반응 형 CSS-패딩 / 여백을 사용하여 div를 부모 너비에 '동적으로'정렬하는 방법은 무엇입니까?

분류에서Dev

If else 블록을 사용하여 Razor에서 스타일을 결정하는 방법은 무엇입니까?

분류에서Dev

CKStackLayoutComponent를 사용하여 두 레이블을 수평으로 정렬하는 방법은 무엇입니까?

분류에서Dev

jQuery를 사용하여 div의 특정 부분을 선택하는 방법은 무엇입니까?

분류에서Dev

열 수를 사용하여 목록 항목을 정렬하는 방법은 무엇입니까?

분류에서Dev

3 개 div를 서로 나란히 정렬하여 아래쪽 및 위쪽 div 사이에 있도록하는 방법은 무엇입니까?

분류에서Dev

page_objects gem을 사용하여 div를 클릭하는 방법은 무엇입니까?

분류에서Dev

텍스트 파일을 정렬하고 Java를 사용하여 저장하는 방법은 무엇입니까?

분류에서Dev

jquery를 사용하여 특정 li을 클릭하면 css 클래스를 목록에 추가하는 방법은 무엇입니까?

분류에서Dev

RxJS를 사용하여 직렬 및 병렬 작업을 조정하는 방법은 무엇입니까?

분류에서Dev

클래스를 사용하여 tkinter GUI와 프로그램을 연결하는 방법은 무엇입니까?

분류에서Dev

PHP에서 DOM을 사용하여 클래스를 제거하는 방법은 무엇입니까?

분류에서Dev

레일을 사용하여 구분자에 클래스를 추가하는 방법은 무엇입니까?

Related 관련 기사

  1. 1

    jQuery를 사용하여 클래스 / div없이 섹션을 정렬하는 방법은 무엇입니까?

  2. 2

    Beautifulsoup을 사용하여 Python에서 다른 특정 div 클래스를 포함하는 div 클래스를 얻는 방법은 무엇입니까?

  3. 3

    jquery를 사용하여 div의 여러 클래스에서 지정된 클래스 이름을 얻는 방법은 무엇입니까?

  4. 4

    여러 div에 동일한 클래스 이름이 없을 때 BeautifulSoup을 사용하여 특정 div를 선택하는 방법은 무엇입니까?

  5. 5

    div 내용을 정렬하는 방법은 무엇입니까?

  6. 6

    다양한 크기의 블록 div를 원활하게 정렬하는 방법은 무엇입니까?

  7. 7

    $ (this) 선택기를 사용하여 동일한 클래스의 div에 애니메이션을 적용하는 방법은 무엇입니까?

  8. 8

    jquery를 사용하여 클래스의 CSS 스타일을 재정의하는 방법은 무엇입니까?

  9. 9

    자바 스크립트만을 사용하여 다른 두 div 사이에 div 콘텐츠 블록을 추가하는 방법은 무엇입니까?

  10. 10

    div를 사용하여 곡선을 그리는 방법은 무엇입니까?

  11. 11

    jQuery를 사용하여 클래스를 통해 div 부모에서 입력 값을 얻는 방법은 무엇입니까?

  12. 12

    JQuery를 사용하여 표시 속성 블록이있는 div 수를 얻는 방법은 무엇입니까?

  13. 13

    JQuery를 사용하여 표시 속성 블록이있는 div 수를 얻는 방법은 무엇입니까?

  14. 14

    VB의 클래스를 사용하여 목록에 항목을 추가하는 방법은 무엇입니까?

  15. 15

    insertRow ()를 사용하여 삽입 된 테이블을 정렬하는 방법은 무엇입니까?

  16. 16

    SQL 쿼리를 사용하여 목록 목록을 정렬하는 방법은 무엇입니까?

  17. 17

    반응 형 CSS-패딩 / 여백을 사용하여 div를 부모 너비에 '동적으로'정렬하는 방법은 무엇입니까?

  18. 18

    If else 블록을 사용하여 Razor에서 스타일을 결정하는 방법은 무엇입니까?

  19. 19

    CKStackLayoutComponent를 사용하여 두 레이블을 수평으로 정렬하는 방법은 무엇입니까?

  20. 20

    jQuery를 사용하여 div의 특정 부분을 선택하는 방법은 무엇입니까?

  21. 21

    열 수를 사용하여 목록 항목을 정렬하는 방법은 무엇입니까?

  22. 22

    3 개 div를 서로 나란히 정렬하여 아래쪽 및 위쪽 div 사이에 있도록하는 방법은 무엇입니까?

  23. 23

    page_objects gem을 사용하여 div를 클릭하는 방법은 무엇입니까?

  24. 24

    텍스트 파일을 정렬하고 Java를 사용하여 저장하는 방법은 무엇입니까?

  25. 25

    jquery를 사용하여 특정 li을 클릭하면 css 클래스를 목록에 추가하는 방법은 무엇입니까?

  26. 26

    RxJS를 사용하여 직렬 및 병렬 작업을 조정하는 방법은 무엇입니까?

  27. 27

    클래스를 사용하여 tkinter GUI와 프로그램을 연결하는 방법은 무엇입니까?

  28. 28

    PHP에서 DOM을 사용하여 클래스를 제거하는 방법은 무엇입니까?

  29. 29

    레일을 사용하여 구분자에 클래스를 추가하는 방법은 무엇입니까?

뜨겁다태그

보관