Jump to content
  • 0

как убрать padding у div последнего элемента


pavlovda
 Share

Question

Здравствуйте участники форума подскажите, как убрать padding у div последнего элемента

исходные коды html, css прилагаю ниже

<div class = "news-main">					<div class = "news">						<div>							<img src = "img/article-img1.jpg" alt = "" />							<h3>Column title</h3>							<p class = "preview">							Maecenas faucibus mollis interdum. Etiam porta sem malesuada magna mollis euismod. Cras justo odio, dapibus ac facilisis in, egestas eget quam.							</p>						</div>					</div>					<div class = "news">						<div>							<img src = "img/article-img2.jpg" alt = "" />							<h3>Column title</h3>							<p class = "preview">							Maecenas faucibus mollis interdum. Etiam porta sem malesuada magna mollis euismod. Cras justo odio, dapibus ac facilisis in, egestas eget quam.							</p>						</div>					</div>					<div class = "news">						<div>							<img src = "img/article-img3.jpg" alt = "" />							<h3>Column title</h3>							<p class = "preview">							Maecenas faucibus mollis interdum. Etiam porta sem malesuada magna mollis euismod. Cras justo odio, dapibus ac facilisis in, egestas eget quam.							</p>						</div>					</div>				</div>

отступ нужно убрать у div, находящегося в последнем блоке с классом news

css код

.news-main{width: 100% ;overflow: hidden ;margin-bottom: 70px ; }.news {float: left ; width: 33.33% ;}.news div{padding-right: 15px ;}.news div img {margin-bottom: 5px ;}.news div h3{font-size: 18px ; color: #444444 ;margin-bottom: 5px ;}.news div p.preview{font-size: 12px ; color: #444444 ;text-align: justify ;}

Пробовал использовать псевдоэлементы last-child ничего не вышло/ В чем проблема не пойму.

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Уэс Бос недавно в твиттере советовал использовать селектор :not() вместо переопределения стилей:

.news:not(:last-child) div {    padding-right: 15px;}

в ответах предложили еще более кроссбраузерную (IE8...) альтернативу:

.news + .news div {        padding-left: 15px;}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy