在div内浮动图像

时间:2015-01-17 07:53:31

标签: html css

您好我正在进行转换为HTML / CSS的模型设计。

如何将人物图像漂浮在第三个框内? 我试图使用图像,并在上部透明,所以每列的背景图像将是相同的,但当我悬停它时,上部包含空白/白色空间,这是不好的。 见图像字母B

一个 A

enter image description here

.home-sections .left-side .title{
			background: #3666af;
			height: 130px;
			padding: 0 30px;
			position: relative;
			z-index: 2;
			overflow: hidden;
		}
		.home-sections .left-side .title h2{
			margin: 0;
			line-height: 130px;
		}
		.home-sections .left-side .title span{
			font-size: 18px;
			color: #f8f8f8;
			padding-left: 10px;
		}


		.home-sections .left-side .item .team-title{
			font-size: 25px;
			font-weight: 400;
			font-family: ralewaylight;
			margin-top:0;
			padding-bottom: 10px;
		}
		.home-sections .left-side .item .team-title span{
			display: block;
			font-size: 50px;
			font-weight: 900;
			font-family: 'ralewayextrabold';
			position: relative;
			top: -5px;
		}
		.home-sections .left-side .item .team-position{
			font-size: 19px;
		}
		.home-sections .left-side .item .info{
			max-width: 75%;
			margin: 0 auto;
			color: #b1b1b1;
			font-size: 1.1em;
			padding: 34px 0 15px 0;
			position: relative;
		}
		.home-sections .left-side .item .info:before{
			content: '';
			position: absolute;
			top:0;
			left: 50%;
			width: 20%;
			margin-left: -10%;
			height: 4px;
			background:#8ead42;
		}
		.home-sections .left-side .item .info .description p:last-child{
			margin-bottom: 0;
		}
		.home-sections .left-side .item .social-icons{
			margin: 0;
		}
		.home-sections .left-side .item .social-icons li{
			list-style: none;
			display: inline-block;
			font-size: 20px;
			padding: 0 5px;
		}
		.home-sections .left-side .item .social-icons li a{
			color: #797979;
			font-size: 20px;
			-webkit-transition: all 0.3s ease;
			   -moz-transition: all 0.3s ease;
				-ms-transition: all 0.3s ease;
				 -o-transition: all 0.3s ease;
					transition: all 0.3s ease;
		}
		.home-sections .left-side .item .social-icons li a:hover{
			color: #fff;
		}

		.home-sections .home-sections-item{
			position: relative;
			text-align: center;

		}
		.home-sections .home-sections-head{
			position: relative;
		}
		.home-sections .home-sections-head > img{
			width: 100%;
		}
		.home-sections .home-sections-head:after{
			content: '';
			position: absolute;
			top: 0;
			left:0;
			width: 100%;
			height: 100%;
			/*background: #dedede;
			opacity: 0.2;*/
			-webkit-transition: all .25s ease;
			   -moz-transition: all .25s ease;
				-ms-transition: all .25s ease;
				 -o-transition: all .25s ease;
					transition: all .25s ease;
		}
		.home-sections-item .home-sections-content{
			background: #fafafa;
			padding: 30px;
			border: 1px solid #ebebeb;
			border-top: none;
			box-shadow: inset 0px 1px 8px -4px rgba(0,0,0,0.2);
		}

		.home-sections-item .home-sections-content .title{
			font-size: 25px;
			color: #474747;
			font-weight: 500;
			font-family: 'ralewaymedium';
			margin-top: 0;
			margin-bottom: 10px;

		}

		.home-sections-item .home-sections-content .subtitle{
			text-transform: uppercase;
			color: #adadad;
			font-size: 16px;
			position: relative;
			margin: 0;
			padding-top: 15px;
		}
		.home-sections-item .home-sections-content .subtitle:after{
			content: '';
			position: absolute;
			top:0;
			left: 50%;
			width: 60px;
			height: 2px;
			background: #8ead42;  
			margin-left: -30px;

		}

		.home-sections-button{
			margin: 0;
			padding: 0;
			list-style: none;
			position: absolute;
			bottom: 10px;
			left: 0;
			width: 100%;
			z-index: 1;
			opacity: 0;

			-webkit-transition: all .75s ease;
			   -moz-transition: all .75s ease;
				-ms-transition: all .75s ease;
				 -o-transition: all .75s ease;
					transition: all .75s ease;

		}

		.home-sections-button li{
			display: inline-block;
			margin-right: 10px;

		}

		.home-sections-button li:last-child{
			margin-right: 0;
		}
		.home-sections-button li a{
			display: block;
			color: #8ead42;
			text-align: center;
		}
		.home-sections-button li a i{
			width: 50px;
			height: 50px;
			border-radius: 50%;
			border:1px solid #8ead42;
			text-align: center;
			line-height: 50px;
			font-size: 20px;
			box-shadow: 1px 1px 3px -1px rgba(0,0,0,0.2), inset 1px 1px 3px -1px rgba(0,0,0,0.2);
			text-shadow: 1px 1px 2px rgba(0,0,0,0.2);


		}

		.home-sections-button li a:hover i,.home-sections-button li a:focus i{
			background: #8ead42;
			box-shadow: 1px 1px 3px -1px rgba(0,0,0,0), inset 1px 1px 3px -1px rgba(0,0,0,0);
			text-shadow: 1px 1px 2px rgba(0,0,0,0);
			color: #fff;
		}

		.home-sections-item:hover .home-sections-head:after,.home-sections-item:focus .home-sections-head:after{
			opacity: 0.5;
			background:#000;
		}
		.home-sections-item:hover .home-sections-button,.home-sections-item:focus .home-sections-button{
			bottom: 80px;
			opacity: 1;
			-webkit-transition: all .25s ease, color 0.75s ease;
			   -moz-transition: all .25s ease, color 0.75s ease;
				-ms-transition: all .25s ease, color 0.75s ease;
				 -o-transition: all .25s ease, color 0.75s ease;
					transition: all .25s ease, color 0.75s ease;	
		}

		.row > :first-child,.section > :first-child, div[class^='col-'] > :first-child{
			margin-top: 0 !important;
		}
		.row > :last-child,.section > :last-child, div[class^='col-'] > :last-child{
			margin-bottom: 0 !important;
		}
 <div class="row mb-xlarge">
		<div class="home-sections">	
				<div class="col-md-4">
					<div class="home-sections-item">
						<div class="home-sections-head">
							<img src="images/gallery/thumbs/thumb_01.png" alt="">
							<ul class="home-sections-button">
								<li><a href="#"><img src="images/icon-hover.png"></a></li>
							</ul>
						</div>

						<div class="home-sections-content">
							<h3 class="title">Nos projets domiciliaire</h3>
							<h4 class="subtitle">PLUS DE DÉTAILS </h4>
						</div>	
					</div>
				</div>
						
				<div class="col-md-4">
					<div class="home-sections-item">
						<div class="home-sections-head">
							<img src="images/gallery/thumbs/thumb_02.png" alt="">
								<ul class="home-sections-button">
									<li><a href="#"><img src="images/icon-hover.png"></a></li>
								</ul>
						</div>

						<div class="home-sections-content">
							<h3 class="title">Modèles disponible</h3>
							<h4 class="subtitle">VOIR LES MODÈLES</h4>
						</div>
									
					</div>
				</div>

				<div class="col-md-4">
					<div class="home-sections-item">
						<div class="home-sections-head">
							<img src="images/gallery/thumbs/thumb_03.png" alt="">
							<ul class="home-sections-button">
								<li><a href="#"><img src="images/icon-hover.png"></a></li>
							</ul>
						</div>

						<div class="home-sections-content">
							<h3 class="title">Qualité de construction</h3>
							<h4 class="subtitle">lIRE PLUS </h4>
						</div>
									
					</div>
				</div>			
		</div>			
