我想通過使用 flex 并且沒有負邊距來創建一個類似于這個示例影像的 UI -

挑戰在于我使用浮動和負邊距來創建相同的布局。但我不想使用負值來設定內容外的綠色 div。另外,我使用浮動來保持綠色框周圍的內容。但我想使用 flex 而不是浮動。
所以,總結一下我的問題 - 創建一個參考布局,它不會使用任何浮點或負值來將框對齊為綠色。
我在這里添加了代碼快照來查看我的 HTML 和 CSS。
任何幫助,將不勝感激。提前致謝。
.container {
width: 50%;
text-align: justify;
margin: auto;
}
.box {
background-color: green;
width: 20%;
padding: 15px;
margin: 15px;
}
.right {
float: right;
margin-right: 0 !important;
margin-right: -15% !important;
}
.left {
float: left;
margin-left: 0 !important;
margin-left: -15% !important;
}
<div class="container">
<div class="paragrah">
electronictypesetting,remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheetscontainingLorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker includingversionsof Lorem
Ipsum. It is a long established fact that a reader will be distracted by the readable content of apage
<div class="box right"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porttitor aliquet leo, et suscipit nulla sodales at. Praesent dictum imperdiet lacus nec pharetra.
</div>
when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distributionofletters, as opposed to using 'Content here, content here', making it look like readable English. Manydesktoppublishing packages and web page
editors now use Lorem Ipsum as their default model text, and a search for'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over theyears,sometimes by accident, sometimes on purpose (injected humour and
the like).Contrary to popular belief, Lorem Ipsum is not simply random text. Ithasroots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. RichardMcClintock, aLatin professor at Hampden-Sydney College in Virginia,
looked up one of the more obscure Latin words,consectetur,from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered theundoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
Bonorum et Malorum"(TheExtremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics,verypopular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from alineinsection
1.10.32. There are many variations of passages of Lorem Ipsum available, but the majority havesufferedalteration in some form, by injected humour, or randomised words which don't look even slightly believable.Ifyou
<div class="box left"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porttitor aliquet leo, et suscipit nulla sodales at. Praesent dictum imperdiet lacus nec pharetra. Ut ut risus ipsum ac leo auctor convallis.
</div>
are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden inthemiddle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks asnecessary,makingthis the first true generator
on the Internet. It uses a dictionary of over 200 Latin words, combined with ahandfulof model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum isthereforealways free from repetition, injected humour, or
non-characteristic words etc.he standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested.Sections1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exactoriginalform,accompanied
by English versions from the 1914 translation by H. Rackham. But I must explain to you how allthismistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account ofthesystem, and expound the actual teachings
of the great explorer of the truth, the master-builder of humanhappiness.No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do notknowhowto pursue pleasure rationally encounter consequences that are
extremely painful. Nor again is there anyonewholovesor pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstancesoccurinwhich toil and pain can procure him some great pleasure. To take a trivial example,
which of us everundertakeslaborious physical exercise, except to obtain some advantage from it? But who has any right to find faultwith amanwho chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces noresultant
pleasure? who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids apain that produces noresultant pleasure?who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids apain that produces noresultant
pleasure? who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids apain that produces noresultant pleasure? who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids apain that produces noresultant
pleasure? who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids apain that produces noresultant pleasure? who chooses to enjoy a pleasure that has no.
</div>
</div>
uj5u.com熱心網友回復:
不。
Flexbox 用于在行或列中布置框。
Float 用于使文本環繞框。
你需要為此浮動。
uj5u.com熱心網友回復:
你有兩個要求。第一個可以,第二個不能
首先是綠色插入文本框應該在段落的內容內。這可以通過給段落一個左右填充來實作,根據所需的邊距和填充以及綠色插入元素的寬度來計算它以提供足夠的空間。
第二個是不使用浮動。flex 在這里無能為力,它是一維的,它不理解圍繞元素浮動的文本的概念。這個要求就是 float 的設計目的。你需要在這里繼續使用它。
.container {
width: min(80vw, 700px);
text-align: justify;
margin: auto;
}
.paragraph {
background-color: pink;
padding: 0 calc(10% 15px);
}
.box {
background-color: green;
width: 20%;
padding: 15px;
margin: 15px;
}
.right {
float: right;
margin-right: 0 !important;
margin-right: -15% !important;
}
.left {
float: left;
margin-left: 0 !important;
margin-left: -15% !important;
}
<div class="container">
<div class="paragraph">
electronictypesetting,remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheetscontainingLorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker includingversionsof Lorem
Ipsum. It is a long established fact that a reader will be distracted by the readable content of apage
<div class="box right"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porttitor aliquet leo, et suscipit nulla sodales at. Praesent dictum imperdiet lacus nec pharetra.
</div>
when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distributionofletters, as opposed to using 'Content here, content here', making it look like readable English. Manydesktoppublishing packages and web page
editors now use Lorem Ipsum as their default model text, and a search for'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over theyears,sometimes by accident, sometimes on purpose (injected humour and
the like).Contrary to popular belief, Lorem Ipsum is not simply random text. Ithasroots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. RichardMcClintock, aLatin professor at Hampden-Sydney College in Virginia,
looked up one of the more obscure Latin words,consectetur,from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered theundoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
Bonorum et Malorum"(TheExtremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics,verypopular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from alineinsection
1.10.32. There are many variations of passages of Lorem Ipsum available, but the majority havesufferedalteration in some form, by injected humour, or randomised words which don't look even slightly believable.Ifyou
<div class="box left"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porttitor aliquet leo, et suscipit nulla sodales at. Praesent dictum imperdiet lacus nec pharetra. Ut ut risus ipsum ac leo auctor convallis.
</div>
are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden inthemiddle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks asnecessary,makingthis the first true generator
on the Internet. It uses a dictionary of over 200 Latin words, combined with ahandfulof model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum isthereforealways free from repetition, injected humour, or
non-characteristic words etc.he standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested.Sections1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exactoriginalform,accompanied
by English versions from the 1914 translation by H. Rackham. But I must explain to you how allthismistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account ofthesystem, and expound the actual teachings
of the great explorer of the truth, the master-builder of humanhappiness.No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do notknowhowto pursue pleasure rationally encounter consequences that are
extremely painful. Nor again is there anyonewholovesor pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstancesoccurinwhich toil and pain can procure him some great pleasure. To take a trivial example,
which of us everundertakeslaborious physical exercise, except to obtain some advantage from it? But who has any right to find faultwith amanwho chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces noresultant
pleasure? who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids apain that produces noresultant pleasure?who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids apain that produces noresultant
pleasure? who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids apain that produces noresultant pleasure? who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids apain that produces noresultant
pleasure? who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids apain that produces noresultant pleasure? who chooses to enjoy a pleasure that has no.
</div>
</div>
請注意,在此代碼段中,已更正了 paragrah 的拼寫。此外,整體寬度已設定為最小值,以便在您進入整頁之前很窄的 Stackoverflow 代碼段系統可以容納整個內容。添加粉紅色只是為了展示現在內容的邊界在哪里。
uj5u.com熱心網友回復:
你可以用 flex 來做,但它會涉及在 2 個 div 上使用位置。浮動是更好的解決方案
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/376401.html
標籤:javascript html css
上一篇:基于結束編號的組物件
