gpt4 book ai didi

css - 我想把一个 div 留给另一个 div

转载 作者:行者123 更新时间:2023-11-28 08:39:33 25 4
gpt4 key购买 nike

我正在为这个网站的响应能力而工作,我想将评级图像贴在左侧,留一点余量,当窗口的宽度为 335 时,它在左侧工作:50% 但是当我增加窗口的宽度时,它不会保持我想要的状态,请建议我,我该怎么办??

这是我的代码

<div id="filteredRestBody" class="row filteredRestBody">
<div id="row1" class="row">
<div id="yochina" class="col-sm-4 filterThumbnails" style="background: url('images/yochinathumbbck.jpg')">
<img src="images/bestoffers.png">
<div id="discountImg">
<img src="images/discountimg.png" style="">
<div class="discountNum" title="Discount">15%</div>
</div>
<div id="ratings" title="6/10">
<img src="images/ratingy.png">
<img src="images/ratingy.png">
<img src="images/ratingy.png">
<img src="images/ratingy.png">
<img src="images/ratingy.png">
<img src="images/ratingw.png">
<img src="images/ratingw.png">
<img src="images/ratingw.png">
<img src="images/ratingw.png">
<img src="images/ratingw.png">
</div>
<div id="ratingNum">5</div>
<div id="restaurantThumbnailsTitle" class="restaurantThumbnailsTitle">
<span><a href="viewRestaurant.php?rest=yochina">Yo! China</a></span>
<br>
<span class="restaurantThumbnailsTitleText">chilled out chinese</span>
</div>

CSS

.filteredRestBody {
background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
border: medium none;
border-top-left-radius: 23px;
box-shadow: 0 0 0 grey;
height: auto;
margin-left: -4%;
padding: 0 0 47px 8px;
position: relative;
top: 30px;
width: 111%;
}

.filterThumbnails {
background-position: 2px -19px;
background-repeat: repeat;
border-top-left-radius: 10%;
border-top-right-radius: 10%;
height: 200px;
margin-left: 5.3%;
margin-top: 50px;
position: relative;
top: -36px;
width: auto;
}

#ratings {
background: none repeat scroll 0 0 rgba(0, 0, 0, 1);
border-radius: 8px;
left: 50%;
padding: 0 7px 4px;
position: absolute;
top: 49%;
}

#ratingsNum {
background: none repeat scroll 0 0 rgba(0, 193, 0, 0.9);
border-bottom-right-radius: 9px;
border-top-left-radius: 9px;
font-family: Times New Roman;
font-size: 1.6em;
font-weight: bolder;
left: 89%;
padding: 0 8px;
position: absolute;
top: 45.5%;
width: auto;
}

This is the first screenshot when the width is 335

This is what happens when i increase the window's width

最佳答案

而不是使用 left , 你可以使用 right CSS 中的属性。这会坚持ratingsNumratings div 到容器 div 的右边界。

CSS

#ratings {
right:50px;
}

#ratingsNum {
right:10px;
}

jsFiddle Example

希望对您有所帮助。

作为旁注,我注意到您的代码段包含一些没有结束标记的元素(即 #discountImg div)(在本例中为 </div> )。请注意,因为这可能导致您的布局产生不可预知的结果。

关于css - 我想把一个 div 留给另一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27874368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com