مشکل float عکس و طول div

plague

Member
سلام
من یه div دارم که یه متن و یه عکس به صورت داینامیک توی اون قرار میگیرن
به div مقدار طول ندادم تا خودش به اندازه متن جا باز کنه
و یه عکس هم داریم که من بهش float : leftدادم تا سمت چپ نوشته ها قرار بگیره
الان مشکل من ایه که این عکس وقتی float میگیره همیشه از div میزنه بیرون مگه اینکه نوشته ها انقدر زیاد باشن که طول div رو افزایش بدن و عکس توی اون قرار بگیره
یا اینکه یه مقداری به height به div بدم که از height عکس بزرگتر باشه

که چون من اندازه نوشته و طول عکس رو نمیدونم این روش ها به کارم نمیاد

یه راه به نظرم رسید که در آخرین خط قبل از بسته شدن div یدونه br بزارم با این کلاس clear: both;
ولی این روش به div به اندازه کل صفحه طول میده

راهی وجود نداره که اینdiv , عکس مارو آدم حساب کنه ؟
 

plague

Member
خدمت شما

HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css"> 
<!-- 
body  {
    font: 100% Verdana, Arial, Helvetica, sans-serif;
    background: #666666;
    margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
    padding: 0;
    text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
    color: #000000;
}
.twoColFixRtHdr #container {
    width: 780px;
    margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
    border: 1px solid #000000;
    text-align: left;
    background-color: #FFF;
} 
.twoColFixRtHdr #header { 
    background: #DDDDDD; 
    padding: 0 10px 0 20px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
} 
.twoColFixRtHdr #header h1 {
    margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
    padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
}
.twoColFixRtHdr #sidebar1 {
    float: right; /* since this element is floated, a width must be given */
    width: 200px; /* the actual width of this div, in standards-compliant browsers, or standards mode in Internet Explorer will include the padding and border in addition to the width */
    background: #EBEBEB; /* the background color will be displayed for the length of the content in the column, but no further */
    padding: 15px 10px;
}
.twoColFixRtHdr #mainContent {
    margin: 0 250px 0 0; /* the right margin on this div element creates the column down the right side of the page - no matter how much content the sidebar1 div contains, the column space will remain. You can remove this margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends. */
    padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
    background-color: #999;
} 
.twoColFixRtHdr #footer { 
    padding: 0 10px 0 20px; /* this padding matches the left alignment of the elements in the divs that appear above it. */
    background:#DDDDDD; 
} 
.twoColFixRtHdr #footer p {
    margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
    padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
}
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
    float: right;
    margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page */
    float: left;
    margin-right: 8px;
}
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
    clear:both;
    font-size: 1px;
}
.twoColFixRtHdr #container #mainContent img  {
    float: left;
}
--> 
</style><!--[if IE 5]>
<style type="text/css"> 
/* place css box model fixes for IE 5* in this conditional comment */
.twoColFixRtHdr #sidebar1 { width: 220px; }
</style>
<![endif]--><!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColFixRtHdr #sidebar1 { padding-top: 30px; }
.twoColFixRtHdr #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]--></head>

<body class="twoColFixRtHdr">

<div id="container">
  <div id="header">
    <h1>Header</h1>
  <!-- end #header --></div>
  <div id="sidebar1">
    <h3>Sidebar1 Content</h3>
    <p>The background color on this div will only show for the length of the content. If you'd like a dividing line instead, place a border on the right side of the #mainContent div if it will always contain more content. </p>
    <p>Donec eu mi sed turpis feugiat feugiat. Integer turpis arcu, pellentesque  eget, cursus et, fermentum ut, sapien. Fusce metus mi, eleifend  sollicitudin, molestie id, varius et, nibh. Donec nec libero.</p>
  <!-- end #sidebar1 --></div>
  <div id="mainContent">
   <img src="file:///C|/wamp/www/UFC/image/99.jpg" width="102" height="133" />asdasdasas
  <br  class=""/>

 </div>
    <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
  <div id="footer">
    <p>Footer</p>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>
 

plague

Member
سلام
with و اون margin برای عرض تیبل هستن مشکل من با ارتفاع تیبله
 

echessdesign

مدیر انجمن طراحی وب
درود بر شما
دوست عزیز، به شما حتما توصیه می کنم که کتاب آموزش CSS, HTML انتشارات ناقوس به نوسیندگی خانوم الیزابت کاسترو رو مطالعه کنید.
شناخت و بکارگیری شما از عناصر CSS ، کاملا اشتباه است.
زمانی که شما صفحه رو به 2 قسمت تقسیم می کنید، دقیقا باید موقعیت یک DIV رو مشخص کنید:
HTML:
.twoColFixRtHdr #mainContent {
    float:left;
}
 

plague

Member
سلام
آخه این کد دیفالت دریم ویوره
فکر نمیکردم اون نیاز به دستکاری داشته باشه

مشکل من تو اون کد قبلی خودم با اضافه کردن br با کلاس float : left حل شد
البته بعد از اینی که شما فرمودین هم اینو اضافه کردم
کد:
.twoColFixRtHdr #mainContent {
    float:left;
}
و ایندفعه مشکل با همون br و کلاس float : both حل شد

ولی فکر که میکنم تو همون کد اولی وقتی br با کلاس clear:both میزاشتم صفحه تا پایین کش میومد هم برای خودش خیلی پر کاربرد بود! تو این کد جدیده نمیشه اینو کاریش کرد ؟
 

echessdesign

مدیر انجمن طراحی وب
دورد بر شما
پیشتر به شما توصیه کرده بودم که کدام کتاب را مطالعه کنید!
شما از یک عنصر Inline Level ،نباید کارهای عناصر Block Level را انجام دهید!
در رابطه با خصیصه Clear با مقدار Both ، به طور کامل در انجمن توضیح داده شده است. (جستجو فرمایید)
پاینده باشید
 

جدیدترین ارسال ها

بالا