如何增加主题的宽度

Normally, topic look like this. Not as large as I want.

So, I wrote this code to increase the width :

.topic-body {
    width: 830px;
}

To make it look like this :

But when my screen is smaller, it looks like this :

How to avoid this?

The position of the timeline is based on the default topic width, so that needs to be moved too… our default CSS is:

.timeline-container {
  margin-left: 757px;

  @media all and (min-width: 1140px) {
    margin-left: 820px;
  }
  @media all and (min-width: 1250px) {
    margin-left: 900px;
  }
}

So I think you’d either want to reduce the topic width for smaller screens, or increase the margin-left of the timeline-container a bit.

Another difficulty you might run into is when we switch from the timeline to the progress bar at smaller browser widths… because that switch is determined in JS so it’s more involved than just updating the CSS.

33%20AM

I think eventually we’d want the layout to be more flexible so it would be in the right position automatically if the topic column width is different, but for now it’s a manual adjustment at a few breakpoints.

10 个赞

Hi, stumbled upon this since it has been a request from our users.

Wouldn’t it work to just use the same kind of rules on the topic.body rule?

Instead of this:

  .topic-body {
        width: 830px;
    } 

Could it be like, for instance:

    .topic-body {
        width: 727px;
      @media all and (min-width: 1140px) {
        width: 790px;
      }
      @media all and (min-width: 1250px) {
        width: 870px;
      }

    } 

This way the topic width would always go along with the timeline margin width.

I use a wider screen on my themes. It’s mixed in with a bunch of other stuff but I think I extracted all the widescreen stuff for just the topic posts page into this component, which should be easy enough to edit to get whatever max-width you want.
https://github.com/oerog/widescreen2.git

If you want the header width to stay consistent and not go wider on the topic posts page, then remove
, .archetype-regular .d-header .wrap from line 20

It uses 90px avatars so if you want 45px just delete the head_tag.html and these lines at the end of the css

.topic-avatar {
  width: 90px;
  .avatar {
    width: 90px;
    height: 90px;
  }
}
.embedded-posts .topic-avatar {
  width: 45px;
  img.avatar {
    width: 45px;
    height: 45px;
  }
}

I’ve made a very simple Theme Component which widens the Topic on Desktop only. It was made for my personal notebooking/blogging Discourse at bawmedical.co.uk and it’s not very advanced and doesn’t use @media queries (yet). But it may suit simple use-cases. If anyone uses it and has feedback then we can create a new Topic for discussion of it here on Meta, or submit Issues or PRs on GitHub

https://github.com/pacharanero/discourse-topic-width-desktop

(This is as much an aide-memoire for myself as anything else, because in $sometimeperiod I will have forgotten how I did this and will be searching Meta for it again!)

5 个赞

Fantastic, thank you!

好消息,现在就是这样。在主题中,帖子的内容宽度可以通过一点 CSS 来增加:

:root {
    --topic-body-width: 1000px;
}

就是这样!没有重叠。请注意,最大宽度仍然受到 Discourse 整体最大宽度的限制,因此如果您想做一些极端的事情,例如:

:root {
    --topic-body-width: 2000px;
}

您还需要增加 --d-max-width,它默认为 1110px

:root {
    --d-max-width: 3000px;
    --topic-body-width: 2000px;
}
6 个赞

谢谢 @awesomerobot,我会相应地更新主题组件

1 个赞

我已经更新了 TC 并添加了一个参数以允许在自定义 UI 中控制主题宽度。它正在工作,因为 CSS 参数正在被更改,您可以在检查页面源代码时看到这一点。但是,主题正文的实际宽度似乎没有改变。

2 个赞

我刚试了一下,对我来说是有效的,不过启用组件后我不得不刷新页面

2 个赞

您好,很高兴看到这些关于更宽主题的最新进展,我的用户和我都会感谢您!

看起来 pacharanero 的主题组件可能比 @Alex_P 的版本 这里 更简洁、更现代?(类似主题:https://meta.discourse.org/t/increasing-post-width-with-css/43368)我确实很喜欢 @Alex_P 将帖子编辑器宽度增加到全屏的选项。

我也想让主页的 最新 / 新建 / 分类 列表变得更宽一些。要做到这一点,似乎应该减小最左边和最右边的边距,如果可能的话,为了保持一致性,应该与主题视图中的宽度相同。

感谢 @rahim123,我很高兴能与 @Alex_P 合作,为两者带来相同的功能,或者如果有人想将这两个 TC 重构为一个统一的 TC,并添加“编辑器宽度”选项。或者也可以在我自己的仓库中提交一个 PR。这是一个非常简单的插件,所以并不难弄清楚,只是我现在太忙了,暂时无法完成,但也许在接下来的几周里会有机会。

1 个赞

我尝试了这一点,先是 topic body,然后添加了 --d-max-width,这导致 body 重新对齐到屏幕右侧——出乎意料!?

因此,即使宽度设置为 1400px,你的意思是如果没有上面的 --d-max-width,它也不会超出 1110px 的默认值——是这样吗?

我将其更改为:

:root {
    --topic-body-width: 100w;
    --d-max-width:100w;
}

其中 100w 是窗口的宽度

此主题已在 2290 天后自动关闭。不再允许回复。