创建 HTML 和带有固定布局的 css 视图

我试图仅使用纯 html/css 进行此布局,如图所示,但不能。


我在这方面花了很多时间,并且只成功地处理了表格元素。我正在尝试使用基本的 DIV /CSS 来做到这一点


<html>

    <style>


        table, th, td {

            border: 1px solid black;

        }


        #upleft {

            width: 100px;

            height: 300px;

            background: red;

            float: left;

        }


        #upright {

            width: 300px;

            height: 200px;

            background: blue;

            float: left

        }


        #below {

            height: 300px;

            width: 400px;

            background: green

        }

    </style>

    <body>

    <p style="font-size: 1.5em;">&nbsp;</p>

    <p>&nbsp;&nbsp;</p>

    <table class="editorDemoTable" style="width: 581px; height: 101px;">

        <tbody>

        <tr style="height: 49px;">

            <td style="width: 619px; height: 49px;">

                <p>&nbsp;</p>

                <p>&nbsp;</p>

            </td>

            <td style="width: 423px; height: 49px;"><strong></strong></td>

        </tr>

        <tr style="height: 230px;">

            <td style="width: 19px; height: 230px;">

                <div id="target"></div>&nbsp;

            </td>

        </tr>

        </tbody>

    </table>

    <p></p>

    </body>

    </html>

请建议。


BR,


心有法竹
浏览 105回答 2
2回答

繁花不似锦

希望这对您有用: 您可以根据您的要求调整高度和宽度。.editorDemoTable {&nbsp; border: 1px solid black;&nbsp; width: 100%;}.firstRow .firstTD {&nbsp; border: 1px solid red;&nbsp; width: 25%;&nbsp; height: 200px;}.firstRow .secondTD {&nbsp; border: 1px solid red;&nbsp; width: 75%;}.secondRow .firstTD {&nbsp; border: 1px solid red;&nbsp; width: 25%;&nbsp; height: 500px;}.secondRow .secondTD {&nbsp; border: 1px solid red;&nbsp; width: 75%;&nbsp; height: 500px;}<table class="editorDemoTable">&nbsp; <tbody>&nbsp; &nbsp; <tr class="firstRow">&nbsp; &nbsp; &nbsp; <td class="firstTD">&nbsp; &nbsp; &nbsp; &nbsp; <input type="text" placeholder="search...">&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; &nbsp; <td class="secondTD"><strong></strong></td>&nbsp; &nbsp; </tr>&nbsp; &nbsp; <tr class="secondRow">&nbsp; &nbsp; &nbsp; <td class="firstTD">&nbsp; &nbsp; &nbsp; &nbsp; <div id="target"></div>&nbsp;&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; &nbsp; <td class="secondTD">lower right</td>&nbsp; &nbsp; </tr>&nbsp; </tbody></table>使用Flex:* {&nbsp; margin: 0;&nbsp; padding: 0;&nbsp; border: 0;}#MainDiv {&nbsp; display: flex;&nbsp; flex-direction: column;&nbsp; height: 900px;&nbsp; width: 100%;&nbsp; margin: 5px;}#txtsearch {&nbsp; margin-top: 10px;&nbsp; margin-left: 10px;&nbsp; border: 1px solid black;&nbsp; height: 30px;&nbsp; width: 60%;}.underline {&nbsp; margin-top: 10px;&nbsp; margin-left: 10px;&nbsp; height: 30px;&nbsp; width: 60%;&nbsp; font-weight: bold;}.Rows {&nbsp; display: flex;&nbsp; flex-direction: row;}.Topleft {&nbsp; height: 200px;&nbsp; width: 30%;&nbsp; border: 1px solid red;}.TopRight {&nbsp; height: 200px;&nbsp; width: 70%;&nbsp; border: 1px solid red;}.BottomLeft {&nbsp; height: 700px;&nbsp; width: 30%;&nbsp; border: 1px solid red;}.BottomRight {&nbsp; height: 700px;&nbsp; width: 70%;&nbsp; border: 1px solid red;}<div id="MainDiv">&nbsp; <div class="Rows">&nbsp; &nbsp; <div class="Topleft">&nbsp; &nbsp; &nbsp; <input type="text" id="txtsearch" placeholder="search...">&nbsp; &nbsp; &nbsp; <p class="underline">&nbsp; &nbsp; &nbsp; &nbsp; -------------------------------------&nbsp; &nbsp; &nbsp; </p>&nbsp; &nbsp; </div>&nbsp; &nbsp; <div class="TopRight">Top Right</div>&nbsp; </div>&nbsp; <div class="Rows">&nbsp; &nbsp; <div class="BottomLeft">Bottom Left</div>&nbsp; &nbsp; <div class="BottomRight">Bottom Right</div>&nbsp; </div></div>

红颜莎娜

我建议使用 CSS 网格进行布局(网格和 Flexbox 都是纯 CSS),如下所示:https://jsfiddle.net/7L6bpfn1/超文本标记语言<div id = "grid">&nbsp; <div id = "div1">&nbsp; 1&nbsp; &nbsp; <div id = "search">&nbsp; &nbsp; &nbsp; Search&nbsp; &nbsp; </div>&nbsp; </div>&nbsp; <div id = "div2">&nbsp; 2&nbsp; </div>&nbsp; <div id = "div3">&nbsp; 3&nbsp; </div>&nbsp; <div id = "div4">&nbsp; 4&nbsp; </div></div>CSS#grid {&nbsp; display: grid;&nbsp; grid-gap: 5px;&nbsp; grid-template-columns: 40vw 60vw;&nbsp; grid-template-rows: 30vh 70vh;&nbsp; grid-template-areas:&nbsp; "upper-left upper-right"&nbsp; "lower-left lower-right";}#div1 {&nbsp; grid-area: upper-left;&nbsp; background-color: red;}#div2 {&nbsp; grid-area: upper-right;&nbsp; background-color: red;}#div3 {&nbsp; grid-area: lower-left;&nbsp; background-color: red;}#div4 {&nbsp; grid-area: lower-right;&nbsp; background-color: red;}#search {&nbsp; background-color: blue;&nbsp; color: white;&nbsp; margin: 10px;}希望能帮助到你!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5