如何减少这个div的宽度,以便另一个div可以在它旁边?

时间:2015-11-18 14:42:41

标签: html css css3 width css-position

最初this was an SSCCE,我想对其进行更改。更改的是,我希望将“内联”同级div添加下一步添加到.first-page,我们称之为.first-page-sib,以便.first-page为了这个例子,缩小了一点(可能让overflow-x:scroll给它)宽度和几个像素,65px.first-page-sib占用。 / p>

所以我在div.first-page-sib旁边添加了div.first-sib,为他们添加了一些CSS属性,将它们包装在div.wrapper中。 div.first-page-sib没有出现。但是,一旦我添加了position:absolute;,它就出现了。

但现在问题是它显示在.first-page上方,即注意红色div与标题中的单词ELE重叠。我想要的是让.first-page在宽度方向上变小,以便.first-page-sib可以在它旁边。

我怎样才能做到这一点?

JSFiddle here.

OR

.wrapper {
    height:100%;
}

.first-page {
    vertical-align:top;
    display:inline-block;
    width:95%;
}

.first-page-sib {
    vertical-align:top;
    background-color:red;
    width:65px;
    height:100%;
    position:absolute;
    display:inline-block;
    right:0px;
}


/******************************************************/

.header-element {
    height:70px;
    width:100%;
    top:0px;
    left:0px;
    opacity:0.6;
    background-color:brown;
    z-index:1000;
    position:absolute;
    text-align:right;
}

.header-element p {
    padding:5px 50px;
    color:yellow;
    font-family:sans-serif;
    font-weight:bold;
    font-size:20px;
}

/******************************************************/

html, body {
	height:100%;
}

.first-page {
	height:100%;
}

#imageSlideshowContainer img {
	top:0px;
	left:0px;
	position:fixed;
	width:100%;
	display:none;
	
	height:100%; /*If I don't set this, the image just remains small, confined within the first viewport in the browser, it doesn't for example peep through the translucence of the footer and other sections.*/
}

#imageSlideshowContainer img.slider-image1 {
	display:block;
}

.captionSlideshowContainer { /*same as first-viewport*/
	width:100%;
	display:table;
	/*top:0px;*/
	
	height:100%;
}

.previous-slide-arrow, .next-slide-arrow {
	display:table-cell;
	vertical-align:middle;
	position:relative;/*wat if not?*/
	color:white;
	text-align:left;
	text-decoration:none;
	background-repeat:no-repeat;
	background-position:center center;
	left:20px;
	width:3%;
	
	font-size:50px;
	font-weight:bold;
}

.next-slide-arrow {
	left:auto;
	right:20px;
	text-align:right;
}

.central-content-container {
	display:table-cell;
	text-align:center;
	vertical-align:bottom;
	position:relative;
	bottom:30px;
	padding:20px 5px;
}

/* UPDATED THIS - ABSOLUTE POSITION */
.slider-text-wrapper span {
	display:none;
    position:absolute;
    bottom:0;
    width:100%;
    left:0;
}

.caption1 {
	display:block;
}

.slider-text-wrapper span h3 {
	text-transform:uppercase;
	font-size:68px;
	font-weight:bold;
	font-family: sans-serif;
	color:orange;
	line-height:60px;
}

.slider-text-wrapper span p {
	font-size:20px;
	font-weight:100;
	font-family: sans-serif;
	color:white;
	line-height:60px;
}

.central-content-container a {
	width:6px;
	height:6px;
	display:inline-block;
	margin-right:16px;
	background: white none repeat scroll 0% 0%;
	border-radius:100%;
	color:transparent;
}

.central-content-container a.active {
	background:yellow;
}
<div class="header-element">
    <p>ELE</p>
</div>


<!--  --------------------------------------  -->
<div class="wrapper">