</div>

2 个答案:

答案 0 :(得分:0)

制作图片display: block

.home-sections-head img{
    display: block;
}

<强> JSFIDDLE DEMO

答案 1 :(得分:0)

Vertical-align:top 解决了您在B部分中描述的问题。

由于图像本身及其描述位于 .col-mid-4 内,因此您无需浮动图像。将内联块的属性值添加到.cols-mid-4将使图像看起来像是浮动的,并且在排列图像及其描述方面也具有您想要的外观。

将以下CSS代码块添加到您的

.col-md-4 {
      display: inline-block;
      vertical-align: top; /* solves the problem in B part */
      margin: 0 20px 20px 0; /* Adjust as needed */
      }

注意:要获得统一的外观,请使用属性值添加宽度高度溢出 隐藏

.col-md-4 {
  display: inline-block;
  vertical-align: top;
  margin: 0 20px 20px 0; /* Adjust as needed */
  }



.home-sections .left-side .title{
			background: #3666af;
			height: 130px;
			padding: 0 30px;
			position: relative;
			z-index: 2;
			overflow: hidden;
		}
		.home-sections .left-side .title h2{
			margin: 0;
			line-height: 130px;
		}
		.home-sections .left-side .title span{
			font-size: 18px;
			color: #f8f8f8;
			padding-left: 10px;
		}


		.home-sections .left-side .item .team-title{
			font-size: 25px;
			font-weight: 400;
			font-family: ralewaylight;
			margin-top:0;
			padding-bottom: 10px;
		}
		.home-sections .left-side .item .team-title span{
			display: block;
			font-size: 50px;
			font-weight: 900;
			font-family: 'ralewayextrabold';
			position: relative;
			top: -5px;
		}
		.home-sections .left-side .item .team-position{
			font-size: 19px;
		}
		.home-sections .left-side .item .info{
			max-width: 75%;
			margin: 0 auto;
			color: #b1b1b1;
			font-size: 1.1em;
			padding: 34px 0 15px 0;
			position: relative;
		}
		.home-sections .left-side .item .info:before{
			content: '';
			position: absolute;
			top:0;
			left: 50%;
			width: 20%;
			margin-left: -10%;
			height: 4px;
			background:#8ead42;
		}
		.home-sections .left-side .item .info .description p:last-child{
			margin-bottom: 0;
		}
		.home-sections .left-side .item .social-icons{
			margin: 0;
		}
		.home-sections .left-side .item .social-icons li{
			list-style: none;
			display: inline-block;
			font-size: 20px;
			padding: 0 5px;
		}
		.home-sections .left-side .item .social-icons li a{
			color: #797979;
			font-size: 20px;
			-webkit-transition: all 0.3s ease;
			   -moz-transition: all 0.3s ease;
				-ms-transition: all 0.3s ease;
				 -o-transition: all 0.3s ease;
					transition: all 0.3s ease;
		}
		.home-sections .left-side .item .social-icons li a:hover{
			color: #fff;
		}

		.home-sections .home-sections-item{
			position: relative;
			text-align: center;

		}
		.home-sections .home-sections-head{
			position: relative;
		}
		.home-sections .home-sections-head > img{
			width: 100%;
		}
		.home-sections .home-sections-head:after{
			content: '';
			position: absolute;
			top: 0;
			left:0;
			width: 100%;
			height: 100%;
			/*background: #dedede;
			opacity: 0.2;*/
			-webkit-transition: all .25s ease;
			   -moz-transition: all .25s ease;
				-ms-transition: all .25s ease;
				 -o-transition: all .25s ease;
					transition: all .25s ease;
		}
		.home-sections-item .home-sections-content{
			background: #fafafa;
			padding: 30px;
			border: 1px solid #ebebeb;
			border-top: none;
			box-shadow: inset 0px 1px 8px -4px rgba(0,0,0,0.2);
		}

		.home-sections-item .home-sections-content .title{
			font-size: 25px;
			color: #474747;
			font-weight: 500;
			font-family: 'ralewaymedium';
			margin-top: 0;
			margin-bottom: 10px;

		}

		.home-sections-item .home-sections-content .subtitle{
			text-transform: uppercase;
			color: #adadad;
			font-size: 16px;
			position: relative;
			margin: 0;
			padding-top: 15px;
		}
		.home-sections-item .home-sections-content .subtitle:after{
			content: '';
			position: absolute;
			top:0;
			left: 50%;
			width: 60px;
			height: 2px;
			background: #8ead42;  
			margin-left: -30px;

		}

		.home-sections-button{
			margin: 0;
			padding: 0;
			list-style: none;
			position: absolute;
			bottom: 10px;
			left: 0;
			width: 100%;
			z-index: 1;
			opacity: 0;

			-webkit-transition: all .75s ease;
			   -moz-transition: all .75s ease;
				-ms-transition: all .75s ease;
				 -o-transition: all .75s ease;
					transition: all .75s ease;

		}

		.home-sections-button li{
			display: inline-block;
			margin-right: 10px;

		}

		.home-sections-button li:last-child{
			margin-right: 0;
		}
		.home-sections-button li a{
			display: block;
			color: #8ead42;
			text-align: center;
		}
		.home-sections-button li a i{
			width: 50px;
			height: 50px;
			border-radius: 50%;
			border:1px solid #8ead42;
			text-align: center;
			line-height: 50px;
			font-size: 20px;
			box-shadow: 1px 1px 3px -1px rgba(0,0,0,0.2), inset 1px 1px 3px -1px rgba(0,0,0,0.2);
			text-shadow: 1px 1px 2px rgba(0,0,0,0.2);


		}

		.home-sections-button li a:hover i,.home-sections-button li a:focus i{
			background: #8ead42;
			box-shadow: 1px 1px 3px -1px rgba(0,0,0,0), inset 1px 1px 3px -1px rgba(0,0,0,0);
			text-shadow: 1px 1px 2px rgba(0,0,0,0);
			color: #fff;
		}

		.home-sections-item:hover .home-sections-head:after,.home-sections-item:focus .home-sections-head:after{
			opacity: 0.5;
			background:#000;
		}
		.home-sections-item:hover .home-sections-button,.home-sections-item:focus .home-sections-button{
			bottom: 80px;
			opacity: 1;
			-webkit-transition: all .25s ease, color 0.75s ease;
			   -moz-transition: all .25s ease, color 0.75s ease;
				-ms-transition: all .25s ease, color 0.75s ease;
				 -o-transition: all .25s ease, color 0.75s ease;
					transition: all .25s ease, color 0.75s ease;	
		}

		.row > :first-child,.section > :first-child, div[class^='col-'] > :first-child{
			margin-top: 0 !important;
		}
		.row > :last-child,.section > :last-child, div[class^='col-'] > :last-child{
			margin-bottom: 0 !important;
		}
