我无法将div与彼此相邻的范围对齐我正在使用的代码
<div style="float:left;width:35%;max-width:150px;height:30vh;max-height:200px;background-position:center;background-repeat:no-repeat;background-image:url('http://placehold.it/150x200')"></div>
<span style="margin-left:10px;float:left;font-weight:bold;font-size:22px; display:inline-block;white-space: nowrap;overflow:hidden !important;text-overflow: ellipsis;float:right">ssddsa.hksbkjasdouahdohjaqios'djqw'eodhj;oewdh;oeuwdh;eouwhd;uehwd;iuewghd;iuewhgd;ehwdp;i7euwhgd;pi7hywe;idhg;iwedhouw9ehdiouwehdi;uhwe;iduheiuwdh;eiuwhd;iuwehdiuwehdiuhwediuwhdiuhweiudiuewhdiusdds</span>
&#13;
答案 0 :(得分:1)
因为span
的宽度太宽而无法放在div
旁边。
您必须在span
<span style="width:35%; margin-left:10px;float:left;font-weight:bold;font-size:22px; display:inline-block;white-space: nowrap;overflow:hidden !important;text-overflow: ellipsis;float:right">ssddsa.hksbkjasdouahdohjaqios'djqw'eodhj;oewdh;oeuwdh;eouwhd;uehwd;iuewghd;iuewhgd;ehwdp;i7euwhgd;pi7hywe;idhg;iwedhouw9ehdiouwehdi;uhwe;iduheiuwdh;eiuwhd;iuwehdiuwehdiuhwediuwhdiuhweiudiuewhdiusdds</span>
答案 1 :(得分:0)
首先,您的float:right;
元素上有float: left;
和span
,其次,您的span
元素需要宽度。试试width: 65%;
答案 2 :(得分:0)
测试这个
<div style="float:left;width:35%;max-width:150px;height:30vh;max-height:200px;background-position:center;background-repeat:no-repeat;background-image:url('http://placehold.it/150x200')"></div>
<span style="margin-left:10px;float:left;font-weight:bold;font-size:22px; display:inline-block;white-space: nowrap;overflow:hidden !important;text-overflow: ellipsis;float:right">ssddsa.hksbkjasdouahdohjaqios'djqw'eodhj;oewdh;oeuwdh;eouwhd;uehwd;iuewghd;iuewhgd;ehwdp;i7euwhgd;pi7hywe;idhg;iwedhouw9ehdiouwehdi;uhwe;iduheiuwdh;eiuwhd;iuwehdiuwehdiuhwediuwhdiuhweiudiuewhdiusdds</span>
答案 3 :(得分:0)
<html>
<head>
<style>
div {
float:left;
width:35%;
max-width:150px;
height:30vh;
max-height:200px;
background-position:center;
background-repeat:no-repeat;
background-image:url('http://placehold.it/150x200');
}
span {
margin-left:10px;
float:left;
font-weight:bold;
font-size:22px;
display:inline-block;
white-space: nowrap;
overflow:hidden !important;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<div></div>
<span>This is span</span>
</body>
</html>
工作得很好!
原因:通过在跨度上放置太多没有空格的单词,宽度变得如此之长。 您还使用了float:右边的span样式,这对此没有帮助!