<div class="first-page">
    		<div id="imageSlideshowContainer" class="image-slideshow-container">
    			<img class="slider-image1" src="http://www.stadiumsofprofootball.com/nfc/images/candold2.jpg" alt="pixer!" /> 
    			<img class="slider-image2" src="http://www.bryantpark.org/static/galleries/history/18.jpg" alt="pixer!" /> 
    			<img class="slider-image3" src="http://www.legendsofamerica.com/photos-CO-Misc/CheesmanPark.jpg" alt="pixer!" /> 
    			<img class="slider-image4" src="https://upload.wikimedia.org/wikipedia/commons/2/2d/Sportsman's_Park_1946_World_Series-1.jpg" alt="pixer!" /> 
    			<img class="slider-image5" src="http://www.ballparksofbaseball.com/past/images/cand13959.jpeg" alt="pixer!" /> 
    			<img class="slider-image6" src="https://upload.wikimedia.org/wikipedia/commons/3/38/Central_Park_New_York_City_New_York_8.jpg" alt="pixer!" /> 
    		</div>


    		<div class="captionSlideshowContainer first-viewport">
    			<a class="previous-slide-arrow" href="#">&lt;</a>
    			
    			<div class="central-content-container">
    				<div class="slider-text-wrapper">
    					<span class="caption1" style="display:block;" ><h3>alpha alpha alpha</h3></span>
    					<span class="caption2" ><h3 >beta beta beta</h3></span>
    					<span class="caption3" ><h3>Gamma gamma Gamma</h3></span>
    					<span class="caption4" ><h3>Delta delta Delta</h3></span>
    					<span class="caption5" ><h3>Epsilon epsilon</h3></span>
    					<span class="caption6" ><h3>Neither Either Whatever</h3></span>
    				</div>
    				<!--<div class="learn-more-link-wrapper">
    					<img class="learn-more-image" src="http://localhost/moodle/theme/crystal/pix/headings/learn-more-image.png" />
    				</div>-->
    				<div class="navigation-bullets-wrapper">
    					<a class="active navigation-bullet1" href="javascript: changeImage(1)"><span>Bullet</span></a>
    					<a class="navigation-bullet2" href="javascript: changeImage(2)"><span>Bullet</span></a>
    					<a class="navigation-bullet3" href="javascript: changeImage(3)"><span>Bullet</span></a>
    					<a class="navigation-bullet4" href="javascript: changeImage(4)"><span>Bullet</span></a>
    					<a class="navigation-bullet5" href="javascript: changeImage(5)"><span>Bullet</span></a>
    					<a class="navigation-bullet6" href="javascript: changeImage(6)"><span>Bullet</span></a>
    				</div>
    			</div>
    			
    			<a class="next-slide-arrow" href="#">&gt;</a>
    		</div> <!-- .first-viewport -->
    	
    	</div> <!-- .first-page -->
    
    <div class="first-page-sib">.</div>
    
</div><!--.wrapper-->

    	<p style="background-color:pink; opacity:0.5;">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin 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 the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, Lorem ipsum dolor sit amet.., comes from a line in section 1.10.32.
    	
        The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

        It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing 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 the years, sometimes by accident, sometimes on purpose (injected humour and the like).
        
    	Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin 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 the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, Lorem ipsum dolor sit amet.., comes from a line in section 1.10.32.
    	
    	The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
    	
    	There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which dont look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isnt anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>

2 个答案:

答案 0 :(得分:1)

您可以尝试css3 计算 width: calc(100% - 65px); -

.first-page {
    vertical-align: top;
    display: inline-block;
    width: calc(100% - 65px);
}
.header-element p {
    padding: 5px 50px;
    color: #FF0;
    font-family: sans-serif;
    font-weight: bold;
    font-size: 20px;
    float: right;
    margin-right: 25px;
    width: 100%;
}

答案 1 :(得分:0)

我会尝试将所有其他div作为表格进行div。 然后将其他人定义为表格行

.div-table{
  display:table;         
}
.div-table-row{
  display:table-row;
}

How create table only using <div> tag and Css