<div class="row mb-xlarge">
		<div class="home-sections">	
				<div class="col-md-4">
					<div class="home-sections-item">
						<div class="home-sections-head">
							<img src="images/gallery/thumbs/thumb_01.png" alt="">
							<ul class="home-sections-button">
								<li><a href="#"><img src="images/icon-hover.png"></a></li>
							</ul>
						</div>

						<div class="home-sections-content">
							<h3 class="title">Nos projets domiciliaire</h3>
							<h4 class="subtitle">PLUS DE DÉTAILS </h4>
						</div>	
					</div>
				</div>
						
				<div class="col-md-4">
					<div class="home-sections-item">
						<div class="home-sections-head">
							<img src="images/gallery/thumbs/thumb_02.png" alt="">
								<ul class="home-sections-button">
									<li><a href="#"><img src="images/icon-hover.png"></a></li>
								</ul>
						</div>

						<div class="home-sections-content">
							<h3 class="title">Modèles disponible</h3>
							<h4 class="subtitle">VOIR LES MODÈLES</h4>
						</div>
									
					</div>
				</div>

				<div class="col-md-4">
					<div class="home-sections-item">
						<div class="home-sections-head">
							<img src="images/gallery/thumbs/thumb_03.png" alt="">
							<ul class="home-sections-button">
								<li><a href="#"><img src="images/icon-hover.png"></a></li>
							</ul>
						</div>

						<div class="home-sections-content">
							<h3 class="title">Qualité de construction</h3>
							<h4 class="subtitle">lIRE PLUS </h4>
						</div>
									
					</div>
				</div>			
		</div>			
</div>