根据你现在拥有的,这将工作正常。
我在“figure”元素之前结束了“article”元素,然后我再次打开它。
</article> <figure class="image-x-large"> .... </figure> <article class="content">
CSS调整是删除 .content 来自你的“图”类规则的类。
.content
figure.image-x-large { .... } figure.image-x-large .img img { .... } figure.image-x-large figcaption { .... }
工作样本
@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,900); body { font-family: "Source Sans Pro", sans-serif; line-height: 1.5; font-size: 18px; background-color: snow; } .content { width: 1230px; margin: 0 auto; padding: 0; overflow: visible; } .content .story-content-width, .content h3, .content p { padding-left: 200px; padding-right: 200px; width: 830px; position: relative; } .content h3 { font-size: 25px; color: SteelBlue; } figure.image-x-large { display: table; width: 100%; margin: 0; } figure.image-x-large .img img { /* position:absolute; left: 0;*/ width: 100%; /* min-width: 1230px;*/ height: auto; } figure.image-x-large figcaption { text-align: center; font-size: 14px; border-bottom: 1px solid powderblue; padding-bottom: 15px; }
<article class="content"> <h3>This is a headline</h3> <p>Across the centuries brain is the seed of intelligence, citizens of distant epochs, consciousness Apollonius of Perga billions upon billions Drake Equation network of wormholes another world Sea of Tranquility intelligent beings preserve and cherish that pale blue dot citizens of distant epochs globular star cluster network of wormholes another world? Vangelis Euclid hydrogen atoms tendrils of gossamer clouds quasar kindling the energy hidden in matter Cambrian explosion citizens of distant epochs dream of the mind's eye, a mote of dust suspended in a sunbeam rings of Uranus Orion's sword made in the interiors of collapsing stars. How far away. Across the centuries intelligent beings.</p> <p>Corpus callosum courage of our questions how far away rogue circumnavigated hearts of the stars realm of the galaxies gathered by gravity cosmos, quasar extraplanetary. Of brilliant syntheses Drake Equation network of wormholes dispassionate extraterrestrial observer made in the interiors of collapsing stars dispassionate extraterrestrial observer hydrogen atoms culture astonishment another world paroxysm of global death dispassionate extraterrestrial observer prime number hundreds of thousands vanquish the impossible ship of the imagination. Descended from astronomers trillion descended from astronomers. Ship of the imagination encyclopaedia galactica, courage of our questions. Are creatures of the cosmos?</p> </article> <figure class="image-x-large"> <span class="img "> <img src="http://www.fillmurray.com/1250/750" class="" alt=""> </span> <figcaption> <div class="caption">Franck Bacquet stands outside Ohm Force's first real office in 2006. The signage advertises French Fries and kebabs.</div> <div class="credit"> Image: Ohm Force</div> </figcaption> </figure> <article class="content"> <p>At the edge of forever as a patch of light with pretty stories for which there's little good evidence rings of Uranus tesseract radio telescope of brilliant syntheses, made in the interiors of collapsing stars astonishment Cambrian explosion prime number. The ash of stellar alchemy take root and flourish bits of moving fluff, citizens of distant epochs consciousness as a patch of light how far away. Sea of Tranquility prime number inconspicuous motes of rock and gas rich in mystery a still more glorious dawn awaits galaxies great turbulent clouds citizens of distant epochs. Astonishment vanquish the impossible Hypatia.</p> <p>Hundreds of thousands radio telescope, courage of our questions shores of the cosmic ocean dream of the mind's eye, kindling the energy hidden in matter Euclid. The sky calls to us, a still more glorious dawn awaits! Light years. Descended from astronomers cosmic fugue, a billion trillion Flatland extraordinary claims require extraordinary evidence gathered by gravity birth Sea of Tranquility, Vangelis two ghostly white figures in coveralls and helmets are soflty dancing, birth tesseract, tingling of the spine, ship of the imagination hydrogen atoms, not a sunrise but a galaxyrise cosmic fugue and billions upon billions upon billions upon billions upon billions upon billions upon billions.</p> <p>The ash of stellar alchemy take root and flourish bits of moving fluff, citizens of distant epochs consciousness as a patch of light how far away. Sea of Tranquility prime number inconspicuous motes of rock and gas rich in mystery a still more glorious dawn awaits galaxies great turbulent clouds citizens of distant epochs. Astonishment vanquish the impossible Hypatia.</p> </article>
第一部分实际上非常简单,因为有些单元可以处理浏览器窗口。第二部分有点困难,因为您需要将图像移动到窗口的边缘。既然你有 position:relative; 在图像的父级上,它将无法使用 position:absolute; 。而是试试这个:
position:relative;
position:absolute;
figure.image-x-large { width:100vw; margin-left:50%; transform:translate(-50%); }
这将一直有效,直到视口达到容器的宽度,然后图像将缩小。您必须放入媒体查询才能阻止这种情况发生。
@media screen and (max-width:1230px){ figure.image-x-large{ margin:0; transform:translate(0); } }
正如您可能期望的那样,我强烈建议您重新构建HTML而不是尝试通过css来解决这个问题(只有hacky css才有可能)
我正在谈论的hacky css是这样的:
figure{ width: 100vw; position: relative; left: calc( -0.5 * (100vw - 1230px) ); }
通过添加媒体查询,您还必须使用此方法处理小于1230px的小屏幕,但无论如何,您当前的css不会缩放到较小的屏幕。